Last active
December 8, 2021 15:08
-
-
Save xpqz/6e91d977b0b8b29d94f1dfb8dc694635 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
⍝ https://adventofcode.com/2021/day/8 | |
d←⊃⎕NGET'../d/8'1 | |
data←' '(≠⊆⊢)¨⍤1⊢(⎕CSV⍠'Separator' '|')(d)''4 | |
+/∊2 3 4 7 8∘.=≢¨↑data[;1] ⍝ part 1 | |
seg←{ ⍝ find segment mapping from ⍺ and decode ⍵ | |
frq←{≢⍵}⌸{⍵[⍋⍵]}∊obl←⍺[⍋≢¨⍺] | |
a←'abcdefg' | |
s←7⍴'' | |
s[0]←⊃(1⊃obl)~0⊃obl | |
s[1 4 5]←a[frq⍳6 4 9] | |
s[2]←a[⍸8=frq]~s[0] | |
s[3]←⊃(2⊃obl)∩a[⍸7=frq] | |
s[6]←⊃a~s | |
10⊥s∘decode¨⍵ | |
} | |
decode←{ | |
enc←(0 1 2 4 5 6)(2 5)(0 2 3 4 6)(0 2 3 5 6)(1 2 3 5)(0 1 3 5 6)(0 1 3 4 5 6)(0 2 5)(0 1 2 3 4 5 6)(0 1 2 3 5 6) | |
⊃⍸({⍵[⍋⍵]}⍺⍳⍵)∘≡¨enc | |
} | |
+/seg/⍤1⊢data ⍝ part 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We have 10 encoded digits to the left, and 5 encoded digits to the right on each row.
In the below, we assume that the segment numbering is as follows:
On the left, we have all 10 digits, without repeats. Over the 10 digits, the segment frequencies are as follows (looking at the diagram given in the question):
We can uniquely identify segments 1, 4 and 5 from this.
Now we sort the patterns in terms of ascending length.
You can now, somewhat tediously, work out the remaining few mappings, a bit like sudoku.