about summary refs log tree commit diff
path: root/day12.rb
blob: 288d34fda4e3ce0c27636ad66a5ae9c7a8a32d18 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
s="#..#.#..##......###...###"

t = {
"...##"=>"#",
"..#.."=>"#",
".#..."=>"#",
".#.#."=>"#",
".#.##"=>"#",
".##.."=>"#",
".####"=>"#",
"#.#.#"=>"#",
"#.###"=>"#",
"##.#."=>"#",
"##.##"=>"#",
"###.."=>"#",
"###.#"=>"#",
"####."=>"#",
}

s="##.####..####...#.####..##.#..##..#####.##.#..#...#.###.###....####.###...##..#...##.#.#...##.##.."

t={
"##.##"=>"#",
"....#"=>".",
".#.#."=>"#",
"..###"=>".",
"##..."=>"#",
"#####"=>".",
"###.#"=>"#",
".##.."=>".",
"..##."=>".",
"...##"=>"#",
"####."=>".",
"###.."=>".",
".####"=>"#",
"#...#"=>"#",
"....."=>".",
"..#.."=>".",
"#..##"=>".",
"#.#.#"=>"#",
".#.##"=>"#",
".###."=>".",
"##..#"=>".",
".#..."=>"#",
".#..#"=>"#",
"...#."=>".",
"#.#.."=>".",
"#...."=>".",
"##.#."=>".",
"#.###"=>".",
".##.#"=>".",
"#..#."=>"#",
"..#.#"=>".",
"#.##."=>"#",
}

s = ("."*1000) + s + (".")*1000

r = 0
(1..1000).each { |i|
  s = "..#{s}..".chars.each_cons(5).map { |c|
    t[c.join] || "."
  }.join

  if i == 20 || i == 500 || i == 1000
    r = 0
    s.chars.each_with_index { |c, i|
      if c == "#"
        #    p i-10
        r += i-1000
      end
    }
    
    p [i,r]
  end
}

# 1000..2000 adds up to 32000
p r + ((50000000000/1000)-1)*32000  # 1600000032081