# Python to Ruby: inconsistency with float ceil() [closed]

Just for fun, I am trying to convert the following Python

from math import *

print map(lambda count: ceil( 6 * cos((count + i) * pi / 5) ), range(100))


Which yields something like this

[2.0, -1.0, -4.0, -6.0, -4.0, -1.0, 2.0, 5.0, 6.0, 5.0, 2.0, -1.0, -4.0, -6.0, -4.0, -1.0, 2.0, 5.0, 6.0, 5.0, 2.0, -1.0, -4.0, -6.0, -4.0, -1.0, 2.0, 5.0, 6.0, 5.0, 2.0, -1.0, -4.0, -6.0, -4.0, -1.0, 2.0, 5.0, 6.0, 5.0, 2.0, -1.0, -4.0, -6.0, -4.0, -1.0, 2.0, 5.0, 6.0, 5.0]


To Ruby. This is what I've got:

(0..50).select { |c| (6 * Math::sin(x * Math::PI/5)).ceil }


The following works, but the numbers are still rounded to integers.

## closed as off-topic by Flambino, Hosch250, SirPython, Caridorc, 200_successDec 26 '15 at 23:46

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Questions containing broken code or asking for advice about code not yet written are off-topic, as the code is not ready for review. After the question has been edited to contain working code, we will consider reopening it." – Flambino, Hosch250, SirPython, Caridorc, 200_success
If this question can be reworded to fit the rules in the help center, please edit the question.

• Look at your code again. You're not doing the same operations in the two versions. In one you multiply the result of cos by 6; in the other you multiply the argument by 6. In one you add 3; in the other add i. And in one you multiply by pi/5; in the other you add pi/5. – Flambino Dec 26 '15 at 21:23
• You are right. I made a crucial silly mistake. – Jorge Bucaran Dec 26 '15 at 21:32
• Sorry, but broken code is off-topic here. – SirPython Dec 26 '15 at 21:57
• @JorgeBucaran Even after fixing the typo (which you did after receiving answers, and that's also a no-no), the code still doesn't produce the result you want. Ergo, it's by definition "broken code" and thus off-topic. It's even more broken now, as you reference a variable x that doesn't exist. If x is just intended as a placeholder, your code is instead "hypothetical or stub code" - which is also off-topic. – Flambino Dec 26 '15 at 22:18
• Correct. Code that is ready for a peer review is code that already works as intended; one could think of it as "I just committed / I'm about to commit this code, it does xyz, is there anything I could improve?" - we define broken code as "code that doesn't work as intended", because if you have a question about a specific issue with your code, it could probably be worded as a good Stack Overflow question. – Mathieu Guindon Dec 27 '15 at 4:14

(0..100).collect{|x| (6 * Math::cos(x) * Math::PI/5).ceil()}