Day 5 cleanup
This commit is contained in:
parent
71c3cf9b38
commit
0d9eb13b5b
1 changed files with 3 additions and 5 deletions
|
|
@ -7,7 +7,7 @@ Object subclass: Ordering [
|
||||||
| beforeMap |
|
| beforeMap |
|
||||||
initialize [beforeMap := Dictionary new]
|
initialize [beforeMap := Dictionary new]
|
||||||
|
|
||||||
graphviz
|
graphviz "Very elucidating!"
|
||||||
[ AOC visualizeWithExt: '.dot' do: [
|
[ AOC visualizeWithExt: '.dot' do: [
|
||||||
:stream |
|
:stream |
|
||||||
stream << 'digraph {'.
|
stream << 'digraph {'.
|
||||||
|
|
@ -31,7 +31,7 @@ Object subclass: Ordering [
|
||||||
^true ]
|
^true ]
|
||||||
|
|
||||||
sort: man
|
sort: man
|
||||||
[ ^man asSortedCollection: [ :x :y | ((beforeMap at: y) includes: x) ] ]
|
[ ^man asSortedCollection: [ :x :y | (beforeMap at: y) includes: x ] ]
|
||||||
]
|
]
|
||||||
|
|
||||||
Collection extend [
|
Collection extend [
|
||||||
|
|
@ -45,11 +45,9 @@ AOC input: [ (stdin contents tokenize: (String with: $<10> with: $<10>))
|
||||||
rules lines do: [ :rule | ord addRule: rule ].
|
rules lines do: [ :rule | ord addRule: rule ].
|
||||||
mans := seqs lines collect: [
|
mans := seqs lines collect: [
|
||||||
:seq | seq chain tokenize: ','; collect: [:x | x asNumber] ].
|
:seq | seq chain tokenize: ','; collect: [:x | x asNumber] ].
|
||||||
"ord graphviz."
|
|
||||||
{ord . mans} ] ];
|
{ord . mans} ] ];
|
||||||
part1: [ :ord :mans | mans select: [ :man | ord isValid: man ] ];
|
part1: [ :ord :mans | mans select: [ :man | ord isValid: man ] ];
|
||||||
part2: [ :ord :mans |
|
part2: [ :ord :mans | mans chain reject: [ :man | ord isValid: man ];
|
||||||
mans chain reject: [ :man | ord isValid: man ];
|
|
||||||
collect: [ :man | ord sort: man ] ];
|
collect: [ :man | ord sort: man ] ];
|
||||||
result: [ :ordAndMans :part |
|
result: [ :ordAndMans :part |
|
||||||
part chain valueWithArguments: ordAndMans;
|
part chain valueWithArguments: ordAndMans;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue