Skip to content

Commit 17cc8f7

Browse files
feat(2021-day-08): generate codes for each possible number
1 parent 17a6552 commit 17cc8f7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

2021/day-08/display.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,8 @@ const descrambleSignal = (data) => {
448448
console.debug(segmentCodes)
449449

450450
return {
451-
segmentCodes
451+
segmentCodes,
452+
charCodes: sortedCodes
452453
}
453454
}
454455

2021/day-08/display.test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
const { expect } = require('chai')
33
const { descrambleSignal } = require('./display')
44

5-
const testSingle = `acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab |
6-
cdfeb fcadb cdfeb cdbaf`
5+
const testSingle = 'acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab | cdfeb fcadb cdfeb cdbaf'
76

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

2221
it('takes scambled string of 10 codes and identifies the letters matching each seven-digit-display segment', () => {
23-
expect(result.length).to.equal(7)
24-
expect(result.filter((code) => !['a', 'b', 'c', 'd', 'e', 'f', 'g'].includes(code)).length).to.equal(0)
22+
expect(segmentCodes.length).to.equal(7)
23+
expect(segmentCodes.filter((code) => !['a', 'b', 'c', 'd', 'e', 'f', 'g'].includes(code)).length).to.equal(0)
24+
})
25+
26+
it('produces a list of character codes for each number that can be displayed', () => {
27+
// There should be exactly 10 numbers
28+
expect(charCodes.length).to.equal(10)
29+
// lengths of each code is predictable as each number has a specific count of segments
30+
const expectedLengths = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]
31+
expect(charCodes.map(code => code.length)).to.deep.equal(expectedLengths)
2532
})
2633
})
2734
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy