Skip to content

Commit a844096

Browse files
committed
🔢 added challenge 18: the digital clock
1 parent aa14480 commit a844096

File tree

4 files changed

+753
-0
lines changed

4 files changed

+753
-0
lines changed

lib/rank.png

-80 Bytes
Loading

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Para esta versión estaré usando TypeScript, en su versión 5.3.2.
3838
| 15 | [**Robot autónomo**](https://adventjs.dev/es/challenges/2023/15) | 🟠 | [TS](./src/challenges/15.ts) | [SPEC](./src/tests/15.spec.ts) |
3939
| 16 | [**Viernes de deploy**](https://adventjs.dev/es/challenges/2023/16) | 🟢 | [TS](./src/challenges/16.ts) | [SPEC](./src/tests/16.spec.ts) |
4040
| 17 | [**Optimizando el alquiler**](https://adventjs.dev/es/challenges/2023/17) | 🟢 | [TS](./src/challenges/17.ts) | [SPEC](./src/tests/17.spec.ts) |
41+
| 18 | [**El reloj digital**](https://adventjs.dev/es/challenges/2023/18) | 🔴 | [TS](./src/challenges/18.ts) | [SPEC](./src/tests/18.spec.ts) |
4142

4243
## Herramientas utilizadas 🛠️
4344

src/challenges/18.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
export function drawClock (time: string): string[][] {
2+
const digitGrid: Record<string, string> = {
3+
'00': '1',
4+
'01': '14',
5+
'02': 'A',
6+
10: '1237',
7+
11: 'N',
8+
12: '56',
9+
20: '1237',
10+
21: 'N',
11+
22: '56',
12+
30: '17',
13+
31: '170',
14+
32: 'A',
15+
40: '134579',
16+
41: 'N',
17+
42: '2',
18+
50: '134579',
19+
51: 'N',
20+
52: '2',
21+
60: '147',
22+
61: '147',
23+
62: 'A'
24+
}
25+
const clockGrid: string[][] = []
26+
for (let i = 0; i < 7; i++) {
27+
clockGrid[i] = new Array(17).fill(' ')
28+
}
29+
clockGrid[2][8] = '*'
30+
clockGrid[4][8] = '*'
31+
const digits = [...time.replace(':', '')]
32+
let currentDigit = digits.shift() as string
33+
for (const index of [0, 4, 10, 14]) {
34+
for (let row = 0; row < 7; ++row) {
35+
for (let col = 0; col < 3; ++col) {
36+
const notFill = digitGrid[`${row}${col}`]
37+
if (notFill === 'N') continue
38+
if (!notFill.includes(currentDigit) || notFill === 'A') {
39+
clockGrid[row][col + index] = '*'
40+
}
41+
}
42+
}
43+
currentDigit = digits.shift() as string
44+
}
45+
return clockGrid
46+
}

0 commit comments

Comments
 (0)