-
Notifications
You must be signed in to change notification settings - Fork 5
/
adventofcode3.rb
102 lines (90 loc) · 1.06 KB
/
adventofcode3.rb
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
x = 0
y = 0
vx = 1
vy = 0
l = 1
c = 0
board = {}
nxt = proc{
r = [x,y]
v = 0
[-1,0,1].each do |dy|
[-1,0,1].each do |dx|
nx = x + dx
ny = y + dy
if board[[nx,ny]]
v += board[[nx,ny]]
end
end
end
if v == 0
v = 1
end
board[r] = v
x += vx
y += vy
c += 1
if c == l
c = 0
if vx == 1 && vy == 0
vx = 0
vy = -1
elsif vx == 0 && vy == -1
vx = -1
vy = 0
l += 1
elsif vx == -1 && vy == 0
vx = 0
vy = 1
else
vx = 1
vy = 0
l += 1
end
end
#r
v
}
1000.times{
v = nxt[]
if v > 265149
p v
end
}
__END__
x = 0
y = 0
vx = 1
vy = 0
l = 1
c = 0
nxt = proc{
r = [x,y]
x += vx
y += vy
c += 1
if c == l
c = 0
if vx == 1 && vy == 0
vx = 0
vy = -1
elsif vx == 0 && vy == -1
vx = -1
vy = 0
l += 1
elsif vx == -1 && vy == 0
vx = 0
vy = 1
else
vx = 1
vy = 0
l += 1
end
end
r
}
a = nil
265149.times{
a = nxt[]
}
p a[0].abs + a[1].abs