-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirewall.yuk
executable file
·97 lines (76 loc) · 1.69 KB
/
firewall.yuk
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
#!/usr/bin/awful
:set &max-layer i0
:set &layer-depth :arr
:set &layer-state :arr
:set &layer-dir :arr
!fun :calc-step $pos
:set &risk i0
# :writeln s'pos: ' $pos s'; scanner: ' $layer-state[$pos] s' (' &layer-depth[$pos] s')'
!if :seq i0 :abs &layer-state[&pos]
# :writeln s'caught at layer ' $pos
:set &risk :mul $pos (:add $layer-depth[$pos] i1)
!fi
:set &i i0
!while :le &i &max-layer
!if :is-int &layer-depth[&i]
!if :eq &layer-dir[&i] i0
!if :eq &layer-depth[&i] :add &layer-state[&i] i1
:set &layer-dir[&i] i1
!fi
!else
!if :eq i0 :sub &layer-state[&i] i1
:set &layer-dir[&i] i0
!fi
!fi
!fi
:add &i i1
!done
:return &risk
!nuf
!fun :reset-state
:set &i i0
!while :le &i &max-layer
:set &layer-state[&i] i0
:set &layer-dir[&i] i0
:add &i i1
!done
!nuf
!fun :will-get-caught $delay
:set &i i0
!while :le &i &max-layer
!if :is-int &layer-depth[&i]
:set &cycle-len :mul i2 $layer-depth[$i]
!if :eq i0 :mod (:add $delay $i) $cycle-len
:writeln s'=> ' (:add $delay $i) s' vs. ' $cycle-len s' (0)'
:return i1
!fi
!fi
:add &i i1
!done
:return i0
!nuf
:set &line s''
!while :not :stdin-eof
:readln &line
:set &parts :str-explode &line s':'
:set &l-no :mkint $parts[i0]
:set &l-dp :mkint $parts[i1]
:set &layer-depth[&l-no] (:sub &l-dp i1)
!if :gt &l-no &max-layer
:set &max-layer &l-no
!fi
!done
:reset-state
:set &pos i0
:set &danger i0
!while :le &pos &max-layer
:add &danger :calc-step $pos
:add &pos i1
!done
:writeln s'> delay 0: danger ' &danger
:set &delay i0
!repeat
:set &caught :will-get-caught $delay
:writeln s'> delay ' $delay s': caught=' $caught
:add &delay i1
!until :eq i0 &caught