-
Notifications
You must be signed in to change notification settings - Fork 0
/
day_21.fs
41 lines (32 loc) · 1.04 KB
/
day_21.fs
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
33
34
35
36
37
38
39
40
41
#light
let r = [|
("...#","##.#.....");
(".#...####","#..#........#..#");
|]
let isqrt x =
let rec isqrt r x =
if r * r >= x then r else isqrt (r+1) x
isqrt 1 x
let input = ".#...####" // 9
let input = ".#...####" // 9
let split2 strlen = // provide character indexes
let side = isqrt strlen
if side % 2 <> 0 then [] else
[for r in 0..side/2-1 do
for c in 0..side/2-1 do
let r = r*2*side
yield [r+c*2;r+c*2+1;r+c*2+side;r+c*2+side+1]]
let split3 strlen = // provide character indexes
let side = isqrt strlen
if side % 3 <> 0 then [] else
[for r in 0..side/3-1 do
for c in 0..side/3-1 do
let r = r*3*side
yield [r+c*3;r+c*3+1;r+c*3+2;
r+c*3+side;r+c*3+side+1;r+c*3+side+2;
r+c*3+2*side;r+c*3+2*side+1;r+c*3+2*side+2]]
//split3 36
let findMatch rules input =
let indexes = split3 (String.length input)
indexes
findMatch ["....";"....";] input