セブンセグメントサーチ
Advent of Code 2021 Day 8
Try the simulator!
手仕事
Xの解決
X = the sum of several decoded 4-digit numbers
入力は
abcdefg
と|
表す
桁の
0-9
今年のお気に入りのパズルに戻る
その時の
今回は
パート1 :ユニークな数字のカウント
Split the input into lines
For each line
Split the line at the | character
Keep the second string (containing four space-separated strings
Split the second string at the ' ' character, into an array of four strings
For each string in the array
Increment an accumulating value - starting from 0 - if the string's length is any of: 2, 3, 4, 7
Return the accumulated value
For each value
Increment an accumulating value - starting from 0
Return the accumulated value
パート2 :各桁の復号化
Split the input into lines
For each line
Split the line at the | character and store each one in a variable: digits and code
With the string of digits, perform the steps below and save the result in a variable, mappings:
Identify the three horizontal bar characters by filtering all digit strings for the ones with length of five - 2, 3 and 5 - then filtering for the characters they share: top, middle and bottom bars
Identify the string that is digit four by filtering all digit strings for the one with length 4
Identify the d segment by filtering the horizontal bars for the single character shared by them and 4: the middle bard
Identify the string that is digit one by filtering all digit strings for the one with length 2
Identify the b segment by filtering 4 for the single character that's in 4 but not in 1 (amended to include d)
Identify the string that is digit seven by filtering all digit strings for the one with length 3
Identify the a segment by filtering 7 for the single character that's in 7 but not in 1
Identify the g segment by finding the character that isn't a or d in the horizontal bars
Identify the string that is digit five by filtering all digit strings for the one with length 5 which also is the only one with the b segment
Identify the c segment by filtering 1 for the single character not shared by 5
Identify the f segment by filtering 1 for the single character that isn't the c segment
Identify the string that is digit eight by filtering all digit strings for the one with length 7
Identify the e segment by filtering 8 for the only character that isn't a,b,c,d,f or g
Return an array of ten arrays, where each array contains the characters denoting each digit
Update code to the result of the following operation:
For each of the four strings in code
Update each string to the result of the following operation:
Find and return the location of the item in mappings that matches these two conditions:
1. The length of the current string is equal to the length of the item in mappings
2. Every character from the item in mappings matches every character in the current string
Combine the location numbers into a string of four numbers
Coerce the string into a number
For each number
Increment an accumulating value - starting from 0
Return the accumulated value
ここで視覚化された識別プロセスです
暗号における楽しい冒険
多くの試行錯誤による
このパズルに戻って
Reference
この問題について(セブンセグメントサーチ), 我々は、より多くの情報をここで見つけました https://dev.to/rmion/seven-segment-search-4cmoテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol