in reply to Can It Be Written In Base X With Only 1s And 0s
Seems to me it would be cheaper to actually convert the number.
sub test { my ($num, $base) = @_; while ($num > 0) { my $digit = $num % $base; return 0 if $digit > 1; $num = ($num - $digit)/$base; } return 1; }
Takes at most floor(logb(n)) loop passes, just like what you were attempting.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Can It Be Written In Base X With Only 1s And 0s
by Laurent_R (Canon) on Jun 15, 2015 at 21:57 UTC | |
by ikegami (Patriarch) on Jun 15, 2015 at 22:31 UTC |