-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
110 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { lines, loadData, sum } from '@helper'; | ||
|
||
const input = await loadData(); | ||
|
||
const parsed = lines( | ||
input, | ||
(b) => { | ||
return sum(lines(b, (l) => parseInt(l))); | ||
}, | ||
{ size: 'block' }, | ||
); | ||
|
||
console.log(Math.max(...parsed)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { lines, loadData, self, sort, sum } from '@helper'; | ||
|
||
const input = await loadData(); | ||
|
||
const parsed = lines( | ||
input, | ||
(b) => { | ||
return sum(lines(b, (l) => parseInt(l))); | ||
}, | ||
{ size: 'block' }, | ||
); | ||
|
||
const topThree = sort(parsed, self).reverse().slice(0, 3); | ||
|
||
console.log(sum(topThree)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { loadData, mapToInt, sumBy, product } from '@helper'; | ||
|
||
const input = await loadData(); | ||
const instructions = input.match(/mul\(\d{1,3},\d{1,3}\)/g); | ||
|
||
if (!instructions) { | ||
throw new Error('Invalid data'); | ||
} | ||
|
||
console.log( | ||
sumBy(instructions, (group) => { | ||
const factors = mapToInt(group.slice(4, -1).split(',')); | ||
return product(factors); | ||
}), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { loadData, mapToInt, product } from '@helper'; | ||
|
||
const input = await loadData(); | ||
const instructions = input.match(/mul\(\d{1,3},\d{1,3}\)|do(?:n't)?\(\)/g); | ||
|
||
if (!instructions) { | ||
throw new Error('Invalid data'); | ||
} | ||
|
||
const { result } = instructions.reduce( | ||
(acc, instruction) => { | ||
if (instruction === "don't()") { | ||
return { isEnabled: false, result: acc.result }; | ||
} | ||
if (instruction === 'do()') { | ||
return { isEnabled: true, result: acc.result }; | ||
} | ||
|
||
if (!acc.isEnabled) { | ||
return acc; | ||
} | ||
|
||
const factors = mapToInt(instruction.slice(4, -1).split(',')); | ||
return { | ||
isEnabled: acc.isEnabled, | ||
result: acc.result + product(factors), | ||
}; | ||
}, | ||
{ isEnabled: true, result: 0 }, | ||
); | ||
|
||
console.log(result); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
1000 | ||
2000 | ||
3000 | ||
|
||
4000 | ||
|
||
5000 | ||
6000 | ||
|
||
7000 | ||
8000 | ||
9000 | ||
|
||
10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5)) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { expect, test } from 'bun:test'; | ||
import { pair } from '@helper'; | ||
|
||
test('pair', () => { | ||
expect(pair([1, 2, 3, 4, 5])).toEqual([ | ||
[1, 2], | ||
[2, 3], | ||
[3, 4], | ||
[4, 5], | ||
]); | ||
expect(pair([])).toEqual([]); | ||
expect(pair([1, 2, 3])).toEqual([ | ||
[1, 2], | ||
[2, 3], | ||
]); | ||
expect(pair(['a', 'b', 'c'])).toEqual([ | ||
['a', 'b'], | ||
['b', 'c'], | ||
]); | ||
}); |