-1
\$\begingroup\$

This question already has an answer here:

You must write a program or function that will output all decimals with the specified precision if run forever. Example:

Input:

2

Output:

0.01, -0.01, 0.02, -0.02, 0.03, -0.03...

The input is the number of decimal places to print. The output is all the numbers with the specified decimal precision (if run forever). It will not output 0.

This challenge has much in common with Print all integers, and the rules are the same:

  • The output must be in decimal, unless your language does not support decimal integer (in that case use the natural representation of integers your language uses).
  • Your program has to work up to the numbers with the biggest magnitude of the standard integer type of your language.
  • Each integer must be separated from the next using any separator (a space, a comma, a linebreak, etc.) that is not a digit nor the negative sign of your language.
  • The separator must not change at any point.
  • The separator can consist of multiple characters, as long as none of them is a digit nor the negative sign (e.g. , is as valid as just ,). Any supported integer must eventually be printed after a finite amount of time.

But one more additional rule:

  • Your submission must support the highest input value / precision possible for floating point arithmetic. You don't have to handle input value beyond that.

Additional test cases:

4

-0.0001 0.0001 -0.0002 0.0002 -0.0003 0.0003...

Note that there can be multiple valid outputs,

0.0001 0.0002 0.0003 -0.0001 -0.0002 -0.0003 0.0004 0.0005 0.0006 -0.0004 -0.0005 -0.0006...

is valid for that last example.

The ellipsis (...) means more input will follow.

\$\endgroup\$

marked as duplicate by xnor code-golf Apr 27 '17 at 23:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    \$\begingroup\$ In your output it is not obvious when 0 would be printed \$\endgroup\$ – Digital Trauma Apr 27 '17 at 23:29
  • \$\begingroup\$ "unless your language does not support decimal integer (in that case use the natural representation of integers your language uses)"..."Any supported integer must eventually be printed after a finite amount of time." - copy-paste? \$\endgroup\$ – Jonathan Allan Apr 27 '17 at 23:32
  • 3
    \$\begingroup\$ It looks like you can just print all the integers, dividing each by 10^n. Is this sufficiently different a challenge? \$\endgroup\$ – xnor Apr 27 '17 at 23:36
  • \$\begingroup\$ I think this is close enough to be considered a dup. In languages that support non-integers, I think the answers will mostly be trivially similar. I won't cast my code-golf dup-hammer vote yet though - lets see what others think... \$\endgroup\$ – Digital Trauma Apr 27 '17 at 23:36
  • \$\begingroup\$ I think you need to define "precision" 0.0001 having precision 4 suggests to me that the meaning is number of decimal places (in this case, shouldn't 0.0000 be printed? What is different between one of four and zero of four?), What about 1.0001? \$\endgroup\$ – Jonathan Allan Apr 27 '17 at 23:44
1
\$\begingroup\$

R, 56 Bytes

i=scan();j=1;while(TRUE){l=j/(10^i);j=j+1;cat(l,-l," ")}
\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.