about summary refs log tree commit diff
path: root/aoc/2022/06/part-one.d
blob: c914704ffecc180c3006c10968bd9d87d2f5f8d7 (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
import core.stdc.stdio : getchar, printf;

extern(C) void main()
{
    slide: for (auto q = 0u, i = 1u; q & 0xffu ^ '\n'; ++i)
    {
        q <<= 8u;
        q |= getchar();
        if (i < 4)
          continue;

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

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