diff options
| author | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-02-05 21:23:29 +0100 |
|---|---|---|
| committer | BarrOff <58253563+BarrOff@users.noreply.github.com> | 2024-02-05 21:23:29 +0100 |
| commit | 58f310b6a8abc7f65d6690ea071844f97ad00d75 (patch) | |
| tree | 1039f24e08d5403adfdb7707e9181b74cb015911 /challenge-254/barroff/d | |
| parent | 04c92115f9c30fedf9839a7d0c2e0705914a35a8 (diff) | |
| download | perlweeklychallenge-club-58f310b6a8abc7f65d6690ea071844f97ad00d75.tar.gz perlweeklychallenge-club-58f310b6a8abc7f65d6690ea071844f97ad00d75.tar.bz2 perlweeklychallenge-club-58f310b6a8abc7f65d6690ea071844f97ad00d75.zip | |
feat: add solutions for challenge 254 from BarrOff
Diffstat (limited to 'challenge-254/barroff/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() +{ +} |
