Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

13
  • 1
    \$\begingroup\$ Can be stripped down to: f=lambda x:x%1>0and(-x+x%1)or x+.1 which is only 34 characters long. \$\endgroup\$ Commented Jul 1, 2013 at 21:04
  • \$\begingroup\$ f=lambda x:[x+.1,x%1-x](x%1>0) is only 30 \$\endgroup\$ Commented Jul 1, 2013 at 23:15
  • 1
    \$\begingroup\$ One char shorter: f=lambda x:[x+.5,.5-x][x%1>0]. Note the use of .5 instead of .1 to get around precision issues \$\endgroup\$ Commented Jul 3, 2013 at 9:29
  • 1
    \$\begingroup\$ @AJMansfield 1.48 is not an integer. \$\endgroup\$ Commented Jul 12, 2013 at 15:48
  • 1
    \$\begingroup\$ No, that doesn't mean it. If he ment that, he should have written "all rational numbers". f:Q->Q does only mean that f maps rational number to rational numbers. Which my definition of f does. \$\endgroup\$ Commented Jul 12, 2013 at 16:01