From 296331d95169dc66ed1e5060806bd6c5e66c329c Mon Sep 17 00:00:00 2001 From: arthomnix Date: Wed, 3 Dec 2025 06:12:38 +0000 Subject: [PATCH] Day 3 part 1 --- d03/.gitignore | 1 + d03/README.md | 9 ++++++--- d03/day3.ps | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 d03/.gitignore create mode 100644 d03/day3.ps diff --git a/d03/.gitignore b/d03/.gitignore new file mode 100644 index 0000000..f08278d --- /dev/null +++ b/d03/.gitignore @@ -0,0 +1 @@ +*.pdf \ No newline at end of file diff --git a/d03/README.md b/d03/README.md index 6885a49..bb6b344 100644 --- a/d03/README.md +++ b/d03/README.md @@ -2,10 +2,13 @@ | | | |-------------------|-------------------| -| Language | ?? | -| Input Method | ?? | -| Output Method | ?? | +| Language | PostScript | +| Input Method | file | +| Output Method | PDF document | ## Running +``` +gs -sDEVICE=pdfwrite -sOutputFile=out.pdf -dNOSAFER -- day3.ps +``` ## Notes \ No newline at end of file diff --git a/d03/day3.ps b/d03/day3.ps new file mode 100644 index 0000000..c23b0c4 --- /dev/null +++ b/d03/day3.ps @@ -0,0 +1,54 @@ +%!PS + +% array max int int +% get maximum value of an array and the index of the first occurence of that value +/max { + 2 dict begin + /val 0 def + /idx 0 def + + dup length 0 1 3 -1 roll 1 sub { + dup + 2 index exch get dup + val gt { + /val exch def + /idx exch def + } { pop pop } ifelse + } for + + pop val idx + end +} def + +.shellarguments not count 1 eq or { + (Please provide input file as a command-line argument!) = + quit +} if +(r) file /thefile exch def + +/partone 0 def + +{ + thefile 255 string readline not { exit } if + dup length dup array /digits exch def + + 0 1 3 -1 roll 1 sub { + dup + 2 index exch get 48 sub + digits 3 1 roll put + } for + + digits dup length 1 sub 0 exch getinterval max + 1 add digits dup length 2 index sub 3 -1 roll exch getinterval max pop + exch 10 mul add + partone add /partone exch def +} loop + +% A4 paper, obviously +<< /PageSize [595 842] >> setpagedevice +/Monospace 20 selectfont + +50 800 moveto +partone 10 string cvs show + +thefile closefile \ No newline at end of file -- 2.51.2