about summary refs log tree commit diff
path: root/aoc/2022/06/part-two.d
blob: 4465e38b26b66b79ff58c8ac521a7c7ecb582887 (plain) (blame)
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
import core.int128 : Cent, and, or, shl, tst, xor;
import core.stdc.stdio : getchar, printf;

extern(C) void main()
{
    slide: for (auto q = cast(Cent) 0u, i = 1u;
                tst(xor(and(q, cast(Cent) 0xff), cast(Cent) '\n'));
                ++i)
    {
        q = or(shl(q, 8u), cast(Cent) getchar());
        if (i < 14)
          continue;

        auto p = cast(ubyte*) &q;
        for (auto s = 0u, j = 0u; j < 14u; ++j)
        {
            auto b = 1u << (p[j] & 0x1fu);
            if (s & b)
                continue slide;
            s |= b;
        }

        printf("%d\n", i);
        break;
    }
}