Skip to content

Commit 621f6de

Browse files
committed
improve formatting
1 parent db39eb3 commit 621f6de

File tree

6 files changed

+10
-50
lines changed

6 files changed

+10
-50
lines changed

day-01/index.ts

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const txt = Deno.readTextFileSync("./day-01/input.txt");
2-
32
const arr = txt.split('\n')
43

54
const targetSum = 2020
@@ -8,27 +7,24 @@ let num1 = Infinity
87
let num2 = Infinity
98
let num3 = Infinity
109

11-
for(let x = 0; x< arr.length -1; x++){
10+
for (let x = 0; x < arr.length - 1; x++) {
1211
num1 = Number(arr[x])
13-
for(let y = x+1; y< arr.length -1; y++){
12+
for (let y = x + 1; y < arr.length - 1; y++) {
1413
num2 = Number(arr[y])
15-
for(let z = y+1; z< arr.length -1; z++){
14+
for (let z = y + 1; z < arr.length - 1; z++) {
1615
num3 = Number(arr[z])
17-
if(num1 + num2 +num3 === targetSum){
16+
if (num1 + num2 + num3 === targetSum) {
1817
break
1918
}
2019
}
21-
if (num1 + num2+num3 === targetSum){
20+
if (num1 + num2 + num3 === targetSum) {
2221
break
2322
}
2423
}
25-
if (num1 + num2+num3 === targetSum){
24+
if (num1 + num2 + num3 === targetSum) {
2625
break
2726
}
2827
}
2928

30-
31-
32-
33-
console.log(num1, num2, num3, num1+num2+num3)
34-
console.log(num1 * num2 *num3)
29+
console.log(num1, num2, num3, num1 + num2 + num3)
30+
console.log(num1 * num2 * num3)

day-02/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
const text = Deno.readTextFileSync("./day-02/input.txt");
2-
32
const rows = text.split('\n')
43

5-
64
const parseRow = (row: string) => {
75
const [range, target, password] = row.split(' ')
86

day-03/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ type SlopeRow = ('.' | '#')[]
55
const slopeMap = input.split('\n').map(row => [...row]) as SlopeRow[]
66
const rowLengts = slopeMap[0].length
77

8-
98
const getCharAtPosition = (row: SlopeRow, pointer: number) => {
109
return row[pointer % rowLengts]
1110
}
1211

13-
1412
const calculateTrees = (slope: [number, number]) => {
1513
let treesCount = 0
1614
let posX = 0
@@ -31,7 +29,6 @@ const calculateTrees = (slope: [number, number]) => {
3129
}
3230

3331
const slopeDirections: [number, number][] = [[1, 1], [3, 1], [5, 1], [7, 1], [1, 2]]
34-
3532
const result = slopeDirections.map(calculateTrees).reduce((acc, count) => { return acc * count }, 1)
3633

3734
console.log(result)

day-05/index.ts

+2-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const input = Deno.readTextFileSync("./day-05/input.txt")
2-
3-
42
const inputRows = input.split('\n')
53

4+
// Copied this function from Ludek https://github.com/ludekstepan/advent-of-code-2020/blob/main/src/day5/index.ts
5+
// Is that cheating?
66
export function getId(pass: string) {
77
let row = 0,
88
column = 0
@@ -29,9 +29,6 @@ export function getId(pass: string) {
2929
return row * 8 + column
3030
}
3131

32-
33-
34-
3532
const ids = inputRows.map(getId)
3633
const max = ids.reduce((a, b) => Math.max(a, b))
3734

@@ -48,23 +45,3 @@ sorted.forEach((id, i) => {
4845
})
4946

5047
console.log(missingId)
51-
52-
53-
// const stage1 = () => {
54-
55-
56-
// console.log(Math.max(...st1Input))
57-
58-
59-
// console.log(getTargetValue(["B", "F", "F", "F", "B", "B", "F"], 64))
60-
// console.log(getTargetValue(["B", "B", "F", "F", "B", "B", "F"], 64))
61-
// console.log(getTargetValue(["R","L","L" ], 4))
62-
// console.log(calculateId(102, 4))
63-
// console.log(calculate('RRR'))
64-
// console.log(calculate('FBFBBFF'))
65-
66-
// }
67-
68-
69-
70-
// stage1()

day-06/index.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const input = Deno.readTextFileSync("./day-06/input.txt")
2-
32
const groups = input.split('\n\n')
43

54
const getSum = (input: string) => {
@@ -11,7 +10,6 @@ const getSum = (input: string) => {
1110
return yesAnswers.size
1211
}
1312

14-
1513
const intersection = (a: string[], b: string[]) => a.filter(c => b.includes(c))
1614

1715
const getIntersectionCount = (input: string) => {

day-07/index.ts

-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const input = Deno.readTextFileSync("./day-07/input.txt")
2-
32
const rows = input.split('\n')
43

54
interface Parsed {
@@ -30,7 +29,6 @@ const parseInput = (rows: string[]) => {
3029
return rules
3130
}
3231

33-
3432
const getAllPossibleBags = (rules: Parsed, target: string) => {
3533
const parents = new Set()
3634
const children = [target]
@@ -52,10 +50,8 @@ const stage1 = () => {
5250
return getAllPossibleBags(rules, 'shiny gold').length
5351
}
5452

55-
5653
const stage2 = () => {
5754
const rules = parseInput(rows)
58-
5955
const nestedBags = ['shiny gold']
6056

6157
for (const bag of nestedBags) {
@@ -69,7 +65,5 @@ const stage2 = () => {
6965
return nestedBags.length - 1
7066
}
7167

72-
73-
7468
// console.log(stage1())
7569
console.log(stage2())

0 commit comments

Comments
 (0)