in reply to Determining if a rational number terminates
Nicely obfuscated, but this is shorter:
$_=pop;$_/=2until$_%2;print/(5|^1)$/?Y:N,$/
$_=pop;for$.(2,5){$_/=$.until$_%$.}print/^1$/?Y:N,$/
Of course, neither of these works for the fraction 3/6 which of course terminates as 0.5. For that to work, you'd need to add an initial step to reduce the fraction to its lowest terms.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Determining if a rational number terminates
by tobyink (Canon) on Nov 29, 2012 at 16:52 UTC | |
by blackle (Beadle) on Nov 29, 2012 at 18:12 UTC | |
by tobyink (Canon) on Nov 29, 2012 at 20:13 UTC | |
by pemungkah (Priest) on Dec 03, 2012 at 01:34 UTC | |
by tobyink (Canon) on Dec 03, 2012 at 07:37 UTC | |
|
Re^2: Determining if a rational number terminates
by trizen (Hermit) on Dec 25, 2012 at 17:26 UTC |