セブンセグメントサーチ



Advent of Code 2021 Day 8

Try the simulator!


手仕事

Xの解決X = the sum of several decoded 4-digit numbers
入力は
  • マルチラインストリング
  • 各ラインは、以下を含みます:abcdefg|

  • 表す
    桁の
  • 暗号化:0-9
  • の間の秘密番号

  • 今年のお気に入りのパズルに戻る
  • 私は
  • リリースされた日に、この課題の両方の部分を解決しました
  • 私は徹底的に7つのセクション
  • のそれぞれを識別するために、少なくとも1つの方法を発見するのに十分な各桁を分析楽しんだ
    その時の
  • 、私はちょうど2つの星
  • を得るのに十分幸せでした
    今回は
  • 、私は自分のコードをレビューし、別のシミュレータ
  • を作成することに興奮していた

    パート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
    

    ここで視覚化された識別プロセスです


    暗号における楽しい冒険
  • 「少し控えめに」….私は、各セグメントの文字が
  • を表す各セグメントを解読する1つの方法を発見しました
    多くの試行錯誤による
  • .私は、同じ妙技
  • を成し遂げたアルゴリズムを書きました
    このパズルに戻って
  • 今私のアルゴリズムを視覚化するために等しくやりがいのある機会を提供し、対話型にする!