From dfa19978241b6f069594a98541848b3b88b299ef Mon Sep 17 00:00:00 2001 From: plasmaofthedawn Date: Sat, 23 Dec 2023 23:29:53 -0500 Subject: [PATCH] day7part1 python --- Makefile | 11 +++++++++++ pythonsrc/day7/part1.py | 19 +++++++++++++++++++ src/day17/part1.pas | 14 ++++++++++++++ src/day17/queue.pas | 23 +++++++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 pythonsrc/day7/part1.py create mode 100644 src/day17/part1.pas create mode 100644 src/day17/queue.pas diff --git a/Makefile b/Makefile index 5a99a5c..4bca4b0 100644 --- a/Makefile +++ b/Makefile @@ -165,5 +165,16 @@ day16part2: ./build/day16part2 +day17part1: + fpc src/day17/part1.pas -obuild/day17part1 + @echo + ./build/day17part1 + +day17part2: + fpc src/day17/part2.pas -obuild/day17part2 + @echo + ./build/day17part2 + + clean: rm build/* \ No newline at end of file diff --git a/pythonsrc/day7/part1.py b/pythonsrc/day7/part1.py new file mode 100644 index 0000000..c7cd163 --- /dev/null +++ b/pythonsrc/day7/part1.py @@ -0,0 +1,19 @@ +print( + sum([a * (c + 1) for c, (_, a) in enumerate(sorted( # sort by hand value and payout bets according to rank + [(sum([ # total hand value + [max( + 13**5 * 6 if 5 in d else 0, # five of a kind + 13**5 * 5 if 4 in d else 0, # four of a kind + 13**5 * 4 if 3 in d and 2 in d else 0, # full house + 13**5 * 3 if 3 in d else 0, # three of a kind + 13**5 * 2 if list(d).count(2) == 2 else 0, # two pair + 13**5 if 2 in d else 0 # pair + ) for d in [{k: b.count(k) for k in b}.values()]][0], # total type value (value from the type of hand) + sum([13**(4 - e) * '23456789TJQKA'.index(a) for e, a in enumerate(b)]) # total card value (value from the type of card) + ]), int(v)) # makes an array of form (total hand value, bet) + for b, v in [x.split(' ') for x in open('resources/day7.txt').read().split("\n")] # reads file split on \n + ] + ))]) +) + +#sum([a * (c + 1) for c, (_, a) in enumerate(sorted([(sum([[max(13**5 * 6 if 5 in d else 0, 13**5 * 5 if 4 in d else 0, 13**5 * 4 if 3 in d and 2 in d else 0, 13**5 * 3 if 3 in d else 0, 13**5 * 2 if list(d).count(2) == 2 else 0, 13**5 if 2 in d else 0) for d in [{k: b.count(k) for k in b}.values()]][0], sum([13**(4 - e) * '23456789TJQKA'.index(a) for e, a in enumerate(b)])]), int(v)) for b, v in [x.split(' ') for x in open('resources/day7.txt').read().split("\n")]]))]) \ No newline at end of file diff --git a/src/day17/part1.pas b/src/day17/part1.pas new file mode 100644 index 0000000..52f80b9 --- /dev/null +++ b/src/day17/part1.pas @@ -0,0 +1,14 @@ +{$mode objfpc} +{$RANGECHECKS ON} + +program day17part1; +uses sysutils; + +type + Tnode = record + x, y: int32; + end; + +begin + +end. diff --git a/src/day17/queue.pas b/src/day17/queue.pas new file mode 100644 index 0000000..103c263 --- /dev/null +++ b/src/day17/queue.pas @@ -0,0 +1,23 @@ +// i wrote this but i didn't use it +// might be useful for the future; + +var + queue: array[0..1000] of Tnode; + queue_start, queue_length: int32; + +procedure enqueue(node: Tnode); +begin + queue[queue_start + queue_length] := node; + inc(queue_length); +end; + +function dequeue(): Tnode; +begin + dequeue := queue[queue_start]; + inc(queue_start); + dec(queue_length); +end; + +var + + a, b: Tnode;