An array of all numbers below 100,000 with a factor of 19. Tested, working.
S= Array.new
S[0]= 19
i= 0
while S[i]+19 < 100000 do
i+=1
S[i] = S[i-1]+19
end
The problem: Trying to find all numbers in the array that have a ‘reflection’ that is also in the array.
My attempt:
reflectionArray= Array.new
i=0
S.each do |s|
reverse= s.to_s().reverse!
S.each do |r|
if (reverse == r)
reflectionArray[i]= s
i+=1
end
end
end
I’m expecting an array with all the mirrored factors of 19, but I get an error.
New to Ruby today, but I could’ve sworn this would work!
Your problem is on this line
But you might want to do it this way instead
But you could use a range to generate your array
And to find all the reflections in the array you could simply do
So at the end you can do all of that in one line 🙂