aboutsummaryrefslogtreecommitdiff
path: root/challenge-254/barroff/d/ch_1.d
blob: d01771cf1dd2c4ab92866ebab6750ddf942f8504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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()
{
}