Skip to content

Commit

Permalink
feat(2021-day-08): generate codes for each possible number
Browse files Browse the repository at this point in the history
  • Loading branch information
amclin committed Dec 16, 2021
1 parent 17a6552 commit 17cc8f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
3 changes: 2 additions & 1 deletion 2021/day-08/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,8 @@ const descrambleSignal = (data) => {
console.debug(segmentCodes)

return {
segmentCodes
segmentCodes,
charCodes: sortedCodes
}
}

Expand Down
17 changes: 12 additions & 5 deletions 2021/day-08/display.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
const { expect } = require('chai')
const { descrambleSignal } = require('./display')

const testSingle = `acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab |
cdfeb fcadb cdfeb cdbaf`
const testSingle = 'acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | cdfeb fcadb cdfeb cdbaf'

console.debug(
testSingle.split('|')[0].trim()
Expand All @@ -17,11 +16,19 @@ describe('--- Day 8: Seven Segment Search ---', () => {
describe('Part 1', () => {
describe('descrambleSignal()', () => {
const testData = testSingle.split('|')[0].trim()
const result = descrambleSignal(testData).segmentCodes
const { segmentCodes, charCodes } = descrambleSignal(testData)

it('takes scambled string of 10 codes and identifies the letters matching each seven-digit-display segment', () => {
expect(result.length).to.equal(7)
expect(result.filter((code) => !['a', 'b', 'c', 'd', 'e', 'f', 'g'].includes(code)).length).to.equal(0)
expect(segmentCodes.length).to.equal(7)
expect(segmentCodes.filter((code) => !['a', 'b', 'c', 'd', 'e', 'f', 'g'].includes(code)).length).to.equal(0)
})

it('produces a list of character codes for each number that can be displayed', () => {
// There should be exactly 10 numbers
expect(charCodes.length).to.equal(10)
// lengths of each code is predictable as each number has a specific count of segments
const expectedLengths = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
expect(charCodes.map(code => code.length)).to.deep.equal(expectedLengths)
})
})
})
Expand Down

0 comments on commit 17cc8f7

Please sign in to comment.