-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate.ps
106 lines (89 loc) · 2.67 KB
/
generate.ps
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
102
103
104
105
106
%!PS
% Copyright 2024 Google LLC
%
% Use of this source code is governed by an MIT-style
% license that can be found in the LICENSE file or at
% https://opensource.org/licenses/MIT.
(cob/bootstrap.ps) runlibfile
(cob/ascii.ps) cob.require
(cob/core.ps) cob.require
(cob/iter.ps) cob.require
/exists? { % filename exists? bool
[ exch dup length string {} exch filenameforall ] empty? not
} bind def %/exists?
/writetofile { % str filename writetofile -
dup exists? not { %ifelse
dup (writing to ) print =
(w) file exch { %loop
(DAYNUM) search { %ifelse
3 index dup 3 -1 roll writestring DayNum writestring pop
} { %else
1 index exch writestring exit
} ifelse
} loop
closefile
} { %else
(%stderr) (w) file dup dup 4 -1 roll
writestring ( already exists\n) writestring flushfile
pop % arg string
} ifelse
} bind def %/writetofile
/trailingnum { % (abc123) trailingnum (123)
% For each index in the string (starting with 0), see if the string starting
% at that point is all digits.
% XXX O(n^2) in the worst case if there's just one non-digit, near the end
dup length { %repeat
dup length 0 eq { exit } if
dup { ascii.digit? } all? { exit } { %else
dup length 1 sub 1 exch getinterval
} ifelse
} repeat
} bind def %/trailingnum
/generateinto { % (dir) generateinto -
(/) cat % ensure dir ends with a /
(%!PS
% Copyright 2024 Google LLC
%
% Use of this source code is governed by an MIT-style
% license that can be found in the LICENSE file or at
% https://opensource.org/licenses/MIT.
% Advent of Code 2024 day DAYNUM https://adventofcode.com/2024/day/DAYNUM
(cob/bootstrap.ps) runlibfile
(cob/arraylist.ps) cob.require
(cob/ascii.ps) cob.require
(cob/core.ps) cob.require
(cob/iter.ps) cob.require
(cob/log.ps) cob.require
(cob/math.ps) cob.require
(cob/stackeffect.ps) cob.require
(cob/string.ps) cob.require
(cob/stringbuf.ps) cob.require
(aoc.ps) cob.require
/DayDAYNUM 8 dict def
DayDAYNUM begin
/part1 { 8 dict begin % [lines] part1 result
/input exch def
% input { (line: ) print = } forall
/TODO
end } bind def %/part1
/part2 { 8 dict begin % [lines] part2 result
/input exch def
% input { (line: ) print = } forall
/TODO
end } bind def %/part2
end %DayDAYNUM
/ARGUMENTS where { pop /DayDAYNUM aoc.runday } if
) 1 index (day) DayNum (.ps) 4 cat writetofile
() (input.example.txt) 2 index exch cat writetofile
(part1:\040
part2:\040
) (input.example.expected) 2 index exch cat writetofile
pop
} bind def %/generateinto
/ARGUMENTS where { %if
/ARGUMENTS get { %forall
dup trailingnum /DayNum exch def
dup (generating files in ) print print (\n) print flush
generateinto
} forall
} if