mirror of
https://github.com/plasmaofthedawn/2023adventofcode.git
synced 2024-10-18 08:16:25 -05:00
day7part1 python
This commit is contained in:
parent
77250a2568
commit
dfa1997824
11
Makefile
11
Makefile
@ -165,5 +165,16 @@ day16part2:
|
|||||||
./build/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:
|
clean:
|
||||||
rm build/*
|
rm build/*
|
19
pythonsrc/day7/part1.py
Normal file
19
pythonsrc/day7/part1.py
Normal file
@ -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")]]))])
|
14
src/day17/part1.pas
Normal file
14
src/day17/part1.pas
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
{$mode objfpc}
|
||||||
|
{$RANGECHECKS ON}
|
||||||
|
|
||||||
|
program day17part1;
|
||||||
|
uses sysutils;
|
||||||
|
|
||||||
|
type
|
||||||
|
Tnode = record
|
||||||
|
x, y: int32;
|
||||||
|
end;
|
||||||
|
|
||||||
|
begin
|
||||||
|
|
||||||
|
end.
|
23
src/day17/queue.pas
Normal file
23
src/day17/queue.pas
Normal file
@ -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;
|
Loading…
Reference in New Issue
Block a user