diff options
Diffstat (limited to 'challenge-254/barroff/d/ch_1.d')
| -rw-r--r-- | challenge-254/barroff/d/ch_1.d | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/challenge-254/barroff/d/ch_1.d b/challenge-254/barroff/d/ch_1.d new file mode 100644 index 0000000000..d01771cf1d --- /dev/null +++ b/challenge-254/barroff/d/ch_1.d @@ -0,0 +1,32 @@ +#!/usr/bin/env -S rdmd -unittest + +import std.conv, std.math; + +bool three_power(int n) +{ + foreach (x; 0 .. to!int(sqrt(to!float(n))) + 1) + { + int tripple = x ^^ 3; + if (tripple > n) + { + break; + } + if (n == tripple) + { + return true; + } + } + + return false; +} + +unittest +{ + assert(three_power(27)); + assert(three_power(0)); + assert(three_power(6) == false); +} + +void main() +{ +} |
