I was trying to solve the following problem: https://www.codeeval.com/open_challenges/23/
This was my solution in Python, which didn't pass:
for x in range(1,13):
string = ''
for y in range(1,13):
string += ' '*(4-len(str(x*y))) + str(x*y)
print string.strip()
This was my friend's solution in Ruby, which did pass:
for i in 1..12
line = ""
for j in 1..12
line += " " * (4 - (j * i).to_s.length) + "#{j * i}"
end
puts line.strip
end
To me, the two snippets look like they do the same thing and they output the same thing based on my testing. Do you think there is a reason my solution isn't being accepted other than issues with the evaluation system?
stringand use string formatting to align stufffor i in 1..12is almost always better written as12.times do |i|or(1..12).each do |i|as it's extremely unusual to seeforused in Ruby code.