Compare commits

..

34 Commits

Author SHA1 Message Date
ddcf072281 I'm not sure why I'm awake, so I'll do this tomorrow. 2024-12-07 01:57:47 -05:00
David Vereb
156f1e7dac Retried 2023 Day 1 Part 2 after Becky mentioned we never did it. It isn't optimized, but it's done. 2024-12-06 16:49:48 -05:00
David Vereb
86476f7ff0 Initial work done on part 2, but I'm not sure I'll keep the method I'm using. I might have to refactor it out into a function so that it can be called with any particular direction so that when I'm testing potential pathways I can change directions, too. 2024-12-06 16:23:50 -05:00
David Vereb
f9c90b42de Day 6 Part 1. 2024-12-06 10:07:14 -05:00
David Vereb
f0a86a6479 Day 5 Part 2. 2024-12-05 15:34:20 -05:00
David Vereb
80555c4d9c Added solution to Day 5 Part 1. 2024-12-05 09:51:02 -05:00
David Vereb
8fb1a7d95c Day 4 was MUCH easier than REGEX DAY 3. 2024-12-04 11:16:51 -05:00
David Vereb
c4d14c613d Fixed issue where newlines in the data would reset the multiplying flag. 2024-12-04 10:54:49 -05:00
David Vereb
2317ec628a Work on 3. 2024-12-03 18:10:04 -05:00
David Vereb
f3e0917a38 Oops. .end() is one past the end, so get rid of the -1. 2024-12-03 09:45:29 -05:00
David Vereb
40c9bd5e50 WIP 2024-12-02 17:47:56 -05:00
David Vereb
f7083ef726 Added some missing old files and new day2 of 2024. 2024-12-02 14:07:39 -05:00
David Vereb
450b9c790b Added 11 to repo, empty. 2022-12-20 15:46:56 -05:00
David Vereb
f80787cadb Refactored a bit to get the answer for part 2, day 10. 2022-12-20 15:30:39 -05:00
David Vereb
37c1fb045f Part 1 complete. 2022-12-20 15:10:39 -05:00
03b991a582 Added day 10, but then the queue popped in FACEIT. 2022-12-18 23:34:18 -05:00
ad3e9e42bb Added part 2. 2022-12-17 14:51:01 -05:00
68552d259d Part 1 of day 9 complete. 2022-12-17 14:02:12 -05:00
b9cb43378c Finished day 8. 2022-12-17 12:40:42 -05:00
575b9e8aed I'm not proud of this, but it works. lol. (day 8). 2022-12-11 16:59:56 -05:00
39111a9d6a Day 8 attempt 1 is proof that I should get some sleep. I totally forgot about a couple things and this is hack-n-slashed together nonsense. 2022-12-08 23:57:49 -05:00
2139a01252 Refactored #7 out into class files like I should have to begin with. 2022-12-08 23:21:16 -05:00
7ef32aafcb #7 part 2 on my first try, too. Daaaang. 2022-12-08 23:02:53 -05:00
ce7229c13c #7 part 1 works on the first try. 2022-12-08 22:52:31 -05:00
fff4541aca Starting work on #7. 2022-12-08 22:39:30 -05:00
David Vereb
b1a4398782 Added day 6 (two programs. had to rewrite for the second problem). Added starter files. 2022-12-08 08:42:07 -05:00
6b2e3aeab5 Finished part 2. 2022-12-07 21:13:01 -05:00
ada1f27620 First star of 2022 #5. 2022-12-07 21:08:09 -05:00
David Vereb
87161b6375 Added day 4, part 1 and 2. 2022-12-06 08:56:28 -05:00
David Vereb
be4347ab5f Added day 2 and 3, but didn't do them in rust like I wanted to. 2022-12-05 11:08:48 -05:00
David Vereb
209aa39edb Part one of day 2, 2022, but I don't have time to finish this at the moment. 2022-12-02 17:01:07 -05:00
David Vereb
79a6123526 2022 begins. 2022-12-01 14:11:53 -05:00
David Vereb
7717713bde Finished day 11. 2021-12-13 13:59:07 -05:00
David Vereb
4b4b083bd4 Day 10. 2021-12-10 09:10:33 -05:00
91 changed files with 18226 additions and 1 deletions

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
*~
*a.out
*main

98
2021/10/data Normal file
View File

@@ -0,0 +1,98 @@
{<[[<<<[[{[[<<()()>>[([]<>){{}{}}]]]<(<{{}<>}{{}{}}><{<>[]}[{}{}]>)({(())}<[(){}][(){}]>)>}]<<<(<<{}
{[({({([({(((<[]()>[()<>]){[<>[]](<>[])})<<<[]()}>(<()()>)>)}[{((<{}[]>{<>()}){[<>{}]<<><>>})(({[]()}<<>()>)<
(((([{{{<{<[[<()<>><<>{}>]]{<(<>())>}>{<[([]<>)<{}{}>][[<><>][<>[]]]>[{(<>{})[<>()]}<<()[]>[[]<
<<[<([[{{{[({<<>()>}<<<>[]>([]())>){{{{}[]}<(){}>)}]{{[(()())[(){}]]<<[]{}>({}[])>}({<<><>>}<([]<>){()[]}>)}
<[(({[({<<[[[{<>{}}(<><>))<(<>[])[{}[]]>]<[([][])[(){}]]>]([<[()()](<>[])>]<(<{}()>[{}<>])({<>[
(<[[{[[[(<((<<{}{}><[]<>>><[{}<>][<>[]]>)<(<{}<>><{}{}>)[{()[]}<<>()>]>)>[(<{({}{})}[{()[]}{[]<>}]>){<(([]
(([[({{{(<([({[]{}}){{[][]]}])>)[<([[[{}]{(){}}][([]())]]([{[][]}{<>()}](({}()){<>{}})))[{({
{(<<([([(<<[{((){})([]<>)}]<{{{}{}}{{}[]}}<{(){}}{()[]})>><([<[]{}>([]<>)](<()<>>)){<([]<>
{[<<[<{{((({<[[]{}]{{}}>{<{}<>>[<>[]]}})<{[(<><>><{}<>>][{[]{}}]}[[[[][]]<<>{}>]{[[]()][[]<>]}]>)[(
({<(<([{<{<[(((){}){(){}})]>}[{{{{()()}<[]()>}{{<>()}<{}{}>}}[[{{}{}}[<><>]]{({}[]>[[]{}]}]}({{{()()
{[[{([{<<{<(<<{}()>[()]>)<{{()()}}[<[][]>(<>{})]>>{[<{<>()){()<>}>{{()()}[<>()]}][[[{}[]]]<{{}[]}<()(
{{<<<<<[[([{<[{}[]]{()<>}>{<<>()>{{}<>}}}<<{{}()}{()()}>{[()<>]({}[])]>]{[(<{}{}>)<({}[])>]<{({}<>)}{({}())
({(<<{[<<{<(<[<>()][[][]]><[{}<>]({}[])>)[[[<>[]][[]()]]<{[]{}}[{}{}]>]>{[(<[]()>{<>{}})][<{{}}<{
(<<<[[({<[[(<<[]{}>>[(()<>)[<>{}]])<{(<>[])}(<<>()>[[]{}])>]<[({[]()}{{}{}})<{{}()}<{}<>>>]>][[({<<>()>{[]()}
{{{[<[([<(<{[([][])[{}[]]]{[()()]{{}()}}}><[<([][])(<>())><{()[]}({}<>)>]<<<(){}><<><>>>((()()){
[(((([{({<(<(<[]<>>{()[]})><{(<><>){{}[]}}{(()<>)([][])}>)>})}][({{[[{<(<><>){{}()}>((<>()){<>[]
([{<{<({(<[(<({}<>)><{[]}[{}[]]>)(<[[][]]{[]{}}>{{[]}((){})})]{(((()){{}()})(([][])({}{})))[(<()[]><(
[([{{<{(<[{{((()())<[]{}>){{{}<>}<<><>>}}[<([]())>[(()[])<{}{}>]]}{[({(){}}{(){}])<<[]()>{{}()}>
(<[<{{[<<({<<{<><>}><<()[]>[<><>]>>}{[(((){}){()<>}}<<[]()>{(){}}>]{{{{}[]}[{}<>]}[{{}{}}<(){}>]}}){{({
<([([[<[({<<{{[][]}<{}[]>}<<()[]>[()<>]>>>})((<(<[[]]((){})>{([]()){<><>}})>)(<<<<[]<>>[[]()])>>([[
[<<{<(<<{{[({<<>()><{}[]>})<{[<>()](<><>)}[{{}()}{[]()}]>]}}({<[{<()<>>}[<<>>]]((<[][]>{[][
{{(<({[((<([({()<>})[{{}[]}(()<>))]{[{[]<>}][{()<>}]})([({<><>}{{}()})])>)({<(((()<>)(<><>)))>((
[(<{({[<{<[<([{}()](<>{}))>]([([[]<>]<()<>>){<()>}]{{[[]()]{{}{}}}[{[]}{{}<>}]})>}<([<[<<>[]>]{<(){}>{
[[[[<(<({<[[<{()}{{}[]}><[<><>]<()[]>>](<([]{})[{}]>)]>}<[{[[{(){}}]{(<><>)}][<<[][]>{(){}
{(({({[{{((<[([]())((){})]>){[{(<>[])}<([]{})[[]<>]>]({<()<>>[[]<>]}[<()>{<>[]}])})({<([[][]]((){}))([<>{}])
<(<(<<{[<<{<<[()[]][[]()]><([][])<{}()>>}}>[<<<<{}<>>>{[{}][{}{}]}>[<[()()]{{}[]}>[{[][]}([])]]>[[<<[][]>(
<<{{({<<(([{{([][])(()<>)}}(<<[]{}>>)])([{[(()[])]}<{{<><>}<[]<>>}[<{}<>><[]<>)]>]{{<[{}[]]
({[[[[(([[[{<({})([]())>{{<>{}}}}][[<<[]>[<>()]>]{[[[]<>][<>{}]]{[<>[]]}})][[<(<(){}>{()[]})><[[()[
(((((([{{{(<<(<>{}){<>}><(()[])<()[]>>>{[<{}<>>(<>())}<{{}()}>})((([(){}]{<>})[{[]{}}{{}[]
(([([(((<[(({[<>()]{[][]}})[{{[]()>[[]{}]}(<<>{}><{}<>>)]){[({[]}(<>[]))([()()][<>{}])]({({}
[(<({{([[<(((<<>()>[[]<>])({{}()}<()<>>))[[{[]()}<()<>>][{()()}<{}[]>]])>({(<({}{})<()[]}>[{()
{{{[([<{{{([<<<>{}>{()<>}>{<{}()><<><>>}]([{()}]))<{[<()()>{()[]}]{({}[])[<>()]}}>}}}({<(({({
[([([<[<(<[{{{<>()}{()[]}}({()[]}[{}<>])}{[{<>}]([[][]]<(){}>)}]>[[{<[<>()][{}()]>(((){}>[<>[]])}{{{<>(
{{[{{[[<{(<([[[][]]([]<>)])>)<{<<{<>()}[<>()]><((){})<<><>>>>([<<><>>(()<>)]([(){}}{[]<>}))}>}(({{{{[]}{
[[[[({[<({{[[(<><>)]{<<>[]>([]{})}]<[{[]}{()()}]([<>()]([]<>>)>}})>{{<([{<{}{}>{()}}])({<[<>()](<><>)>
{[({<[({[{[({[{}()][[]<>]}((()<>)<{}<>>))<[{{}}({}{})]>]{[<<<>[]>[[][]]>(({}[])(()[]))>{(([]{})({}[]))([
[<<([{{(<<[<[[{}[]]](<[]{}>[<>{}])>[[<{}[]>(<>[])]{([][])[()[]]}]][[{{()[]}[<>{}]}(<<>{}>[[]
<[(([{([([<{[[(){}]<<>{}>]}[[[()()]{{}<>}]]>[[{({}{})[()()]}([()()][<>[]])]{<[[]<>][[][]]>}]]{{<{[<>
[<[[[[([[{[[<[{}{}]([]<>)>[({}[])<[]<>>]][<{()()}[<>[]]>([[]]<<><>>)]]}([<{{{}[]}}{(()<>>({}[
<[<{[(<{({[<[[[][]]([][])]<([]){{}<>}>>[({<>{}}<[]>)]]([[([]{})[[]()]][[[]{}]({}{})]](<[{}<>
({[<([(<[[<([[(){}]<<>{}>])({[[]{}]<()[]>}<<[]<>>{[][]}>)>{<[<[]()><{}[]>]([<>()]({}[]))><(
({<<<{<({[[{[{<>{}}[<><>]]}{(({})[()()])<<()<>>([]{})>}]]]{<{{([[]<>](<>[]))[[{}()]({}())]}}>((<([{}<>])>{{<[
[{([{[[{{<{<[{[]()}<[]{}>]>({<{}[]>{<>[]}})}[(({{}<>}<{}<>]){[[]{}]({}[])})]>}}]({([[([<()()>{[]
<[{([([{[{<(([<>[]]{<>()})<{{}<>}>){([<><>])<(()[])<<>{}>>}><{{[{}<>]{<>}}[(())[()<>]]}<{[{}{}]{{}{}}}<{{}<>
[{<<([{{(((<{<<>()>[{}()]}>{<<<>[]><[]()>>}){[(([][])([]()))<{{}[]}[[]()]>][[{{}<>}({}{})]{({}{})(<
{({[((<([[[{{([])[()()]}({{}{}}))<(<[]<>>[()[]])>]<<([[]<>])<[<>()][[]<>]>>({[<><>]{{}[]}}({()[]
{[(<(<{[({[(<<[]>{<>{}}>[{<><>}([]())])(<[[][]]<()<>>>[(()[])])]<{[{()[]}[<>{}]]}[{<(){}>(<>{})}<<<>()>>]
(<{<[<({{{{([({}{})[[]{}]]({{}<>}<()[]}))}(<<{<>()}{()<>}>{[<>{}][()[]]}>{<<[][]>{<>()}><(<>{})<{}[]>>})}
{(<<{[({<<[(<{{}{}}<[]<>>>((<>())([]<>)))]>><<({<{[]<>}([]<>)>{[()()]}}<<{{}<>}<()()>>(<()()
<([([<(<[({[[({}()){()<>}](({}{})(<><>))][{({}<>)<{}{}>}{([]){(){}}}]})]>)<[[{<{{(()){<>[]}}({{}()}
<<<([{[({{{((<{}()>{()()})[[<>()]])[[[{}()]<{}()>]{{[]<>}{{}())}]}<<{<<>><<><>>}[{{}[]}(<><>)
<([<[<{[[[{[{[<><>][{}<>]}(<[]{}>)]}([{{<>()}<{}[]>}{([]<>)[(){}]}]<{((){})<[]()>}[<[]()><()[]>]>
[([[[[[({{[(<[{}<>]<{}()>><[<><>]{<>()}>)]}<{(<(()<>)<{}{}>>{{()<>}(()()}})}>})(<[<([<<>[]>((){})]([[]<>]<()
{(<[[{(((([[([{}()]<{}()))[({}{}){[]}]](<<<>[]>>([<>{}]))][(<({}{})<()[]>><<[]{}><{}[]>>)])(<([([][])[
({(([{{<{{{<[<<>[]>{()<>}][([][]){()<>}]>([<()>(<><>)]<{<><>}<[]>>)}<{[[<>[]][<>{}]]<{<>()}{[][]
{[([[[(([<{<{[[]<>]<<>()>}<<()()>([]{})>>[<<()[]>(<>())>[(()<>)]]}>]{{({{{{}[]}({})}<{{}<>}[[]()]>}((
[<([[<[{{{[[[<<>{}>]{<()[]>{[]<>}}]{([[]{}]({}()))}]}}}(<{<[[({}{})<()()>]]({({}<>)[[]]}{[<><>]{<>{}}})>(<[
<<(<<{{(({<[<<[]{}>{()()}}[[()[]]]]{[(<>{}){<>}]{[{}](<>)}}><{<(()())<[]<>>>[<(){}>(<>[])]
{<(<[<[(((<{((()[])([]<>))([[]<>]({}[]))}><<([<>())<[]<>>)(<{}[]>({}<>))>[[([]())]({()()}{{}<>})
[[((<[[[{{<{<{{}()}[{}()]>{{[]{}}[<><>]}}>}<{[<[(){}]<<><>>]([{}<>]<<><>>)]}(<<[{}<>]<<>{}>
<[{{[[{<[{(({[(){}]({}{})})[([{}<>][()()])[<[][]><{}<>>]])}](<({(([]<>){()[]})[([]())((){})]}{{{<>{}}<[]()>}<
<{((<([[{<<[(<{}()><{}[]>)]>[([{<>()}<()()>]<{()[]><()[]>>){<[{}[]]>[{[][]}(<><>)]}]>{{[{{{}<>}{<>}}[[(){}]<(
{<[({(<{{[([{{[]{}}((){})}[[{}[]]<{}()>]]((<[]<>>)<([]()){{}[]}>))(<<{()[]}{[]})>[[(()())]{[()<>][<>(
<<{[[[[{<({<[[{}()]]{{[]<>}{[]}}><{{{}()}({}{})}>}{([({}[])({}())](({}[])))[<{[]<>}[<>()]><<[]<>>(<>[])>]}
[(([<<[{[{<({{()[]}<<><>>})[[([]())[[]{}])(<<>{}>)]>(<{{[][]}[{}()]}([{}{}][(){}])>((<<>[]>(()
[({<<[[<{[<<({[]()}<()<>>)>]]{{<[[[]][{}<>]]>}{([[<>{}][{}{}]]<((){})(()[])>)}}}([{((<{}[]>)[<{}[]><{}()>])}
{[[((<[{<<([{<<><>>([]{})}<(<><>)<<>()>>][{[[]{}]{()()}}<({}{})([][])>])><<{({<>{}}[<>()])((
[[[<{{(<((([{<[]{}>({}<>)}[<<>()>]]<<(()[]){{}[]}>{(()<>){{}<>}}>){{{(()())[<><>]}[[[]<>]{<>[]}]}}))[
(<({[({[[({{<{<>{}}<()[]>>[{(){}}<<>[]>]}[[<[][]><()<>>]({<>{}}{[]()})]}{(([[]<>][{}[]])(<[]<>>([
{([<{[<({{{({[[][]][()()])[<<>()><[][]>])}<{{{[]()}[{}()]}{{<>()}{<>}}}((({}())<{}{}>){(<>{})[<>{}]})>}})(((
([[[[[[{(((((<<>()>[[]<>])<{()()}[()<>]>){<[()[]]<<>[]>>(<<>{}}{{}[]})}))<<[([()()][[]()])[{()[]}([]())]][<([
({{((((<{<[{[(<>{})][<()()>[[]()]]}]{({(<>())[[]()]}{<[][]><[][]>})}>}>{<<{{(({}())[<>])((()[])<[]<>>)}}[
<(<[[[<<{([<<[[]<>]{<>[]}><{()()}([]<>)>>]{<{(<>())((){})}{[{}{}]<<>{}>}>})({([[{}{}]])[(<<>()>[
{[(<{<[[{<{{(<()[]><<>{}>){[()<>]<{}<>>}}[[[<>{}][[]<>]]]}<[[({})<<>[]>]]{{<()<>><<>[]>}<{()[]}((){}
({[{(<<{[<{({[()()]{{}}}<({}{}){()()}>)}<{(({}{})[<>[]]){([]())[[][]]}}{(<[]<>)[()])[[<>()]]}>>
(({<<[<[<<<({<{}[]>({}{})}{<{}[]><{}[]>})>>(<<(<()()>{[]{}})({()<>}[()()])>[{[{}()][[]]}({<>()}}]>(
<<(<(<[{([{<[[<>{}]<{}<>>]>{<(()[])(()())><{<>[]}{()()}>}}([{({}<>){<>{}}}{{<>[]}[{}{}]}]([<[]()>((){})
{[{([({[[<<<{{[]{}}<[]{}>}[<()[]><[]<>>]>([{{}[]][[][]]]{{(){}}({}[])})>(<{[<>{}](()<>)}>{[<[]()>
([[[<(<{[({<({()()}{<>()})((<>[])<[]<>>)>}<{<<{}()><<>>>}({{{}[]}}[(()[])[()<>]])>)<[<((()())[<>{}])(
{<(((<[((((({<[]>[[]{}]}))[(<[[][]][{}{}]>){{[<>()][[]<>]}([()()](<><>))}])){(<[{[<>()][{}()]
({([{<(((<{[<[{}[]]<<>>>({{}[]}[[]()])]([<(){}>])}{<[{<>[]}{[]<>}][<<><>){<>{}}]>[<((){})([]{})>[[{}{}][()
<[{[<[{[({{<(({}<>}[[]()])>({{[][]}}<[(){}](()[])>)}})([[{{<<>()>([]{})}[<<>{}>[<><>]]}]])]
{(<{([{[[({[(<[]{}>)({{}[]}{()()}))<{(()[])}[[()()]{{}[]}]>}<{<(()<>)>{{[]{}}({}())}}({{{}[]}{<
[<<{<{<<(<([<(<>()){[]()}>[({}<>)({}<>)]][(([]{}){()[]})[{{}()}(()())]])>{([{{()[]}<<>[]>}<{<>[
{{[[(([([({([([]<>)(()())][{<>()}{(){}}])})])]([{{[<{{{}<>}(<>())>{[()()]<<>[]>}>[{(()){{}[
[({({({(({{(<[()()][{}<>]>[[{}()]{(){}}])<[<<>[]>][<{}>(<>{})]>}(((({}())({}{}))){{(()[])<[][
<(<(<[([<[{[<(()<>)<()[]>><(<>())([][])>]{<[{}<>]{{}()}>{[[]{}](<>{})}}}<[<([]{})><{{}<>}([]())>]>]>
<<<(<<[({{{<{({}<>)<()[]>}<[()<>]{(){}}>><{[[]()]<[]{}>}[({}{})<(){}>]>}(<[<<>[]>{()[]}]>)}[<{[<{}>[{}{
{(<((<[{{[[[[<{}{}]<{}()>]][{({}{})<<>{}>}[<()[]>(()())]]]{([<[]()><[]{}>](<{}()>))({<<><>>(<>())}{
{({{[[<[{<{{(<<>>)(<[]()>[()])}([({}<>)])}[[{[()<>][()[]]}]({<[]<>>{<>()}})]><<(<<{}()>{<>[]
{{{[{[<<{[[{[{{}<>}<[][]>]{(()[])<<>()>}}[<{()()}[(){}]><<()[]>>]]{<((<>{})({}()))[<(){}>([][])]>{({{}[]}<
<{{[<{({{{[<{{<>()}{{}()}}>]<{<[()[]](<><>)><[<>[]]{(){}}>}<([(){}]<{}{}>){(())}>>}[([{[[]<>][{}<>]}[{()}(
[<<[{{(({({<{{{}{}}{<>[]}}({[][]}{<>[]})>[{[{}<>][<>[]]}[({}[])[[]<>]]]})}))<(<[[<(({}()))[<<>()>{(
{<<([<{({[{{[({}[])<<>{}>]([()<>]<(){}>)}<([{}[]]({}{}))>}[<<<<>{}>[[][]]>{<<>[]><()>}>[<<<>><[][]>
[({(<({[<[{{[<<>[]>[()[]]]<<<>[]>>}}<{([{}[]](<>{}))[{<>}{{}<>}]}(<<[][]>>[{[]<>}])>]>[(<(({<>[]}{<><>}))(<
{<[[{{<<{(<(<([]<>)[[][]]>[([]{})[<>{}]])<[{<>()}{[]<>}]>>>[{(({()()}[<>[]]){({}())<[]<>>})}[(<{<>
{[[{{{<[<[{<(({}{})[{}()])[(<><>)({}())]>}{[<{[]{}}[()[]]>]<{[()()]<[]()>}<[[][]]>>}]>{{({{{()[]}{{}(
<{[<([{{[[<(<{<><>}[{}{}]><((){})>){[[()()][()[]]]{[[]<>]}}>]<<(<({}[])<{}[]>>{(<><>)<[]()>}){(<

10
2021/10/example_data Normal file
View File

@@ -0,0 +1,10 @@
[({(<(())[]>[[{[]{<()<>>
[(()[<>])]({[<{<<[]>>(
{([(<{}[<>[]}>{[]{[(<()>
(((({<>}<{<{<>}{[]{[]{}
[[<[([]))<([[{}[[()]]]
[{[{({}]{}}([{[{{{}}([]
{<[[]]>}<{[{[{[]{()[[[]
[<(<(<(<{}))><([]([]()
<{([([[(<>()){}]>(<<{{
<{([{{}}[<[[[<>{}]]]>[]]

34
2021/10/main.py Normal file
View File

@@ -0,0 +1,34 @@
openers = ['(', '[', '{', '<']
closers = [')', ']', '}', '>']
points = [3, 57, 1197, 25137]
score = 0
with open('data', 'r') as fp:
# NOTE(dev): We assume all lines are the same length
for line in fp:
stack = []
for ch in line.strip():
line_score = 0
if(ch in openers):
stack.append(ch)
elif(len(stack) == 0):
try:
i = closers.index(ch)
line_score += points[closers.index(ch)]
except ValueError: # not a closer
pass
else:
try:
i = closers.index(ch)
last = stack[-1]
stack.pop()
if(last != openers[i]):
line_score += points[i]
score += line_score
print(last, '!=', openers[i])
break
except ValueError: # not an opener or closer!
pass
score += line_score
print(score)

33
2021/10/main2.py Normal file
View File

@@ -0,0 +1,33 @@
openers = ['(', '[', '{', '<']
closers = [')', ']', '}', '>']
points = [3, 57, 1197, 25137]
scores = []
with open('data', 'r') as fp:
# NOTE(dev): We assume all lines are the same length
for line in fp:
stack = []
corrupt = False
for ch in line.strip():
if(ch in openers):
stack.append(ch)
else:
try:
i = closers.index(ch)
last = stack[-1]
stack.pop()
if(last != openers[i]):
corrupt = True
break
except ValueError: # not an opener or closer!
pass
if(not corrupt and len(stack)):
line_score = 0
for ch in reversed(stack):
line_score *= 5
line_score += openers.index(ch) + 1
scores.append(line_score)
scores.sort()
print('scores[int(', len(scores), '/ 2 )]')
print(scores[int(len(scores) / 2)])

10
2021/11/data Normal file
View File

@@ -0,0 +1,10 @@
1254117228
4416873224
8354381553
1372637614
5586538553
7213333427
3571362825
1681126243
8718312138
5254266347

10
2021/11/example_data Normal file
View File

@@ -0,0 +1,10 @@
5483143223
2745854711
5264556173
6141336146
6357385478
4167524645
2176841721
6882881134
4846848554
5283751526

42
2021/11/main.py Normal file
View File

@@ -0,0 +1,42 @@
grid = []
to_flash = []
for line in open('data', 'r'):
grid_line = []
for ch in line.strip():
grid_line.append(int(ch))
grid.append(grid_line)
flashed = 0
for step in range(0, 100):
# Step 1: Increment
for y in range(0, len(grid)):
for x in range(0, len(grid[y])):
grid[y][x] += 1
if(grid[y][x] > 9):
to_flash.append(tuple([y, x]))
if(len(to_flash) == len(grid) * len(grid[0])):
print('all flash step #', step + 1)
# Step 2: Flash
while(len(to_flash)):
cell = to_flash[-1] # take the last one
to_flash.pop() # remove
flashed += 1 # count
for y in range(-1, 2):
new_y = cell[0] + y
if(new_y >= 0 and new_y < len(grid)): # in bounds
for x in range(-1, 2):
new_x = cell[1] + x
if(new_x >= 0 and new_x < len(grid[y])): # in bounds
grid[new_y][new_x] += 1
if(grid[new_y][new_x] == 10): # JUST flashed
to_flash.append(tuple([new_y, new_x]))
# Step 3: Reset (if flashed)
for y in range(0, len(grid)):
for x in range(0, len(grid[y])):
if(grid[y][x] > 9):
grid[y][x] = 0
print('Step #', (step + 1), ': ', flashed)

49
2021/11/main2.py Normal file
View File

@@ -0,0 +1,49 @@
grid = []
to_flash = []
for line in open('data', 'r'):
grid_line = []
for ch in line.strip():
grid_line.append(int(ch))
grid.append(grid_line)
flashed = 0
step = 0
#for step in range(0, 100):
while(True):
# Step 1: Increment
for y in range(0, len(grid)):
for x in range(0, len(grid[y])):
grid[y][x] += 1
if(grid[y][x] > 9):
to_flash.append(tuple([y, x]))
# Step 2: Flash
prior_flash = flashed
while(len(to_flash)):
cell = to_flash[-1] # take the last one
to_flash.pop() # remove
flashed += 1 # count
for y in range(-1, 2):
new_y = cell[0] + y
if(new_y >= 0 and new_y < len(grid)): # in bounds
for x in range(-1, 2):
new_x = cell[1] + x
if(new_x >= 0 and new_x < len(grid[y])): # in bounds
grid[new_y][new_x] += 1
if(grid[new_y][new_x] == 10): # JUST flashed
to_flash.append(tuple([new_y, new_x]))
# PART TWO ANSWER
if(flashed - prior_flash == len(grid) * len(grid[0])):
print('all flash step #', step + 1)
break
# Step 3: Reset (if flashed)
for y in range(0, len(grid)):
for x in range(0, len(grid[y])):
if(grid[y][x] > 9):
grid[y][x] = 0
print('Step #', (step + 1), ': ', flashed)
step += 1

102
2021/14/data Normal file
View File

@@ -0,0 +1,102 @@
ONHOOSCKBSVHBNKFKSBK
HO -> B
KB -> O
PV -> B
BV -> C
HK -> N
FK -> H
NV -> C
PF -> K
FV -> B
NH -> P
CO -> N
HV -> P
OH -> H
BC -> H
SP -> C
OK -> F
KH -> N
HB -> V
FP -> N
KP -> O
FB -> O
FH -> F
CN -> K
BP -> P
SF -> O
CK -> K
KN -> O
VK -> C
HP -> N
KK -> V
KO -> C
OO -> P
BH -> B
OC -> O
HC -> V
HS -> O
SH -> V
SO -> C
FS -> N
CH -> O
PC -> O
FC -> S
VO -> H
NS -> H
PH -> C
SS -> F
BN -> B
BF -> F
NC -> F
CS -> F
NN -> O
FF -> P
OF -> H
NF -> O
SC -> F
KC -> F
CP -> H
CF -> K
BS -> S
HN -> K
CB -> P
PB -> V
VP -> C
OS -> C
FN -> B
NB -> V
BB -> C
BK -> V
VF -> V
VC -> O
NO -> K
KF -> P
FO -> C
OB -> K
ON -> S
BO -> V
KV -> H
CC -> O
HF -> N
VS -> S
PN -> P
SK -> F
PO -> V
HH -> F
VV -> N
VH -> N
SV -> S
CV -> B
KS -> K
PS -> V
OV -> S
SB -> V
NP -> K
SN -> C
NK -> O
PK -> F
VN -> P
PP -> K
VB -> C
OP -> P

18
2021/14/example_data Normal file
View File

@@ -0,0 +1,18 @@
NNCB
CH -> B
HH -> N
CB -> H
NH -> C
HB -> C
HC -> B
HN -> C
NN -> C
BH -> H
NC -> B
NB -> B
BN -> B
BB -> N
BC -> B
CC -> N
CN -> C

45
2021/14/main.py Normal file
View File

@@ -0,0 +1,45 @@
str = ''
data = {}
letters = []
with open('data', 'r') as fp:
for line in fp:
if(' -> ' in line):
pair = line.strip().split(' -> ')
data[pair[0]] = pair[1]
elif(len(line) > 1):
str = line.strip()
for ch in str:
if(not ch in letters):
letters.append(ch)
letters.sort()
# # DEBUG(dev):
# print(data)
# print(str)
# print(letters)
for step in range(0, 40):
print('BEFORE:', str)
new_str = ''
for i in range(0, len(str) - 1):
lookup = str[i:i+2]
print(lookup)
if(lookup in data.keys()):
new_str += str[i] + data[lookup]
else:
new_str += str[i]
new_str += str[-1]
str = new_str
counts = {}
for ch in str:
if(ch in counts):
counts[ch] += 1
else:
counts[ch] = 1
counts_list = list(counts.values())
counts_list.sort()
print(counts_list[-1] - counts_list[0])

45
2021/14/main2.py Normal file
View File

@@ -0,0 +1,45 @@
str = ''
data = {}
letters = []
with open('data', 'r') as fp:
for line in fp:
if(' -> ' in line):
pair = line.strip().split(' -> ')
data[pair[0]] = pair[1]
elif(len(line) > 1):
str = line.strip()
for ch in str:
if(not ch in letters):
letters.append(ch)
letters.sort()
# # DEBUG(dev):
# print(data)
# print(str)
# print(letters)
for step in range(0, 40):
new_str = ''
for i in range(0, len(str) - 1):
lookup = str[i:i+2]
if(lookup in data.keys()):
new_str += str[i] + data[lookup]
else:
new_str += str[i]
new_str += str[-1]
str = new_str
print('Step ', step+1, ', length', len(str))
# NOTE(dev): un-indent this (take it out of the for loop) for just a final answer
counts = {}
for ch in str:
if(ch in counts):
counts[ch] += 1
else:
counts[ch] = 1
counts_list = list(counts.values())
counts_list.sort()
print(counts_list, counts_list[-1] - counts_list[0])

100
2021/15/data Normal file
View File

@@ -0,0 +1,100 @@
9165985876154699219988192797299938946759548993842382179897895847959995468789384779887969965834298757
9998264799399739852669159899969915752881369928979589425659869512849898348591988899941938989958981368
8899439372928798295981284899995498957198997822776999766989269673341115866632499916582179985999797178
9421373314798816327241583824298987799745811978869899899899999689988933652499891999899718759652641398
9949959989598519929632977671926983547787167773939739198988988851889519228348573848979828599971727943
2989192448779756984992587956689999842746119939998567894718899918799954281648927282191699499764931166
9536499426969676189784443598979559899499773119978188394689557995599331996979736693529419681251956996
1751936936954979779895998917863998697858138691879749999727789764741997539275579593798975539798818972
7274746616894977772987689459988988891794769772199789185982726479992789563994126143759648659653627929
9768211178649269995923493912176968666679999859829913848396992289798892197419967914777851877899477278
9548265381888989898295865115497574817515178999881998168798969539989897979118423366393898169329939816
5346816194398971492996938739782725986596757996472498951666679779287752997484725936582558299359964812
2169889968977588483272986596967998729999883958728879796999737989942928997399898577324799379798165679
5756791285489939716695977945746649394898965799971791856215827997699758829299499895496993375817688889
1189911823962199612255959754716953775367595418858921381973577497988994381699599376948136788285998274
6979939299876267486998569159464199464965974658469723835541132825855912999935783995325776519991867869
7829881839997878488734339898145124968389716637926975397882799631985728918519668146942356911683694975
4973997156985297758563699888285794535932928974966978296562139199889893476728999942416259889912711471
9534797994999788999759474799734844192166842694971197691854895641895188586895455192589986798997913693
2819784988295365719599997589858664998979399989735399884134499895873389479651295996498866989999839974
6129944129969453989699888866976269999128469799982997963676678293639494188967181417362922546475281598
9716591619494494558731969871917781639763288288691962634219628479989988828962651246459129568974491171
7894482759988943587818779691955666934841799931371572868778856815865991124376396974593984947897442991
1858394839149329949299818139987736884848178995897668499996188998667699618978779495959989927996996397
9917119977481935978699197129381282957978683881779735689583195993458959989897975199999285945815997999
1699128644295779552889817864638995225998895287579281281998594696644213479297199692979781937997179875
8289472999575769888986161678994171392789714988719932799199558696689379278929798887977551878788398787
9175199787918919864185866129967892999898318993291829953849829788999738939999469848949591989149962712
6199185639948988878676462732119197225882925435874993975768952939825978994996892549999699984912695356
3396488583898545189449831859997919671368765298895692847986994925119921865818912189499168979958896494
9938398336984195997576689194134985999635325783571526493894394589917988793989755746999698829649589393
6985999497989855798918845568728129349777627978979362788359497952698956998292996918648692699694349887
1983998898992942689898989791697792913121476987631657959299998868769559979688918876893688862439185197
7357776772998794811999929459919571597899775797198394831478974157594549666253368399586349899987699999
7959339994696971922632949191545959757987989979787788169979748972545188912811999284691666989915589771
9759961834557989443271499976572889278289319995879484972649589489199519573998999779383692242897767588
9179641759649515678926897874488858988897787895855979191899776967749898123692484838554413919817918963
6839761379993114699928685489349481791394595895995488717149328139993956495742445794747189959976877649
7719888678899926948979191678165949542927483596385943836398298659699148778343914768999898197267997991
8769727958885176392169934146934172488871783986753744485932511888999799159194751538987186924419884479
8991999992999929999897984599767977994699827768813861298818993288386943869782797583698682188885283399
7618891897968939798498999399278379698962758659288163913969875574557443483997692961986999939899819481
8879168556577788339549879912587944289995777798881688244889799389891799876819699576957557971877898128
9291695492736749179768777989972456198819896897386591181956469899994155718299785968686938589318979479
7795999789358882518386787487224292238877893956695912892699678996798249199324897986249725799479399977
7157587585956489829119899759896997988918879818491999931184192141949199172799356679472486896195864474
8369998998796539973399979987949986863639829688617494995142799799778639869918868177475771699198897648
6597979998999646797717999135983617949772192975367951599248888799957499785994774771558359664883693989
8494399497884369731998936499887638658943929616778716995355827188745777858983426799559721799739362629
7988688889359569698815957687229757873596999199938929146584679599188685439814466838789683219554419476
9247298485768968989794782295879689497761879956994316114992795924987262939579993889586584967699911179
9585318399982677997578979671589977319169586337196999959189521499887711992343851295981988819951696391
9688419987598317988779256198579659993398274893319912676925791429994831998147985462785322692958417991
9162526572947889939619891135679859992512868978725888837198497899147199825914711544192984934699878858
9997992172487298739215471619688889939819838188921969391991648949979166298795194179866892977317488668
4342969513889787361777751972798659462495119377122327857968869995779944989446988786669168689799978198
9991989792887933999782849992885388199539897175961949179928388186994694998865752811971681796835228899
9689884899572994167989994913659819996941825788877898819911788969419991277989227389959829597962878797
9919879157714445923163829999735888889724892834556637899899999974386932299127993655996239789769999544
8158429263197997788393974998999939783878693949897825898975995959979986635699272784592895953298769979
6933156399191389719992767671896649494989689977121886269912939799779176467784638649979932992778611947
9937886748328953482685979758934658999819989845699372899934596991259755741819979779889881397565568579
6628287411551868899648999511774894539834357749799788481594933187788979179772699757813897655969637759
1681758889993977881987844998586378799289969999542735618971489988849699628668119898999679199493949189
7756952966791755589777886975949697297729368719914568929921989979278297994486928996985666791996513546
7959939142776881868999785876799728991368773296952962918971941199687791336941297836969992566198117899
9919799591383641992451999795686291882995991159937526287799259396499782592953878378919512331399769295
9979988697799299993248298599458499952548969526718987894849849961566959196296836979299696595499951269
8989115299788834687596939899183482448889849883899881337161943668283395379982966119363885868799817686
3917979748934696925996487991958936699899582264499928897937594999993391587881813378359971812919779972
7798825938413749319999785941489868587674397449269738978317389938919984622199581498529938819682972471
7749948181969657924978787838596695869966969369158962427829991499668977295896254897998989743989952389
6398998955793159938819887788968371888968395499298999755899949268632898528951445886293997299392969779
9539983773686993498991392899889572558299175987819981797981886747694169489893727157979378595839496298
9599999287193787789729986389617989992374479972959749982818939999895692869845931449861767839389829149
4889176836968695418797941267779399488818276299865898498649489796971967884999112828966259271689857259
7139139187955994831738585298962698949981181887589699969919418116293969946431635243579918986885919619
7935837589876972417397869798312741789988882795986987744696696629647813993997762979599189148298958581
8791284382878199766798982957837371997961791491996313339915819373928948979938596612197699691473969914
1372974376943738718696489825854989786382983999879965536283589995655483569334269859559761199879679291
9719671746885959293824693968698399315424948599622489865269469961617669916732853892695261177787994496
7849319899791243818799879975258532467699699999398269787199341236894749619399991856788917729181194197
9148263323757681139949799197198549259446781912979561927929891898923997238737858757915394778591127667
1945591989843987198391756487965892217958111951642219915715439797998675786222936815998966826782589594
5254778838276178988551266998775337643868756772978159294191819424888551874271745598136847865594999289
3998557499888479397893111869792537426834985941959185929798919875628859952429849886849639853349182496
8958877677623879221669563361998988956937492798913659491897715599879989983979859984661929198589817564
9989969281947994946512996153988898382127889834868897498898867797998892148557494839482788798269898496
9779851919689459958899912662756981619298821434879339749956713988385759469959788279765789991925947918
4196471827218751217999955385399979199189581896987488518319752529829892282899638773984698854832217793
5968399569814182278918739959691249997958587277596698779311494824187981838837892479347738267879912541
8659894118598996577145167494795592898597175979829589886499183913197276893979278479678988218798894991
6649277899864442637895792699719172999998662937819979979769821897696686788719291967114346689819212978
6699889979874997773889958977455779952988466968759738452847569993821963796198741514377779188577811889
1173976886399735895884999486498511998399588328832288555979166889776686858695414825689877994898917949
9629147139882191719857926675389957799296279989442991999622669639755767892922474778888299984452999898
4391879947595258989144156986799899833458894496218777872997391217987623967998848296898891312888421579
9362699299759899879589911968947655251988997896874791778876389919939496782959848979971163281597161779
1652179878596567755189593919723287659886989991199789326995581692999815373488857495418291969165215199
9788389477191759669998798979888832998683445278988415997594187969167388689899997659918914818788982937

10
2021/15/example_data Normal file
View File

@@ -0,0 +1,10 @@
1163751742
1381373672
2136511328
3694931569
7463417111
1319128137
1359912421
3125421639
1293138521
2311944581

12
2021/15/main.py Normal file
View File

@@ -0,0 +1,12 @@
class Point:
shortest_path = []
data = []
for line in open('example_data', 'r'):
data_row = []
for ch in line.strip():
data_row.append(ch)
data.append(data_row)
for row in data:
print(row)

2238
2022/1/data.txt Normal file

File diff suppressed because it is too large Load Diff

57
2022/1/main.cpp Normal file
View File

@@ -0,0 +1,57 @@
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Couldn't open file." << std::endl;
return -1;
}
static bool last_line_blank = false;
std::vector<long> numbers;
long total = 0;
long most = 0;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
{
if(!last_line_blank)
{
numbers.push_back(total);
if(total > most)
most = total;
total = 0;
}
last_line_blank = true;
}
else
{
last_line_blank = false;
total += std::atoi(line.c_str());
}
}
std::cout << "Most: " << most << std::endl;
std::sort(numbers.begin(), numbers.end());
if(numbers.size())
{
int three = 3;
long total_total = 0;
for(int i = numbers.size() - 1; i >= 0; i--)
{
if(three-- > 0)
total_total += numbers[i];
}
std::cout << "Top 3: " << total_total << std::endl;
}
return 0;
}

38
2022/1/main.rs Normal file
View File

@@ -0,0 +1,38 @@
use std::fs;
fn main()
{
let contents = fs::read_to_string("data.txt")
.expect("Could not find data.txt.");
let mut numbers = Vec::new();
let mut total = 0;
let mut max = 0;
for line in contents.split('\n')
{
if line == ""
{
if total > max
{
max = total;
}
numbers.push(total);
total = 0;
}
else
{
let i = line.parse::<i32>().unwrap();
total += i;
}
}
println!("Max: {max}");
numbers.sort();
let mut top_three = 0;
for amt in &numbers[numbers.len() - 3..numbers.len()]
{
top_three += amt;
}
println!("Top Three: {top_three}");
}

2
2022/10/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

146
2022/10/data.txt Normal file
View File

@@ -0,0 +1,146 @@
addx 1
addx 4
noop
noop
noop
noop
addx 6
addx -1
noop
addx 5
noop
addx 5
noop
noop
noop
addx 1
addx 3
addx 1
addx 6
addx -1
noop
noop
noop
addx 7
noop
addx -39
noop
noop
noop
addx 7
addx 3
addx -2
addx 2
noop
addx 3
addx 2
addx 5
addx 2
addx -8
addx 13
noop
addx 3
addx -2
addx 2
addx 5
addx -31
addx 36
addx -2
addx -36
noop
noop
noop
addx 3
addx 5
addx 2
addx -7
addx 15
addx -5
addx 5
addx 2
addx 1
addx 4
noop
addx 3
noop
addx 2
addx -13
addx -16
addx 2
addx 35
addx -40
noop
noop
addx 7
noop
noop
noop
addx 5
noop
addx 5
addx 10
addx -10
noop
noop
noop
addx 3
noop
addx 16
addx -9
noop
noop
noop
addx 3
noop
addx 7
addx -32
addx 35
addx -38
addx 22
addx 10
addx -29
addx 2
noop
addx 3
addx 5
addx 2
addx 2
addx -12
addx 13
noop
noop
addx 7
addx 5
noop
noop
noop
addx 7
addx -6
addx 2
addx 5
addx -38
addx 1
noop
noop
addx 2
noop
addx 3
addx 5
noop
addx 4
addx -2
addx 5
addx 2
addx 1
noop
addx 4
addx 4
addx -14
addx 16
noop
addx -13
addx 18
addx -1
noop
noop
noop

146
2022/10/larger.txt Normal file
View File

@@ -0,0 +1,146 @@
addx 15
addx -11
addx 6
addx -3
addx 5
addx -1
addx -8
addx 13
addx 4
noop
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx 5
addx -1
addx -35
addx 1
addx 24
addx -19
addx 1
addx 16
addx -11
noop
noop
addx 21
addx -15
noop
noop
addx -3
addx 9
addx 1
addx -3
addx 8
addx 1
addx 5
noop
noop
noop
noop
noop
addx -36
noop
addx 1
addx 7
noop
noop
noop
addx 2
addx 6
noop
noop
noop
noop
noop
addx 1
noop
noop
addx 7
addx 1
noop
addx -13
addx 13
addx 7
noop
addx 1
addx -33
noop
noop
noop
addx 2
noop
noop
noop
addx 8
noop
addx -1
addx 2
addx 1
noop
addx 17
addx -9
addx 1
addx 1
addx -3
addx 11
noop
noop
addx 1
noop
addx 1
noop
noop
addx -13
addx -19
addx 1
addx 3
addx 26
addx -30
addx 12
addx -1
addx 3
addx 1
noop
noop
noop
addx -9
addx 18
addx 1
addx 2
noop
noop
addx 9
noop
noop
noop
addx -1
addx 2
addx -37
addx 1
addx 3
noop
addx 15
addx -21
addx 22
addx -6
addx 1
noop
addx 2
addx 1
noop
addx -10
noop
noop
addx 20
addx 1
addx 2
addx 2
addx -6
addx -11
noop
noop
noop

154
2022/10/main.cpp Normal file
View File

@@ -0,0 +1,154 @@
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
enum Command {
NOOP = 1,
ADDX,
};
Command ParseCommand(const std::string &str) {
if(str.size() < 4)
return Command::NOOP;
std::string head = str.substr(0, 4);
if(head == "noop")
return Command::NOOP;
else if(head == "addx")
return Command::ADDX;
std::cerr << "Missing command type \"" << head << "\"." << std::endl;
exit(-1);
}
void StepCycles(long &cycle, const Command &command, const long &x);
void IncrementAndDraw(const long &x, long &cycle);
long Report(const long &cycle, const long &x);
void ApplyAction(const std::pair<Command, std::string> &command, long &x);
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::vector<std::pair<Command, std::string> > commands;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
auto cmd = ParseCommand(line);
if(cmd == Command::NOOP)
commands.push_back({cmd, ""});
else
commands.push_back({cmd, line.substr(5)});
}
long cycle = 1;
long x = 1;
for(const auto &command : commands)
{
// Step 1: Increase cycle count of command to see if we would have reported
StepCycles(cycle, command.first, x);
// Step 2: Report, if needed:
total += Report(cycle, x);
// Step 3: Perform command action:
ApplyAction(command, x);
}
while(cycle <= 220)
{
StepCycles(cycle, Command::NOOP, x);
total += Report(cycle, x);
}
std::cout << "Ended on cycle #" << cycle << ", value of x: " << x << std::endl;
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}
void StepCycles(long &cycle, const Command &command, const long &x)
{
switch(command)
{
case Command::NOOP:
IncrementAndDraw(x, cycle);
break;
case Command::ADDX:
for(auto i = 0; i < 2; ++i)
IncrementAndDraw(x, cycle);
break;
default:
std::cerr << "Missing ability to parse command type." << std::endl;
exit(-1);
break;
};
}
long Report(const long &cycle, const long &x)
{
static long last_reported_cycle = -20;
auto next_cycle = last_reported_cycle + 40;
if(cycle > next_cycle)
{
// std::cout << "Cycle #" << next_cycle << ": "
// << next_cycle << " * " << x << " = "
// << next_cycle * x << std::endl;
last_reported_cycle += 40;
return next_cycle * x;
}
return 0; // no change
}
void ApplyAction(const std::pair<Command, std::string> &command, long &x)
{
switch(command.first)
{
case Command::NOOP:
// std::cout << "NOOP" << std::endl;
// noop
break;
case Command::ADDX:
// std::cout << "ADDX " << command.second << ": x goes from " << x << " to ";
x += std::atoi(command.second.c_str());
// std::cout << x << std::endl;
break;
default:
std::cerr << "Missing ability to parse command type." << std::endl;
exit(-1);
break;
};
}
void IncrementAndDraw(const long &x, long &cycle)
{
static int drawing_index = 1; // 1 to 40
// NOTE(dev): using -0 and +2 instead of -1 and +1 to account for 0-based vs 1-based
if(drawing_index >= x - 0 && drawing_index <= x + 2) // within one or on target
std::cout << "#";
else
std::cout << ".";
++cycle;
if(++drawing_index > 40)
{
std::cout << std::endl;
drawing_index = 1;
}
}

2
2022/11/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

56
2022/11/data.txt Normal file
View File

@@ -0,0 +1,56 @@
Monkey 0:
Starting items: 93, 98
Operation: new = old * 17
Test: divisible by 19
If true: throw to monkey 5
If false: throw to monkey 3
Monkey 1:
Starting items: 95, 72, 98, 82, 86
Operation: new = old + 5
Test: divisible by 13
If true: throw to monkey 7
If false: throw to monkey 6
Monkey 2:
Starting items: 85, 62, 82, 86, 70, 65, 83, 76
Operation: new = old + 8
Test: divisible by 5
If true: throw to monkey 3
If false: throw to monkey 0
Monkey 3:
Starting items: 86, 70, 71, 56
Operation: new = old + 1
Test: divisible by 7
If true: throw to monkey 4
If false: throw to monkey 5
Monkey 4:
Starting items: 77, 71, 86, 52, 81, 67
Operation: new = old + 4
Test: divisible by 17
If true: throw to monkey 1
If false: throw to monkey 6
Monkey 5:
Starting items: 89, 87, 60, 78, 54, 77, 98
Operation: new = old * 7
Test: divisible by 2
If true: throw to monkey 1
If false: throw to monkey 4
Monkey 6:
Starting items: 69, 65, 63
Operation: new = old + 6
Test: divisible by 3
If true: throw to monkey 7
If false: throw to monkey 2
Monkey 7:
Starting items: 89
Operation: new = old * old
Test: divisible by 11
If true: throw to monkey 0
If false: throw to monkey 2

114
2022/11/main.cpp Normal file
View File

@@ -0,0 +1,114 @@
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
enum Operation {
ADD,
MULTIPLY,
};
class Monkey {
public:
Monkey(const std::vector<int> &starting_items, Operation operation_type, int operation_amount,
int division_by, int true_monkey, int false_monkey)
: items(starting_items), operation_type(operation_type), operation_amount(operation_amount),
division_by(division_by), true_monkey(true_monkey), false_monkey(false_monkey)
{
}
friend std::ostream& operator<<(std::ostream &out, const Monkey &monkey);
private:
std::vector<int> items;
Operation operation_type;
int operation_amount;
int division_by;
int true_monkey;
int false_monkey;
};
std::vector<int> ParseItems(const std::string &line);
std::pair<Operation, int> ParseOperation(const std::string &line);
int ParseDivisibleBy(const std::string &line);
int ParseTrue(const std::string &line);
int ParseFalse(const std::string &line);
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::vector<Monkey> monkeys;
int line_num = 0;
std::vector<std::string> buf;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
{
if(buf.size() == 5)
{
auto op = ParseOperation(buf[2]);
monkeys.push_back(Monkey(//std::atoi(buf[0].substr(7, buf[0].size() - 7).c_str()),
ParseItems(buf[1]),
op.first,
op.second,
ParseDivisibleBy(buf[3]),
ParseTrue(buf[4]),
ParseFalse(buf[5])));
buf.clear();
}
continue;
}
else if(line.starts_with(" "))
buf.push_back(line);
}
for(const auto &monkey : monkeys)
std::cout << monkey << std::endl;
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}
std::ostream& operator<<(std::ostream &out, const Monkey &monkey)
{
out << " Starting items: ";
for(auto item : monkey.items)
out << item << ", ";
return out;
}
std::vector<int> ParseItems(const std::string &line)
{
return {};
}
std::pair<Operation, int> ParseOperation(const std::string &line)
{
return { Operation::ADD, 0 };
}
int ParseDivisibleBy(const std::string &line)
{
return 1;
}
int ParseTrue(const std::string &line)
{
return 1;
}
int ParseFalse(const std::string &line)
{
return 1;
}

2500
2022/2/data.txt Normal file

File diff suppressed because it is too large Load Diff

127
2022/2/main.cpp Normal file
View File

@@ -0,0 +1,127 @@
#include <fstream>
#include <iostream>
#include <string>
enum RPS {
Rock = 1,
Paper,
Scissors,
};
enum Result {
Lose = 1,
Draw,
Win,
};
RPS ToRPS(char c)
{
if(c == 'A' || c == 'X')
return RPS::Rock;
else if(c == 'B' || c == 'Y')
return RPS::Paper;
else if(c == 'C' || c == 'Z')
return RPS::Scissors;
std::cerr << "BAD DATA '" << c << "'." << std::endl;
exit(-1);
}
int RPSScore(RPS rps)
{
switch(rps)
{
case RPS::Rock:
return 1;
case RPS::Paper:
return 2;
case RPS::Scissors:
return 3;
}
}
bool Won(RPS us, RPS them)
{
if(us == RPS::Rock && them == RPS::Scissors)
return true;
else if(us == RPS::Paper && them == RPS::Rock)
return true;
else if(us == RPS::Scissors && them == RPS::Paper)
return true;
return false;
}
RPS Which(RPS them, Result desired)
{
if(desired == Result::Draw)
return them; // same
switch(them)
{
case RPS::Rock:
if(desired == Result::Lose)
return RPS::Scissors;
return RPS::Paper;
case RPS::Paper:
if(desired == Result::Lose)
return RPS::Rock;
return RPS::Scissors;
case RPS::Scissors:
if(desired == Result::Lose)
return RPS::Paper;
return RPS::Rock;
}
}
int Points(RPS us, RPS them)
{
int rtn = 0;
// score our play:
rtn += RPSScore(us);
// tie:
if(us == them)
return rtn + 3;
// win:
if(Won(us, them))
return rtn + 6;
// loss:
return rtn;
}
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long new_total = 0;
for(std::string line; std::getline(ifs, line); )
{
char them = line[0];
char us = line[2];
Result r = Result::Lose;
if(us == 'Y')
r = Result::Draw;
else if(us == 'Z')
r = Result::Win;
RPS todo = Which(ToRPS(them), r);
total += Points(ToRPS(us), ToRPS(them));
new_total += Points(todo, ToRPS(them));
}
std::cout << " Total: " << total << std::endl;
std::cout << "New Total: " << new_total << std::endl;
return 0;
}

300
2022/3/data.txt Normal file
View File

@@ -0,0 +1,300 @@
vGFhvGvvSdfwqhqvmCPnlFPnCNPcCFcWcr
ZbWZDMgsTHsrNNLJcJnsJl
HbBWQgZVZZBzbgZphwjqpmmVfdGmjG
vvCJLGnthChvtrvCCnRbTRqRPRBtbTRfPRRl
djZSgHNNwjqcdWlbcbfc
pFgMSfpMfzMDZFSgSjGJQQnCvMCVLnnJQLGC
gVhQWQpcWZVwwHVvFvnnnnDFdL
lzbPlztjltztzSjfGcPdTHLTHFCnnHCLndFGGd
jsNbzbczclttSlfbqlljRQMJRMMpJwRZhspZgJRM
hLJvfGcNDttSGvJtvSSJcqbqFBBWbjQqDrqbjDDjjb
lTswlzZdssgFpdPwZpMQnCjngCCjWBQBWWQqng
PRZMpzPZTdVZTfJvFvLFRctJcf
JHbQtHVHHLLbTJmmZddgdgwhllMNhhhTgg
spqpNGDjDPMhCFChMj
DBSDDGnpSDsDWqWczcvSqWvsBtJJLLZrRVZLJRbBZNVrBHrV
GwGhfhPhpHccvwSwrTsmsCjDmqTfbDqjss
tQntQcNRJMFnnVQFFctJqCsRmsTjjbDqDlTqTbWT
NZdVBZZNFzMFNNNvG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V
FhFzRTDRPzsRQGQGTFlllrJHjdsJlHMqjjHr
LqDcTbmJcqSJSTmnrTcmJrfffplfjZsGZfGGZfQLdplj
hWddgBvzWFZfPsQlGh
RBWBRCdHtgHttVVzHBVNNNDwSTDcSSSbScDDwbwbnmRS
FFPzwlZVVrzFFlFLVlllZdHCHPQMnJQQbhhChdhCbb
BRRqGBgRfqvgvBDDDTRgghNCMMTQNNbVJMNJJdbbdT
DfpgjGfsRWrFVzwLcs
PMTSdSmFjhFpNTqvppvRBrRBrDqB
HnZZznJbzGZGlZtZWHlJGcGcwMvQBsrwRDQvcDgrgDgrqRvq
HGlGfnJZfMMCfNhm
nRssqlqVRppVwdMMQwFgtRFz
smTvLLTvvNLtwMMQNg
CmPGBvZGWvBSGGDmTZjZlhpJcpHDJsbDnlrrprpl
djcQGNQqdGdGqMCgndwgCLDMgW
nvBvHpBppnvPPnJTBWLJVMwVfWJfCbfWgW
hsHHpBsvRTHpsPszTBTTsRTslGqGqlcqlScnqmhZmmZSZSjl
DddBHCmfWCBTDBHTHfMpzhzpJJMJsFrGrz
tPVPmbnttjPnZvSvSbnmZPZPNpNGMpJNzzNrGJpvhsshMpFs
mwnZcbmmStbVtVjbZVlcLTBlcLCRHRDWCWWW

81
2022/3/main.cpp Normal file
View File

@@ -0,0 +1,81 @@
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
int score(char c)
{
if(c >= 'a' && c <= 'z')
return (c - 'a') + 1;
return (c - 'A') + 1 + 26;
}
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
const size_t half = line.size() / 2;
std::string right = line.substr(half);
for(int i = 0; i < half; ++i)
{
if(right.contains(line[i]))
{
total += score(line[i]);
break;
}
}
// Part 2:
static std::vector<std::string> lines;
lines.push_back(line);
if(lines.size() == 3)
{
// get all letters it could be from first line
std::set<char> options;
for(const char c : lines[0])
options.insert(c);
// remove if not a duplicate
std::set<char> to_remove;
for(auto i = 1; i < 3; ++i) // remaining two lines
{
for(const char c : options)
if(!lines[i].contains(c))
to_remove.insert(c);
for(const char c : to_remove)
options.erase(c);
}
if(options.size() != 1)
{
std::cerr << "Error: More than one remaining option: ";
for(const char c : options)
std::cout << c << ",";
exit(-1);
}
total_pt2 += score(*(options.begin()));
lines.clear(); // reset
}
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

2
2022/4/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

1000
2022/4/data.txt Normal file

File diff suppressed because it is too large Load Diff

79
2022/4/main.cpp Normal file
View File

@@ -0,0 +1,79 @@
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
std::vector<std::string> SplitStr(std::string str, const std::string &delim)
{
std::vector<std::string> rtn;
for(auto split = str.find(delim); split != std::string::npos; split = str.find(delim))
{
rtn.push_back(str.substr(0, split));
str = str.substr(split + delim.size()); // chop off beginning
}
if(str.size())
rtn.push_back(str);
return rtn;
}
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
auto sections = SplitStr(line, ",");
if(sections.size() != 2)
{
std::cerr << "Incorrect amount of data for line: " << line << std::endl;
exit(-1);
}
auto elf_a = SplitStr(sections[0], "-");
auto elf_b = SplitStr(sections[1], "-");
if(elf_a.size() != 2 || elf_b.size() != 2)
{
std::cerr << "Incorrect amount of data for line: " << line << std::endl;
exit(-2);
}
int elf_a_min = std::atoi(elf_a[0].c_str());
int elf_a_max = std::atoi(elf_a[1].c_str());
int elf_b_min = std::atoi(elf_b[0].c_str());
int elf_b_max = std::atoi(elf_b[1].c_str());
if((elf_a_min <= elf_b_min && elf_a_max >= elf_b_max) ||
(elf_b_min <= elf_a_min && elf_b_max >= elf_a_max))
++total;
// sort
if(elf_a_min > elf_b_min)
{
std::swap(elf_a_min, elf_b_min);
std::swap(elf_a_max, elf_b_max);
}
if(elf_b_min <= elf_a_max)
++total_pt2;
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

1
2022/5/Makefile Symbolic link
View File

@@ -0,0 +1 @@
../4/Makefile

512
2022/5/data.txt Normal file
View File

@@ -0,0 +1,512 @@
[B] [L] [J]
[B] [Q] [R] [D] [T]
[G] [H] [H] [M] [N] [F]
[J] [N] [D] [F] [J] [H] [B]
[Q] [F] [W] [S] [V] [N] [F] [N]
[W] [N] [H] [M] [L] [B] [R] [T] [Q]
[L] [T] [C] [R] [R] [J] [W] [Z] [L]
[S] [J] [S] [T] [T] [M] [D] [B] [H]
1 2 3 4 5 6 7 8 9
move 5 from 4 to 5
move 2 from 5 to 8
move 2 from 9 to 1
move 2 from 9 to 1
move 1 from 5 to 3
move 10 from 5 to 8
move 1 from 4 to 7
move 1 from 1 to 2
move 5 from 3 to 7
move 1 from 2 to 8
move 21 from 8 to 5
move 13 from 5 to 7
move 2 from 9 to 4
move 1 from 7 to 4
move 5 from 1 to 4
move 1 from 5 to 7
move 2 from 2 to 7
move 1 from 3 to 2
move 1 from 1 to 6
move 7 from 5 to 9
move 16 from 7 to 4
move 7 from 9 to 3
move 1 from 7 to 5
move 1 from 3 to 8
move 3 from 2 to 7
move 1 from 8 to 9
move 3 from 3 to 6
move 21 from 4 to 9
move 1 from 5 to 7
move 4 from 4 to 9
move 8 from 6 to 3
move 6 from 7 to 1
move 12 from 9 to 8
move 6 from 7 to 2
move 3 from 6 to 5
move 1 from 6 to 9
move 4 from 8 to 6
move 3 from 8 to 5
move 4 from 1 to 8
move 4 from 6 to 1
move 2 from 1 to 3
move 1 from 5 to 8
move 2 from 2 to 8
move 5 from 8 to 3
move 4 from 2 to 7
move 5 from 8 to 1
move 2 from 1 to 7
move 1 from 8 to 2
move 2 from 1 to 7
move 11 from 9 to 2
move 1 from 8 to 5
move 2 from 9 to 4
move 3 from 9 to 5
move 2 from 5 to 1
move 6 from 5 to 8
move 2 from 4 to 2
move 1 from 5 to 6
move 7 from 1 to 8
move 2 from 2 to 7
move 13 from 8 to 1
move 16 from 3 to 1
move 3 from 2 to 1
move 12 from 7 to 6
move 15 from 1 to 8
move 2 from 3 to 8
move 16 from 1 to 2
move 24 from 2 to 8
move 1 from 1 to 5
move 1 from 5 to 8
move 3 from 6 to 7
move 26 from 8 to 3
move 20 from 3 to 9
move 1 from 2 to 9
move 16 from 9 to 3
move 14 from 3 to 1
move 13 from 1 to 6
move 3 from 3 to 4
move 3 from 9 to 4
move 1 from 7 to 8
move 5 from 8 to 2
move 8 from 8 to 5
move 18 from 6 to 1
move 4 from 8 to 5
move 6 from 4 to 1
move 2 from 2 to 5
move 5 from 3 to 8
move 5 from 8 to 7
move 2 from 5 to 8
move 5 from 5 to 4
move 3 from 2 to 8
move 22 from 1 to 2
move 1 from 1 to 2
move 5 from 8 to 2
move 2 from 5 to 2
move 1 from 1 to 6
move 5 from 5 to 2
move 1 from 9 to 8
move 5 from 4 to 1
move 6 from 6 to 9
move 3 from 1 to 9
move 1 from 1 to 7
move 8 from 9 to 6
move 6 from 7 to 1
move 5 from 6 to 5
move 27 from 2 to 1
move 4 from 5 to 7
move 9 from 1 to 5
move 1 from 9 to 1
move 3 from 6 to 2
move 9 from 2 to 1
move 2 from 7 to 2
move 1 from 8 to 7
move 10 from 5 to 9
move 1 from 9 to 7
move 25 from 1 to 8
move 6 from 7 to 4
move 11 from 1 to 7
move 3 from 8 to 1
move 3 from 2 to 6
move 3 from 8 to 9
move 11 from 8 to 6
move 1 from 2 to 6
move 12 from 6 to 4
move 13 from 4 to 5
move 1 from 6 to 1
move 3 from 7 to 5
move 5 from 8 to 7
move 1 from 7 to 1
move 5 from 1 to 6
move 3 from 6 to 4
move 3 from 8 to 6
move 2 from 5 to 2
move 12 from 5 to 9
move 5 from 6 to 2
move 2 from 5 to 9
move 6 from 4 to 9
move 11 from 7 to 3
move 1 from 2 to 5
move 1 from 7 to 8
move 1 from 5 to 7
move 1 from 7 to 1
move 1 from 8 to 1
move 2 from 4 to 7
move 2 from 6 to 8
move 5 from 3 to 6
move 2 from 7 to 2
move 2 from 2 to 9
move 1 from 2 to 9
move 1 from 1 to 6
move 35 from 9 to 7
move 2 from 8 to 7
move 3 from 3 to 8
move 5 from 2 to 4
move 3 from 3 to 7
move 2 from 4 to 7
move 4 from 6 to 5
move 4 from 5 to 9
move 3 from 4 to 5
move 1 from 8 to 3
move 4 from 9 to 8
move 1 from 9 to 6
move 38 from 7 to 2
move 1 from 3 to 5
move 1 from 1 to 7
move 4 from 7 to 3
move 3 from 6 to 1
move 22 from 2 to 7
move 1 from 5 to 8
move 7 from 8 to 4
move 8 from 2 to 8
move 3 from 5 to 1
move 4 from 3 to 9
move 1 from 8 to 3
move 1 from 3 to 7
move 2 from 2 to 3
move 5 from 8 to 9
move 3 from 9 to 1
move 2 from 1 to 7
move 6 from 2 to 3
move 6 from 3 to 1
move 2 from 3 to 6
move 1 from 6 to 1
move 14 from 7 to 2
move 4 from 1 to 6
move 8 from 1 to 3
move 4 from 3 to 6
move 3 from 9 to 5
move 1 from 8 to 6
move 1 from 8 to 4
move 9 from 7 to 1
move 8 from 2 to 4
move 4 from 2 to 9
move 2 from 2 to 1
move 3 from 5 to 8
move 1 from 8 to 6
move 1 from 7 to 8
move 1 from 6 to 5
move 3 from 9 to 5
move 2 from 9 to 5
move 4 from 3 to 9
move 3 from 6 to 3
move 3 from 6 to 9
move 9 from 4 to 1
move 1 from 9 to 8
move 3 from 3 to 6
move 2 from 7 to 4
move 4 from 8 to 5
move 7 from 5 to 6
move 19 from 1 to 9
move 5 from 9 to 3
move 2 from 1 to 6
move 1 from 4 to 6
move 4 from 3 to 2
move 21 from 9 to 7
move 1 from 1 to 2
move 1 from 9 to 1
move 1 from 1 to 8
move 16 from 7 to 6
move 24 from 6 to 5
move 7 from 4 to 5
move 1 from 8 to 3
move 2 from 2 to 8
move 31 from 5 to 8
move 1 from 4 to 6
move 2 from 6 to 9
move 1 from 7 to 4
move 3 from 7 to 9
move 1 from 4 to 8
move 2 from 3 to 5
move 1 from 2 to 3
move 1 from 3 to 7
move 1 from 7 to 9
move 24 from 8 to 6
move 1 from 8 to 1
move 30 from 6 to 1
move 2 from 5 to 2
move 1 from 6 to 9
move 6 from 9 to 7
move 1 from 6 to 4
move 1 from 4 to 6
move 23 from 1 to 3
move 21 from 3 to 4
move 4 from 2 to 6
move 3 from 6 to 1
move 1 from 5 to 1
move 4 from 1 to 9
move 3 from 9 to 6
move 8 from 1 to 6
move 4 from 8 to 5
move 2 from 7 to 5
move 7 from 4 to 3
move 3 from 4 to 9
move 9 from 3 to 9
move 1 from 7 to 6
move 6 from 5 to 8
move 14 from 6 to 2
move 4 from 8 to 4
move 7 from 4 to 5
move 1 from 7 to 9
move 6 from 4 to 3
move 13 from 2 to 6
move 5 from 3 to 7
move 1 from 3 to 8
move 1 from 8 to 2
move 4 from 8 to 3
move 6 from 6 to 4
move 2 from 2 to 8
move 5 from 4 to 7
move 3 from 7 to 5
move 1 from 7 to 9
move 2 from 3 to 9
move 3 from 7 to 3
move 1 from 7 to 9
move 1 from 7 to 9
move 3 from 4 to 1
move 6 from 6 to 1
move 2 from 7 to 5
move 1 from 3 to 5
move 11 from 9 to 4
move 9 from 4 to 5
move 3 from 3 to 4
move 1 from 3 to 9
move 2 from 8 to 1
move 9 from 1 to 8
move 22 from 5 to 8
move 2 from 1 to 3
move 3 from 4 to 6
move 14 from 8 to 9
move 1 from 3 to 9
move 19 from 9 to 3
move 3 from 9 to 4
move 2 from 7 to 2
move 1 from 4 to 6
move 1 from 3 to 8
move 8 from 3 to 1
move 2 from 9 to 6
move 1 from 2 to 5
move 3 from 4 to 9
move 1 from 2 to 3
move 20 from 8 to 3
move 4 from 9 to 5
move 1 from 4 to 2
move 26 from 3 to 5
move 1 from 8 to 3
move 8 from 1 to 4
move 1 from 3 to 7
move 1 from 2 to 1
move 1 from 1 to 6
move 1 from 6 to 7
move 4 from 5 to 3
move 3 from 4 to 2
move 5 from 5 to 3
move 2 from 2 to 6
move 3 from 3 to 5
move 2 from 4 to 8
move 5 from 3 to 9
move 5 from 9 to 8
move 19 from 5 to 9
move 1 from 5 to 2
move 2 from 7 to 1
move 1 from 1 to 7
move 1 from 7 to 4
move 13 from 9 to 3
move 8 from 6 to 2
move 10 from 3 to 5
move 14 from 5 to 4
move 7 from 8 to 4
move 1 from 6 to 2
move 6 from 3 to 8
move 4 from 9 to 7
move 2 from 9 to 8
move 1 from 7 to 1
move 3 from 2 to 7
move 1 from 5 to 3
move 7 from 8 to 6
move 5 from 6 to 2
move 8 from 4 to 5
move 3 from 5 to 8
move 3 from 8 to 6
move 5 from 7 to 9
move 5 from 3 to 6
move 1 from 9 to 4
move 17 from 4 to 7
move 1 from 8 to 1
move 12 from 7 to 8
move 3 from 1 to 4
move 2 from 4 to 6
move 8 from 6 to 1
move 4 from 6 to 3
move 1 from 7 to 8
move 5 from 5 to 8
move 4 from 7 to 1
move 3 from 2 to 6
move 2 from 5 to 1
move 6 from 1 to 6
move 4 from 3 to 5
move 4 from 5 to 3
move 1 from 4 to 8
move 3 from 3 to 2
move 17 from 8 to 4
move 6 from 6 to 3
move 14 from 4 to 9
move 1 from 3 to 8
move 1 from 7 to 4
move 3 from 8 to 3
move 5 from 2 to 5
move 6 from 1 to 7
move 2 from 6 to 4
move 4 from 5 to 7
move 1 from 1 to 5
move 1 from 6 to 3
move 10 from 7 to 4
move 1 from 5 to 4
move 1 from 2 to 3
move 15 from 4 to 5
move 3 from 3 to 1
move 6 from 2 to 6
move 1 from 2 to 3
move 2 from 4 to 7
move 2 from 7 to 8
move 1 from 4 to 2
move 2 from 1 to 7
move 1 from 7 to 2
move 12 from 9 to 1
move 4 from 9 to 5
move 4 from 6 to 2
move 1 from 7 to 3
move 6 from 2 to 4
move 1 from 8 to 5
move 2 from 4 to 2
move 11 from 1 to 7
move 3 from 1 to 4
move 17 from 5 to 6
move 15 from 6 to 4
move 1 from 8 to 9
move 10 from 4 to 1
move 1 from 3 to 9
move 2 from 6 to 5
move 1 from 2 to 6
move 4 from 5 to 6
move 4 from 1 to 2
move 6 from 6 to 7
move 2 from 2 to 6
move 9 from 4 to 9
move 6 from 1 to 2
move 3 from 4 to 1
move 10 from 9 to 8
move 4 from 2 to 1
move 1 from 1 to 2
move 5 from 8 to 6
move 1 from 2 to 7
move 1 from 9 to 4
move 2 from 6 to 9
move 13 from 7 to 2
move 5 from 7 to 5
move 2 from 5 to 2
move 1 from 4 to 5
move 4 from 8 to 4
move 17 from 2 to 6
move 3 from 4 to 6
move 2 from 9 to 1
move 7 from 6 to 8
move 1 from 5 to 2
move 1 from 4 to 1
move 2 from 9 to 4
move 1 from 3 to 9
move 4 from 3 to 7
move 2 from 8 to 5
move 3 from 7 to 5
move 10 from 5 to 8
move 2 from 2 to 4
move 6 from 1 to 2
move 4 from 6 to 3
move 8 from 2 to 6
move 1 from 7 to 4
move 5 from 4 to 5
move 7 from 6 to 7
move 5 from 3 to 5
move 5 from 5 to 2
move 4 from 8 to 1
move 6 from 1 to 6
move 3 from 3 to 2
move 22 from 6 to 2
move 1 from 9 to 7
move 8 from 8 to 6
move 1 from 7 to 6
move 2 from 5 to 7
move 4 from 8 to 5
move 7 from 6 to 7
move 2 from 6 to 4
move 14 from 2 to 1
move 7 from 1 to 3
move 12 from 7 to 3
move 1 from 4 to 3
move 2 from 5 to 8
move 2 from 8 to 1
move 1 from 4 to 3
move 6 from 2 to 9
move 6 from 9 to 2
move 2 from 2 to 7
move 6 from 7 to 5
move 13 from 3 to 5
move 5 from 2 to 6
move 5 from 6 to 1
move 2 from 3 to 6
move 1 from 6 to 5
move 1 from 6 to 1
move 3 from 1 to 9
move 6 from 2 to 7
move 1 from 2 to 3
move 24 from 5 to 2
move 7 from 3 to 7
move 13 from 7 to 9
move 4 from 1 to 9
move 4 from 1 to 6
move 1 from 5 to 6
move 16 from 9 to 5
move 1 from 6 to 4
move 1 from 5 to 2
move 5 from 1 to 3
move 11 from 2 to 1
move 4 from 9 to 6
move 1 from 4 to 7
move 2 from 3 to 4
move 6 from 6 to 9
move 1 from 1 to 3
move 2 from 9 to 4
move 1 from 7 to 9
move 4 from 2 to 9
move 8 from 9 to 2
move 3 from 3 to 2
move 1 from 9 to 4
move 5 from 1 to 7
move 1 from 4 to 8
move 2 from 1 to 9
move 1 from 8 to 7
move 6 from 5 to 3
move 1 from 5 to 1
move 5 from 2 to 3
move 4 from 1 to 5
move 4 from 7 to 1
move 8 from 5 to 8

119
2022/5/main.cpp Normal file
View File

@@ -0,0 +1,119 @@
#include <algorithm>
#include <fstream>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
void DebugOutput(std::vector<std::vector<char>> &stacks)
{
// DEBUG:
for(const auto &st : stacks)
{
std::cout << "Stack: " << std::endl;
for(const auto &ch : st)
std::cout << "[" << ch << "]" << std::endl;
std::cout << std::endl;
}
}
std::vector<std::string> SplitStr(std::string str, const std::string &delim)
{
std::vector<std::string> rtn;
for(auto split = str.find(delim); split != std::string::npos; split = str.find(delim))
{
rtn.push_back(str.substr(0, split));
str = str.substr(split + delim.size()); // chop off beginning
}
if(str.size())
rtn.push_back(str);
return rtn;
}
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
std::vector<std::vector<char>> stacks;
std::vector<std::vector<char>> stacks2;
// Step 1: Parse Starting Position
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
break;
stacks.resize((line.size() + 1) / 4);
for(auto idx = 0; (idx * 4) < line.size(); ++idx)
if(line[1 + idx * 4] != ' ')
stacks[idx].push_back(line[1 + idx * 4]);
}
// Step 2: Clean up data:
for(auto &st : stacks)
{
// clear out last line of each, seeing as how they're just index numbers:
st.pop_back();
// reverse list since we parsed top to bottom and inserted backwards...
std::reverse(st.begin(), st.end());
}
// DebugOutput(stacks);
stacks2 = stacks;
// Step 3: Parse Actions
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
auto actions = SplitStr(line, " ");
if(actions.size() != 6)
{
std::cerr << "Data corrupt: " << line << std::endl;
exit(-1);
}
long amt = std::atoi(actions[1].c_str());
long from = std::atoi(actions[3].c_str()) - 1;
long to = std::atoi(actions[5].c_str()) - 1;
// Part 1:
for(auto i = 0; i < amt; ++i)
{
stacks[to].push_back(stacks[from].back());
stacks[from].pop_back();
}
// Part 2:
std::stack<char> temp;
for(auto i = 0; i < amt; ++i)
{
temp.push(stacks2[from].back());
stacks2[from].pop_back();
}
for(auto i = 0; i < amt; ++i)
{
stacks2[to].push_back(temp.top());
temp.pop();
}
}
// DebugOutput(stacks);
for(const auto &st : stacks)
std::cout << st.back();
std::cout << std::endl;
for(const auto &st : stacks2)
std::cout << st.back();
std::cout << std::endl;
return 0;
}

6
2022/6/Makefile Normal file
View File

@@ -0,0 +1,6 @@
all: a.out b.out
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp
b.out: main2.cpp
clang++ -std=c++2b -g -O0 main2.cpp -o b.out

BIN
2022/6/b.out Executable file

Binary file not shown.

1
2022/6/data.txt Normal file
View File

@@ -0,0 +1 @@
hqhnqhqshhslswsffchfcfbblvlblqlggfwwqfwwqdddbbbhzhjjrqjqbjqjwqjwqwhwrrmcrrjqjjlllcvcrrnpptzpzmmswmmzrzjrrfcrfccpbpzzvrrdndllttwftwwgzzwhwggdvdnnlrnncscbcfcctchcdchdccztzgzjjtdtcdtcchrrgpgzgsgpsggvtvppdccfhcfclfcfdfnddlbbptbtdbtdtjdjgdjjzljlssgbgcgqcqzccfnftfjjsgstggsngsscvssjzjnjtntvnvssrqqhtqtvqtvvjbvvbnvvqvmvrmmdsdvdwwnbnvbnvvcgvcczcfzftfsfrfsfttldtdrrgrgmgbbdvvbqbhqbqlqsqbsbpbgbvgbgwwrswrwrwttvnnzdnzzwggrmrfmmvllzwlwzzlvlbvllgsllpnlnvncvcvqqrwwcmcczhchzczbccdwcwvwzwwvddlwlhljlqjqnncntnctczzmwmlmccpggljlssqswsmmpvmvwvrrcpcrprmprrtdrtdrrsjsmshmmdpdlppbnbvvmmflmmjvjhvhjvjsjbjwjvvblvbvlbbllwlslvljvlvdvdgvgcchnhpnhnvhhtfhhvssczztlzzgvvqqghqgqssdscsnsrsmrmmwgwmgmlmdmggbgzbgzgdzdzccghgfgddtntftddpdrdrmrjmmmzttqmttnwngggtgtqtqnqhnqqpnnntrntrnnshhjtjzzfqqblqqlblslflmlttcwtwzzrlrnrcrrrgtrrftfhthzhggwggvgvvfvddcnddfjddzqzrrvtrvrfrrgpgrgngsgddlmddzgzppdzzjzhjhjhqqbpbvvlrvrsvrvnrrsgsttndnbngnppmlppvgvfggvcvrvnnsnfnnfqfwwppnddrrfqqgbqqfmmlnlnngwgcgjgnjgjsgjgqjjnccdttpqttswwcgcmgmccrppmqmbbfwwvdwdfwfjwfjjblldsdrdvvgcvcwwllfpllcslsvssnvsnvvhnvnvwwcgwccslsbbnlbnbrrrtprptpdpdvdttgsgwswppcdchhqbqcbqbzbgbbstshthsttqgtqtpqqzhhwhghwwmbbdlbbtlltsllbvbnvvmqvqtvqvttlwtltmmrttwgtwwfdddwcchtchhbthbbclczzqbzzpvvwzwswggjddntnrnnwmnnbdbmbccqgqvvsnvvqbvbzvvzmvzzrfrlfrfhhdvddnmnnmhmqhhrhlrldljlbljjgqqvdvhhgmgvgddmmznndmmhssznsswvwdvdzdhhscssntnftfmmrggbmbmgmlltctbtbntnqqscqcscrcrhrlhhdchhzccvvbfvvpfffbwbsbjjmgmwgmgppjnpjphhlmhhpwwhwzhhhzbbzzcbchhpnnptpvphhsdsccffqbqllchlhlwlcljlppnccqsstzstswtwwljwjmmpttvqqspsjjclljqqlhqqtnnbrrsbrbjjllrmrjmjzmmclmclmmcvvbddhnnmhmbbwqqqhrqqtqmqbqdbdtdvvcscshccmffhqffdgdcgddljdjbdbjbdbrrtjjtnntpntpnpmnpmpgghffrnfrnnmdnmnhmmjcjffftrrttfwfvwvcwwrmwmpwmmnvntthmmgmbbcdclcppjhpjhjwwlppgsszqqwggmttfrfqflfsfmmmhchshmmjtjjgdjjnnsvsmsnwcgdfqljmnphlfdrhpggfqnhnszgpndhdqcgfhtdcgbsbtmhvnnrmqzqqcjdqndzbnrhwjvbvcldmnwltgpqbmstntnggtbqjzzqrfdsfttdfrcnsrpwrjrjqbgtjfmlwsrzdbdqvbtczgsjqhtgmctjfmdglfrsvqtgwpbqghzgzdfwzhbdhlmhdvhwjrdhhtjptvwpmjnmfcjdmdczmczvdqwvbgtvlwvwnvdlbqfshmlmvzzcmjbtpwpwgsqhfsgljzhbppcztfjdntzcvllqnzrqjwfjrlgvhmbpvbtqjrdzcsmcjzcdsmvcmhrbhgnscnfrfmscqsqpqplbrzhsrlsvvpmfdtdmtlrtvspmlljmfpshfmstjgnrrwmqlbnwbndcfdstrtqtnzpfqlcgrzmsnmhllljdgtmvftjttbwhqzcqwbwdbshgcqrptfjwbbfsjnvzztlbdchqrlbbrcnsswmhwphfwrbnvrncbrthprmltlwwlfpbqhdfqzwwcwjgqzdnvmhwpzpbtpwwvzcpfcsfqpwjljzzfwzmlfvhsccppzlzjlrvlpdtjpcptnvqjwtdbzrqwnfwmmjndflqqggczrfjlpdfjffctprnmhfdqvnzbfvhszzdmngnlmwzfdrbvlvjnmbllgrczssqcrhbmnpmqlrzgmqmhgsvcdlqnmlhlzvqzhnccbctslzlbcpdvqltqncpcrzwdchrqmwfwlcbcvfnnpjntfrznqdjsdtzqjjttddwvnfqmznhflblzvvtbwdzrrlqlmndzzzwnpbhhlvlbswfjtbnhlccscbnfgjtwbfdlwvzszwnwzhlbcdpvgqjcrpzsvvnfwqcqvrmhzhggvmzwggdpbfrdscjwhsdsbbjcnzldhzcvqtjrhsbfjlrlpvtcqhnnsvslfrdjvjhfhdcfzqchpvvhzbpqglqlrdttrdtndzhnzhtqndghtgmpsnhptprqzhbbdcrgmbvrvqmbptqgnmsccwmhrlpddvmhjntllwrzqwnsjchnblcgndjtmpswwgcstdftqcbhzgttrhnpvrhspjznhhvrlpdqbzzrvzjphcswhljdldvsrdhzltwgrcsvqwnhtqqjjrjgrplzmsnjhzrfbtqgdfgnbpvjrfzrrpdphgzrfbswdhzgbzswqtwwdtrvvswmjvwhqddfzjhgdqsfnwbmlcfwtmpldrdpwjwggbpmncvbghzjmpsqpvnmbhjfzzpsjdgmrtnndhzrphjzdbgrrnthtrfnspdngbdmwbnfjlsndqswfsvfqftqlgqjpfsfpmdbsjfrptvbpvflqgvlmmbchhghhrwmvdlrhlsdtvjjchwglcrwfsfnnbhjbtccbjsfwrbzrvgsbfnvzghhrqblqchjvdtrrbrwwwmfnczzmmrqdggsfrqbldbbfbbcthtsvpcnlbjjztwvhctbrjltqdwbzmrrfslbmjpnqwllbvjzgfsfqqtwbgwgclgdflshfhwggwdqlgbmdmdqglrtfwbddtsltmsvswhgjtqwtnrncpdzhnpfqcjnjzmtbjfzpjwgfbfggmsmfdhfbjctnhchpgfspthdbfpmvrmdbbspvwzqqwnmfwdnnblbcjszbccgflngnjjwsqshfbhjwgzrmvsgnrdbgwfhdvpmznpnvznfcqdclztcptjrrpbmpztwwbvlvtmngfhmfbfmrjbjzlrcvgllrlgthltstnwmffntqrwsrndlzqhztwpcwbdjjztgdzmgtthcvtvnjzzhvstfqhgddddgdsrbcqzqspjrncphhtbnslzphrtfqphffjrrlgwbrwqfzzqvzhnffcwvrncttgplshccglvchvlcbnlthhmzvcrfjvjqfsjjzzgqlpslfwngqnbgcwffpcqhlmlhvwssrpjbrcbftpzbbpptzrdqwpzpdjhtwbvwcqbfnwtflfgzgttglpcwdnzsmjffgfftdnpzlpszmzrrhvlzdfpgbzqlvvfslnndcmjvvpwzwcdzpcttfwbsdswmfqbbhbfbjvbvtspbbhmphzjsjcmmzpvvzhtvzlgwlqqvbnrgtszvghjfmchrwwhpmbsvfmgvqdtmvdtjppchbsgqrtgtnzczqmpgjdbmmflfpjbcdmhldwpgdtdvsbzhztjzfhcsbndfjntbldjnqwdffqspfnlplbtcdjtwdjhldtsdfrnmpfhzghnpcqlhhgblmqjvwhndqfbccvzzlbzbdprvcpwjjhrqnjptwssbjhgvpgtfzqwrzjvbdgwtnmptvdjrffcmbzmzcmrfbjv

56
2022/6/main.cpp Normal file
View File

@@ -0,0 +1,56 @@
#include <deque>
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
bool Unique(const std::deque<char> &buf)
{
std::set<char> s;
for(const char &ch : buf)
s.insert(ch);
return (s.size() == 4);
}
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
std::deque<char> buf;
int idx = 0;
for(const char &ch : line)
{
++idx;
buf.push_back(ch);
if(buf.size() >= 4)
{
while(buf.size() > 4)
buf.pop_front();
if(Unique(buf))
{
std::cout << "At index " << idx << ": ";
for(const char &ch : buf)
std::cout << ch;
std::cout << std::endl;
break;
}
}
}
}
return 0;
}

52
2022/6/main2.cpp Normal file
View File

@@ -0,0 +1,52 @@
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
std::vector<char> buf;
int idx = 0;
for(const char &ch : line)
{
++idx;
// clear out from beginning up until this character is found:
auto i = std::find(buf.begin(), buf.end(), ch);
if(i != buf.end())
buf.erase(buf.begin(), i+1);
buf.push_back(ch);
if(buf.size() == 4)
{
std::cout << "Start-of-Packet at index " << idx << ": ";
for(const char &ch : buf)
std::cout << ch;
std::cout << std::endl;
}
else if(buf.size() == 14)
{
std::cout << "Start-of-Message at index " << idx << ": ";
for(const char &ch : buf)
std::cout << ch;
std::cout << std::endl;
}
}
}
return 0;
}

21
2022/7/File.cpp Normal file
View File

@@ -0,0 +1,21 @@
#include "File.h"
File::File(const std::string &set_filename, unsigned long set_size)
{
this->size = set_size;
this->filename = set_filename;
}
File::~File()
{
}
const std::string& File::Filename() const
{
return filename;
}
unsigned long File::Size() const
{
return size;
}

19
2022/7/File.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef ADVENT_DVEREB_FILE_H
#define ADVENT_DVEREB_FILE_H
#include <string>
class File {
public:
File(const std::string &set_filename, unsigned long set_size);
virtual ~File();
const std::string& Filename() const;
virtual unsigned long Size() const;
protected:
unsigned long size;
std::string filename;
};
#endif

58
2022/7/Folder.cpp Normal file
View File

@@ -0,0 +1,58 @@
#include "Folder.h"
#include <algorithm>
#include <iostream>
Folder::Folder(const std::string &filename)
: File(filename, 0)
{
}
unsigned long Folder::Size() const
{
unsigned long size = 0;
for(const auto *file : files)
size += file->Size();
return size;
}
void Folder::AddFile(const std::string &filename,
unsigned long size)
{
// make sure the file doesn't already exist:
if(std::find_if(files.begin(), files.end(),
[&](const File *file) {
return file->Filename() == filename;
}) != files.end())
{
std::cerr << "Folder \"" << this->Filename() << "\" already contains "
<< "the file \"" << filename << "\"." << std::endl;
exit(-1);
}
// increment this folder's size total:
this->size += size;
// add the file:
files.push_back(new File(filename, size));
}
void Folder::AddFolder(const std::string &name)
{
if(std::find_if(files.begin(), files.end(),
[&](const File *file) {
return file->Filename() == name;
}) != files.end())
{
std::cout << "NOTE: Folder \"" << this->Filename() << "\" already contains "
<< "the subfolder \"" << name << "\"." << std::endl;
// exit(-1);
}
files.push_back(new Folder(name));
}
const std::vector<File*>& Folder::Files() const
{
return files;
}

22
2022/7/Folder.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef ADVENT_DVEREB_FOLDER_H
#define ADVENT_DVEREB_FOLDER_H
#include "File.h"
#include <string>
#include <vector>
class Folder : public File {
public:
Folder(const std::string &filename);
unsigned long Size() const override;
void AddFile(const std::string &filename, unsigned long size);
void AddFolder(const std::string &name);
const std::vector<File*>& Files() const;
private:
std::vector<File*> files;
};
#endif

2
2022/7/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp File.h File.cpp Folder.h Folder.cpp SplitStr.h
clang++ -std=c++2b -g -O0 main.cpp File.cpp Folder.cpp

22
2022/7/SplitStr.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef ADVENT_DVEREB_SPLITSTR_H
#define ADVENT_DVEREB_SPLITSTR_H
#include <vector>
#include <string>
std::vector<std::string> SplitStr(std::string str, const std::string &delim)
{
std::vector<std::string> rtn;
for(auto split = str.find(delim); split != std::string::npos; split = str.find(delim))
{
rtn.push_back(str.substr(0, split));
str = str.substr(split + delim.size()); // chop off beginning
}
if(str.size())
rtn.push_back(str);
return rtn;
}
#endif

1013
2022/7/data.txt Normal file

File diff suppressed because it is too large Load Diff

170
2022/7/main.cpp Normal file
View File

@@ -0,0 +1,170 @@
#include "Folder.h"
#include "SplitStr.h"
#include <algorithm>
#include <fstream>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
void DebugOutput(File *file)
{
static int indent = -1;
++indent;
for(auto i = 0; i < indent; ++i)
std::cout << " ";
Folder *folder = dynamic_cast<Folder*>(file);
if(folder)
{
std::cout << "Contents of folder: " << folder->Filename()
<< ", size: " << folder->Size()
<< std::endl;
for(File *file : folder->Files())
DebugOutput(file);
}
else
std::cout << "- " << file->Filename()
<< ", size: " << file->Size()
<< std::endl;
--indent;
}
unsigned long PartOne(File *file, unsigned long &grand_total)
{
unsigned long rtn = 0;
Folder *folder = dynamic_cast<Folder*>(file);
if(folder)
{
for(File *file : folder->Files())
rtn += PartOne(file, grand_total);
if(rtn <= 100000)
{
grand_total += rtn;
std::cout << "Folder \"" << folder->Filename() << "\" has a size of " << rtn
<< std::endl;
}
}
else
rtn += file->Size();
return rtn;
}
void PartTwo(File *file, unsigned long at_least, File *&smallest)
{
Folder *folder = dynamic_cast<Folder*>(file);
if(folder)
{
if(folder->Size() >= at_least && folder->Size() < smallest->Size())
{
std::cout << "New smallest size of " << folder->Size() << " by folder \""
<< folder->Filename() << "\"." << std::endl;
smallest = file;
}
for(File *file : folder->Files())
PartTwo(file, at_least, smallest);
}
return;
}
void Parse(Folder &root)
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
exit(-1);
}
std::stack<Folder*> dir_stack;
dir_stack.push(&root);
// Step 1: Parse:
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
if(line.starts_with("$ ls"))
continue;
else if(line.starts_with("$ cd"))
{
auto to = line.substr(5);
if(to == "/")
{
while(dir_stack.size() > 1)
dir_stack.pop();
}
else if(to == "..")
{
if(dir_stack.size() > 1)
dir_stack.pop();
}
else
{
auto existing = std::find_if(dir_stack.top()->Files().begin(),
dir_stack.top()->Files().end(),
[&to](const File *f){
return f->Filename() == to;
});
if(existing != dir_stack.top()->Files().end()) // found!
{
// Check to see if it's a folder, first:
Folder *folder = dynamic_cast<Folder*>(*existing);
if(folder)
dir_stack.push(folder);
else
{
std::cerr << (*existing)->Filename() << " is a file, not a folder."
<< std::endl;
exit(-3);
}
}
else
std::cerr << "could not navigate to \"" << to << "\" from \""
<< dir_stack.top()->Filename() << "\"." << std::endl;
}
}
else if(line.starts_with("dir "))
{
dir_stack.top()->AddFolder(line.substr(4));
}
else
{
auto values = SplitStr(line, " ");
dir_stack.top()->AddFile(values[1], std::atol(values[0].c_str()));
}
}
}
int main()
{
Folder root("/");
Parse(root);
// Step 1.5: Debug output:
DebugOutput(&root);
unsigned long grand_total = 0;
PartOne(&root, grand_total);
std::cout << "Grand Total (part 1): " << grand_total << std::endl;
const unsigned long max_space = 70000000;
const unsigned long space_needed = 30000000;
const unsigned long currently_used = root.Size();
const unsigned long currently_unused = max_space - currently_used;
const unsigned long amt_to_remove = space_needed - currently_unused;
File *file_to_remove = &root;
PartTwo(&root, amt_to_remove, file_to_remove);
std::cout << "Remove \"" << file_to_remove->Filename() << "\" to free up "
<< file_to_remove->Size() << " which is the smallest amount >= "
<< amt_to_remove << " (part 2)." << std::endl;
return 0;
}

2
2022/8/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

99
2022/8/data.txt Normal file
View File

@@ -0,0 +1,99 @@
020110220332333020110144320304042020444223003535441353331002333431100300241023221210123003331021020
002120010112022233203323334422340102033151553341235324543343233301202102130210343113312320222102020
000000000301021002423224442341031145215244543444223314545524515335404222310244314423023331200102012
011200302010212334422213334343335452314532352111122533515334412241512412033340322004232020212310011
110111200102310120411101020333232255345143342245212323552344535253214434143032323213200301101020121
122001020113011314043121413025543341512335111452355331355351515421515411500421204113413212021112302
011210211003201420103123304513544114145311452334355144111521441452154223512022101102111221311323311
011030200312240341224434214241313322323544154242345656634321531531424124544551344224331443202111303
031023120224010220144244342511241334331166432443322363352643453525244443222142533014331212133113031
331033331100013013431114214253543323143222523423236646456363626622312534521454454123324132323233200
313320023430241044213221132131122135436564345625426422255326234363243521151144414344130023210131130
002203011410101343345413454143416333665335233566235623536644652644522345535525153521230411343303211
022030323311323124542521154345356626352343324652424464566645425223224521453553252234321033403323130
331222243010032043452454232565665256426536435254566436633323343652534544214412242551144312310221231
231133233004211422411531255443363333555345434532475762623642433466363266634413551244254134333243030
020231113200002214145443133533534653326664654474363645366343345466265644554325342415122332200024311
311032340032414323451542554464466352256347635357637447736577667463426532442564245132242343241314212
210342413212232542421452232234546643373633347344743377376553465333423522425436534352355150302110320
012302042023135125251364365232626547463576733637455663764376436734352545425434331543241124042312202
304042410233125532432523224245663443763753734647533535565636563665334542556665554245524241400402122
100324144335411111343624365526556753335435457754653754663647544353454443256623466532421524442220212
004310002315421423634565264237567445665436743333467647547754434765353667542365233361541321530411122
340100133133254351662534562377644656735477678648447854646765556636735646456562322345353223545130204
223422234555541234336653556365464346366386775667444744567758637737757667635354324626442355153142402
301202352352311332364654446567354376644665887886878854847858588356564773766244445222614543212440041
121010254322255546522625235356663453785775455846758588786788567566653645763532436352663334521520342
223123122512444365553626454767563488464886467858877655766685458675437556363673526236645213411512224
003314511142456453664565476333555654845565878476575468776548666885476777366354622652365442341232330
100434351354142623236353735657745766665557455465675844665578767675874476556574642555262344222545124
310035122251134332246455666547787878577677667587668567788744875844888844364453536232254344234442004
332355524421462334544344655646458867688886798865795569865997666688465755335745555656646243433122421
212252432545222565265377376368574784887787696558698987968675547855656555445333366624445325141553342
113535121253534442546646364347455675758878676575695576785998796454646647555637657565266546254424513
023531155256556443573534665476784478579889966685965558767695667786588646763565366352565623135242132
332235311465633455637577656876574774599858977857599877979855878694546488485435736564352255345534352
423312331346353345545646578646466549968669789766955768696578957665488458568376747735452426221223133
042131555255526335474354376567744577697576655686887997959968659596857774864465577464334245541411144
314335533542324633457667677854784879668896688676989899996875778858675674784535777333543532331142411
342431321343652634443346854886679789759856968779866777899677797959996774647753365556465426225312415
443122331352464374355445874586585857875568898788666678776787986756859447544446666763365552244452322
434332122456323647344556476668759666569568769987679766689798887678765548587477474536465533643451422
012515214225433447464677777487776597697976998888987789798887796967785955887765466437333665342324523
151212435544622335634548655777875966867886867777679699887698988956977857868655457465635544364542154
425332155643342656676678888575989888788767888899689899798688796666757955465858667777362363434424542
531532414223243445466348848575895777968779899997887798776667989655588765447757447347342252524115215
155245334655555376575664568856876978978787888977789987998877778796686666588544843473375333466131323
442223263655353573545578848875879796997899897789887987979686977788898887848487563664644353624212355
532342436423523433743374566649565796978689677778887988977986779775985585775684847364464225436344143
144131162643455446377457566657777998676869667898877798979888978868889578745676553337663625625354412
212531125562654464546354657756555595879978788779777999979988869895856856488587466676673534564554215
515521136425625643733788668547967896969879989899779977888986996776697776777887634766746536654352314
533115456346557773554457648785576555967877979777897997977979879979889786544548474557775226255314122
432554142445363766476368787846679896977899887779797978979969889696765986666844737665565256236231155
125253442625345476646468778468579567787976888987879797899978977695756855477657433457362446432521533
451335344244435635354545558745856999567779868887799878899867977959975677866558447464563253543641554
412221312464362643575387865576575778679997969899879799897898997777656968646646747476434353234412443
132123436534443354553586484485777568678779897878779989966877968659558598445764456573762542646254544
024143156436353736354736885476858987768978898698789976987668878886568974574565737457544455543452243
413135313643263775675578866878568599957868689889887898688888897699957964455656556464353643525222353
151155234625524455454576866886566769799886776697778986968676996687578554546778475347663665445441542
225335432336665664467554464786765996688599897886876679899878795577796866847588643664352344525425543
231314414363454365656445447648785668665699968677877867679686575989979554888874435546345632362455211
215225154624264466667536475884866766856799777898688869799678789658958655666655664763723652345235254
035354151466424636347656474544888889966575676978876877797665689589954588444647355553546242434541533
001253252266442433343367457848868577696576876956987767987878766766685545864636355333223636351531525
432114153244234344474473336455665467595685659677769775776598955788485844764764774633253355345153344
440231335123622442356777766866685464699576999777998779679677676798556674878735743562224245652132511
321533313113424533355576556587855784598797699998756887876998858868457756543476743664332364153212141
003415211213442534357575744467674686668987887956977567898997789587764784753377657636326255155213240
224445525333436434526743474634674544887785577959758998579798555487687877644644777665225554533252422
114025431113445462556535777346657775747764689775588768859877487468477864653336547436625221413353402
444431445545324552322733365535555774656466544687955795855665775645668663457547655566226341423452434
410445115125126462226236353755455888548674587788447578688475766447586446763443644432535242233435244
124340412535436432636663557555763744747854587474866557668648548584743443577534342355356535325312231
200313132541126432532542747437536486654767558545587875558487658465577773437664544545354413212211212
101333454545223643623655465756576356785656755457885765456674785763465474656725224222541315314114031
131233142323341366245232435554365765545574774767785475776848668453355554474332533326544433554514201
321411402434455156645353526473756763444567846554465464446465455445745336435566265254512531525210112
030131034355454454644464565464475577344753366858566476585577545346763733342656446563454444451042420
123233024345514531322525463344645673755773347575544437475656346736346777342352464432215452454013411
014322323421235432556233655455544546633674634474456664346664375533773475562242423541545331424443423
103044012005453352356343445634325645434337637364655565435774676736733553262634342435541343244030000
320224321434222311444445623462256346445463567453434633465443337646352226626622452524224345304403330
212420324020443535541356556336654222753455556557453353546474577342535554563532343321131244211234443
122201202000423112251512562424625443344753367744337643545467743645523543344535431154212330403302410
302200224224202341324112146243633653523426575646533673677763345633345645554351214352331400423031333
123001320330302415435532414224224226352235334353577574436324344226425624263133551342153034141032032
213131040401103044255424155325562642646633364323565455323646566426224245451451423431324433130343033
231211142003310021532152553311226325626362465244625533422332633634454451545253314415220400420413203
312320130422410131322514243524545532465435666446335525623552365342455442353243151122403024303312021
133332233112042420435241253424143243654366264342464546256332442465235435334432132240241304411322221
333302213333240222002452421142454145262355663455246362444253326353144344554554324413300122011222021
202310030210410440001115535553444131333333663342464256255352255253344353414423520402213424030101331
020120023231001430421410113431542415212332151336254445313532121145524443121220343020012020230032230
210023323121322121303302233233245321224455333332343322323215223451525532222223304043001030230132022
002222021003231011234340303045243412535411232132142332533521354111141433134004443142111110122121100
022122131333022231003311233440122445251415343142141523345254553214425533033042143220401300010213100
122110132221332212341431023220242412121544355542132225542445544553234342030402442141111321103231211
122021200131211021314010312001241211235253115315252213451111223452204220130001212341202130012001221

200
2022/8/main.cpp Normal file
View File

@@ -0,0 +1,200 @@
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
long ScenicScore(int set_x, int set_y, std::vector<std::vector<int>> &trees)
{
const int tree_val = trees[set_y][set_x];
int score_up = 0;
int score_down = 0;
int score_left = 0;
int score_right = 0;
// up
for(int y = set_y - 1; y >= 0; --y)
{
++score_up;
if(trees[y][set_x] >= tree_val)
break;
}
// down
for(int y = set_y + 1; y < trees.size(); ++y)
{
++score_down;
if(trees[y][set_x] >= tree_val)
break;
}
// left
for(int x = set_x - 1; x >= 0; --x)
{
++score_left;
if(trees[set_y][x] >= tree_val)
break;
}
// right
for(int x = set_x + 1; x < trees[set_y].size(); ++x)
{
++score_right;
if(trees[set_y][x] >= tree_val)
break;
}
return score_up * score_down * score_left * score_right;
}
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::vector<std::vector<int>> trees;
// Parse:
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
trees.push_back({});
for(const char &ch : line)
trees.back().push_back(ch - '0');
}
std::set<std::pair<int, int>> visible_coordinates;
for(auto y = 0; y < trees.size(); ++y)
{
visible_coordinates.insert({0,y});
visible_coordinates.insert({trees[y].size()-1,y});
}
for(auto x = 1; x < trees[0].size() - 1; ++x)
{
visible_coordinates.insert({x,0});
visible_coordinates.insert({x,trees.size()-1});
}
// left to right, right to left IN EACH ROW:
std::vector<int> points;
for(auto y = 1; y < trees.size() - 1; ++y)
{
points.clear();
// initialize list with the first value
points.push_back(trees[y][0]);
// iterate through the rest:
for(auto x = 1; x < trees[y].size(); ++x)
{
// if it's higher than the most recent one:
const auto val = trees[y][x];
if(val > points.back())
{
points.push_back(val);
visible_coordinates.insert({x,y});
}
}
}
for(auto y = 1; y < trees.size() - 1; ++y)
{
points.clear();
// initialize list with the first value
points.push_back(trees[y][trees.size()-1]);
// iterate through the rest:
for(auto x = trees[y].size() - 2; x > 0; --x)
{
// if it's higher than the most recent one:
const auto val = trees[y][x];
if(val > points.back())
{
points.push_back(val);
visible_coordinates.insert({x,y});
}
}
}
for(auto x = 1; x < trees[0].size() - 1; ++x)
{
points.clear();
// initialize list with the first value
points.push_back(trees[0][x]);
// iterate through the rest:
for(auto y = 1; y < trees.size(); ++y)
{
// if it's higher than the most recent one:
const auto val = trees[y][x];
if(val > points.back())
{
points.push_back(val);
visible_coordinates.insert({x,y});
}
}
}
for(auto x = 1; x < trees[0].size() - 1; ++x)
{
points.clear();
// initialize list with the first value
points.push_back(trees[trees.size()-1][x]);
// iterate through the rest:
for(auto y = trees.size()-2; y > 0; --y)
{
// if it's higher than the most recent one:
const auto val = trees[y][x];
if(val > points.back())
{
points.push_back(val);
visible_coordinates.insert({x,y});
}
}
}
total += visible_coordinates.size();
for(auto y = 0; y < trees.size(); ++y)
{
for(auto x = 0; x < trees[y].size(); ++x)
{
if(visible_coordinates.contains({x,y}))
std::cout << "\033[1;31m"; // red
else
std::cout << "\033[0m"; // default white
std::cout << trees[y][x];
}
std::cout << std::endl;
}
std::cout << "\033[0m"; // default white
std::cout << " Total: " << total << std::endl;
long highest_scenic = 0;
for(auto y = 0; y < trees.size(); ++y)
{
for(auto x = 0; x < trees.size(); ++x)
{
auto score = ScenicScore(x, y, trees);
if(score > highest_scenic)
{
highest_scenic = score;
std::cout << "New highest: " << score << " at " << x << "," << y << std::endl;
}
}
}
total_pt2 = highest_scenic;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

2
2022/9/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

2000
2022/9/data.txt Normal file

File diff suppressed because it is too large Load Diff

8
2022/9/data_test.txt Normal file
View File

@@ -0,0 +1,8 @@
R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2

169
2022/9/main.cpp Normal file
View File

@@ -0,0 +1,169 @@
#include <cmath>
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <unistd.h>
#include <vector>
void ApplyMovement(std::pair<int, int> &head,
std::pair<int, int> &tail)
{
const int x_diff = head.first - tail.first;
const int y_diff = head.second - tail.second;
if(std::abs(x_diff) > 1) // 2 away
{
tail.first += (head.first - tail.first) / 2;
if(std::abs(y_diff) > 1) // 2 away due to diagonally following!!!
tail.second += (head.second - tail.second) / 2;
else
// snap to axis since you're already on it or you're one away
tail.second = head.second;
}
if(std::abs(y_diff) > 1) // 2 away
{
tail.second += (head.second - tail.second) / 2;
if(std::abs(x_diff) > 1) // 2 away due to diagonally following!!!
tail.first += (head.first - tail.first) / 2;
else
// snap to axis since you're already on it or you're one away
tail.first = head.first;
}
}
void DebugPrint(std::vector<std::pair<int, int> > &points,
std::set<std::pair<int, int> > &visited_positions,
std::set<std::pair<int, int> > &visited_positions_part2)
{
int x_min = points[0].first;
int y_min = points[0].second;
int x_max = points[0].first;
int y_max = points[0].second;
for(auto &pos : visited_positions)
{
x_min = std::min(x_min, pos.first);
x_max = std::max(x_max, pos.first);
y_min = std::min(y_min, pos.second);
y_max = std::max(y_max, pos.second);
}
for(auto &pos : visited_positions_part2)
{
x_min = std::min(x_min, pos.first);
x_max = std::max(x_max, pos.first);
y_min = std::min(y_min, pos.second);
y_max = std::max(y_max, pos.second);
}
for(auto i = 0; i < 50; ++i)
std::cout << std::endl;
std::cout << "X: " << x_min << " - " << x_max << std::endl;
std::cout << "Y: " << y_min << " - " << y_max << std::endl;
std::cout << std::endl;
for(auto y = y_min; y <= y_max; ++y)
{
for(auto x = x_min; x <= x_max; ++x)
{
if(points[0].first == x && points[0].second == y)
std::cout << "\033[1;30mH"; // head
else if(points[1].first == x && points[1].second == y)
std::cout << "\033[1;25m1"; // tail
else if(points[2].first == x && points[2].second == y)
std::cout << "\033[1;25m2"; // tail
else if(points[3].first == x && points[3].second == y)
std::cout << "\033[1;25m3"; // tail
else if(points[4].first == x && points[4].second == y)
std::cout << "\033[1;25m4"; // tail
else if(points[5].first == x && points[5].second == y)
std::cout << "\033[1;25m5"; // tail
else if(points[6].first == x && points[6].second == y)
std::cout << "\033[1;25m6"; // tail
else if(points[7].first == x && points[7].second == y)
std::cout << "\033[1;25m7"; // tail
else if(points[8].first == x && points[8].second == y)
std::cout << "\033[1;25m8"; // tail
else if(points[9].first == x && points[9].second == y)
std::cout << "\033[1;25m9"; // tail
else if(visited_positions.contains({x, y}))
std::cout << "\033[1;31mX"; // red
else if(visited_positions_part2.contains({x, y}))
std::cout << "\033[1;20mY"; // ??
else
std::cout << "\033[0m-"; // default white
}
std::cout << std::endl;
}
std::cout << "\033[0m"; // default white
}
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::set<std::pair<int, int> > visited_positions;
std::set<std::pair<int, int> > visited_positions_part2;
std::vector<std::pair<int, int> > points;
for(auto i = 0; i < 10; ++i)
points.push_back({0,0});
char dir;
int amt;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
dir = line[0];
amt = std::atoi(line.substr(2).c_str());
for(auto i = 0; i < amt; ++i)
{
// Move head:
switch(dir)
{
case 'U':
points[0].second--;
break;
case 'D':
points[0].second++;
break;
case 'L':
points[0].first--;
break;
case 'R':
points[0].first++;
break;
}
// Follow with tail:
for(auto i = 0; i < points.size() - 1; ++i)
ApplyMovement(points[i], points[i+1]);
visited_positions.insert(points[1]);
visited_positions_part2.insert(points.back());
DebugPrint(points, visited_positions, visited_positions_part2);
usleep(100000);
}
}
DebugPrint(points, visited_positions, visited_positions_part2);
total = visited_positions.size();
total_pt2 = visited_positions_part2.size();
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

2
2022/starter/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

29
2022/starter/main.cpp Normal file
View File

@@ -0,0 +1,29 @@
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

2
2023/1/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

1000
2023/1/data.txt Normal file

File diff suppressed because it is too large Load Diff

7
2023/1/data_test.txt Normal file
View File

@@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

126
2023/1/main.cpp Normal file
View File

@@ -0,0 +1,126 @@
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
int main()
{
const std::string filename = "data.txt";
std::ifstream ifs(filename);
if(!ifs.is_open())
{
std::cerr << "Missing " << filename << "." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::map<std::string, std::string> values =
{
{ "0", "0" },
{ "1", "1" },
{ "2", "2" },
{ "3", "3" },
{ "4", "4" },
{ "5", "5" },
{ "6", "6" },
{ "7", "7" },
{ "8", "8" },
{ "9", "9" },
// { "zero", 0 },
{ "one", "1" },
{ "two", "2" },
{ "three", "3" },
{ "four", "4" },
{ "five", "5" },
{ "six", "6" },
{ "seven", "7" },
{ "eight", "8" },
{ "nine", "9" }
};
auto GetDigit = [&](const std::string &line, int i, bool ascending, std::string &result) {
std::vector<std::string> tests;
if(ascending)
{
tests.push_back(line.substr(i, 1)); // single digits
if(i < line.size() - 2)
tests.push_back(line.substr(i, 3)); // three-letter words
if(i < line.size() - 3)
tests.push_back(line.substr(i, 4)); // four-letter words
if(i < line.size() - 4)
tests.push_back(line.substr(i, 5)); // five-letter words
}
else
{
if(i < line.size() - 4)
tests.push_back(line.substr(i, 5)); // five-letter words
if(i < line.size() - 3)
tests.push_back(line.substr(i, 4)); // four-letter words
if(i < line.size() - 2)
tests.push_back(line.substr(i, 3)); // three-letter words
tests.push_back(line.substr(i, 1)); // single digits
}
for(auto test : tests)
{
if(values.contains(test))
{
result = values.at(test);
return true;
}
}
return false;
};
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
std::string first = "";
std::string last = "";
// first
for(auto i = 0; i < line.size(); ++i)
{
std::string result;
if(GetDigit(line, i, true, result))
{
first = result;
break;
}
}
if(first == "")
std::cerr << "Missing digit in line: " << line << std::endl;
// last
for(auto i = 0; i < line.size(); ++i)
{
std::string result;
if(GetDigit(line, line.size() - i - 1, false, result))
{
last = result;
break;
}
}
if(last == "")
std::cerr << "Missing digit in line: " << line << std::endl;
std::string val = first + last;
int val_int = std::atoi(val.c_str());
std::cout << val_int << std::endl;
total_pt2 += val_int;
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

2
2023/1_old/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -g -std=c++20 main.cpp

1000
2023/1_old/input.txt Normal file

File diff suppressed because it is too large Load Diff

7
2023/1_old/input2.txt Normal file
View File

@@ -0,0 +1,7 @@
two1nine
eightwothree
abcone2threexyz
xtwone3four
4nineeightseven2
zoneight234
7pqrstsixteen

134
2023/1_old/main.cpp Normal file
View File

@@ -0,0 +1,134 @@
#include <cctype>
#include <fstream>
#include <iostream>
#include <vector>
#define INPUT_FILE "input2.txt"
int ParseNumLine1(const std::string &line);
int ParseNumLine2(const std::string &line);
int main()
{
std::ifstream ifs(INPUT_FILE);
if(!ifs.is_open())
{
std::cerr << "Couldn't open " INPUT_FILE "." << std::endl;
return -1;
}
long result1 = 0;
long result2 = 0;
for(std::string line = ""; std::getline(ifs, line); )
{
result1 += ParseNumLine1(line);
result2 += ParseNumLine2(line);
}
std::cout << "Part 1 Result: " << result1 << std::endl;
std::cout << "Part 2 Result: " << result2 << std::endl;
return 0;
}
int ParseNumLine1(const std::string &line)
{
char found[3] = { '\0', '\0', '\0' };
bool found_first = false;
for(auto &ch : line)
{
if(std::isdigit(ch))
{
if(!found_first)
{
found[0] = ch;
found_first = true;
}
// same as first, if only one
found[1] = ch;
}
}
return std::atoi(found);
}
int ParseNumLine2(const std::string &line)
{
char found[3] = { '\0', '\0', '\0' };
bool found_first = false;
for(auto &ch : line)
{
if(std::isdigit(ch))
{
if(!found_first)
{
found[0] = ch;
found_first = true;
}
// same as first, if only one
found[1] = ch;
}
else
{
const static std::vector<std::string> available = {
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
};
int num = 0;
for(auto i = 0; i < line.size(); ++i)
{
for(auto w = 0; w < available.size(); ++w)
{
const std::string &word = available[w];
if(line.size() - i < word.size())
continue; // not enough letters for this word
bool word_matches = true;
for(auto letter = 0; i + letter < line.size() && word_matches; ++letter)
{
if(line[i + letter] != word[letter])
{
word_matches = false;
break;
}
if(letter == word.size() - 1)
{
num = w + 1;
// std::cout << "Found: ";
// for(auto a = 0; a <= letter; ++a)
// std::cout << line[i + a];
// std::cout << " == " << available[w] << " @ " << letter << std::endl;
break; // true!
}
}
if(word_matches)
break;
}
if(num)
{
if(!found_first)
{
found[0] = num + '0';
found_first = true;
}
found[1] = num + '0';
num = 0;
}
}
}
}
std::cout << "Return: " << found << " == " << std::atoi(found) << std::endl;
return std::atoi(found);
}

4
2023/1_old/sample.txt Normal file
View File

@@ -0,0 +1,4 @@
1abc2
pqr3stu8vwx
a1b2c3d4e5f
treb7uchet

2
2024/2/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main_pt2.cpp
clang++ -std=c++2b -g -O0 main_pt2.cpp

1000
2024/2/data.txt Normal file

File diff suppressed because it is too large Load Diff

6
2024/2/data_test.txt Normal file
View File

@@ -0,0 +1,6 @@
7 6 4 2 1
1 2 7 8 9
9 7 6 2 1
1 3 2 4 5
8 6 4 4 1
1 3 6 7 9

83
2024/2/main.cpp Normal file
View File

@@ -0,0 +1,83 @@
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
std::istringstream input(line);
long *last = nullptr;
bool *increasing = nullptr;
bool safe = true;
for(std::string value; std::getline(input, value, ' '); )
{
long current;
// Get the value:
try {
current = std::atoi(value.c_str());
} catch (const std::exception &e) {
break;
}
// See if it's the first value:
if(!last)
{
last = new long(current);
continue;
}
// See if it's the second value:
if(!increasing)
{
increasing = new bool(current > *last);
}
auto diff = current - *last;
if(*increasing &&
(diff < 1 || diff > 3))
{
safe = false;
break;
}
if(!*increasing &&
(diff < -3 || diff > -1))
{
safe = false;
break;
}
if(last)
*last = current;
}
if(increasing && last // actually made it through at least 2 values
&& safe)
total++;
if(increasing)
delete increasing, increasing = nullptr;
if(last)
delete last, last = nullptr;
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

146
2024/2/main_pt2.cpp Normal file
View File

@@ -0,0 +1,146 @@
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
bool GroupSafe(const std::vector<long> &group);
int main()
{
std::ifstream ifs("data.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::vector<std::vector<long>> data;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
// add a row for this line:
data.push_back({});
std::istringstream input(line);
// for each value in the line:
for(std::string value; std::getline(input, value, ' '); )
{
try {
// add it to the row
data.back().push_back(std::atoi(value.c_str()));
} catch (const std::exception &e) {
break;
}
}
}
// DEBUG:
// for(auto row : data)
// {
// for(auto col : row)
// std::cout << col << " ";
// std::cout << std::endl;
// }
for(auto group : data)
{
switch(group.size())
{
case 0:
// Go to next line
continue;
break;
case 1:
// Can't be increasing or decreasing because it's the only one, so I guess safe?
++total;
++total_pt2;
continue;
break;
};
bool safe = true;
if(GroupSafe(group))
++total;
else
{
bool re_safe = false;
for(auto i = 0; i < group.size(); ++i)
{
std::vector<long> check;
if(i != 0)
check = { group.begin(), group.begin() + i };
if(i < group.size() - 1)
check.insert(check.end(), group.begin() + i + 1, group.end());
if(GroupSafe(check))
{
re_safe = true;
++total_pt2;
break;
}
}
if(!re_safe)
{
std::cout << "Bad: ";
for(auto val : group)
std::cout << val << " ";
std::cout << std::endl;
}
}
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total + total_pt2 << std::endl;
return 0;
}
bool GroupSafe(const std::vector<long> &group)
{
bool increasing = false;
for(auto i = 0; i < group.size() - 1; ++i)
{
if(group[i] == group[i+1])
continue;
increasing = group[i] < group[i+1];
break;
}
bool safe = true;
int *last = nullptr;
for(auto i = 0; i < group.size(); ++i)
{
auto next = group[i];
if(!last)
{
last = new int(next);
continue;
}
if(increasing &&
(next - *last < 1 || next - *last > 3))
safe = false;
else if(!increasing &&
(next - *last < -3 || next - *last > -1))
safe = false;
if(!safe)
break;
*last = next;
}
if(last)
delete last, last = nullptr;
return safe;
}

2
2024/3/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp #-fsanitize=address -fno-omit-frame-pointer

6
2024/3/data.txt Normal file
View File

@@ -0,0 +1,6 @@
mul(168,87)}*:mul(911,800)(%,)where()#&&$mul(734,19)?when()why(){$:?mul(829,495)do()mul(724,312){;^mul(520,383) mul(137,485)select()-mul(700,211) <(who()who()/mul(295,600)]~<select()'$why()do()when()mul(310,255)^}where()who()(!+mul(16,916),)what()@:@#where()mul(918,822),when()~/)mul(177,722)<&]:who()where()>mul(439,650)?+$mul(349,399)mul(807,317)what()?@[%mul(674,778)!mul(104,928)~[!!mul(60,636){where()when()&@why()-+mul(742,28)select()why()'&why()@>select()mul(527,483)mul(797,855)how()mul(502,647)what() {(*'}%mul(688,600))!??,+$mul(538,127)&from(),>~&*mul(963,787)~mul(820,259)~}~how()>do()what()^<}[?{'mul(202,9)$select(795,484);from()<!mul(913,93)/{{what()#-select()how()]mul(520,288),^&what()mul(583,623)mul(657,601)>;^@what()mul(671,74)&@how(151,76)!?:{mul(933,567)/)&select()do()>+,~?>mul(627,488) *mul(437,91){!#}%?how()who()mul(741,704)select():where()mul(258,129),&why():)mul(770,13)@ from()?-!what()$mul(229,613)from() select()why()};select()mul(59,263)where()from(97,930)?where()mul(514,278)(-don't()&$[how()why(783,866)&who(589,80)#; mul(130,239)don't()mul(195,249),~>>who()mul(945,698) /}how()>mul(983,248)[~why()({from()-(how()?mul(206,469)&>~who()]mul(661,410)how()&mul(768,601)/!--select()>,%mul(455,805)(}]how();<who(735,631)why()mul(216,340))what(181,514)mul(736,427)^when()]$%where()'<;mul(754,836)*@!why()select()]mul(869,551)~mul(752,713) <(~&@#mul(124,162)why()/mul(512,273); /where()why()mul(471,915)/(where():?}mul(608,515){[@:'select()[][ mul(983,96)%where(),why(){~-+]mul(102,860):#?select()%who(105,947):who(416,728)mul(765,635)@(mul(898,549)$where(580,81){mul(497,154)>/from())mul(728,180)'(what()[mul(915,20)who()+&don't()select()^)}$!who()+>mul(481,439)- *mul(332,923)when()-why()!mul(625,335)?mul(156,134)why()*'$:mul(104,186)^?#>/mul(605,863),,?mul(161,457)!#~,#~>/mul(514how()where(),'$;'$+)mul(207,90)&>$how()mul(394,95),where()'mul(827,742)how()[from()(]:/why()$+mul(46,294)>who()who()^@[^mul(500,356){]{mul(989,398)(}: mul(300,17):how()who()%?#@why()!mul(362,556)>$mul(29,294)who()<;when()mul(108,898),#<<~-*(where()@mul(86,710),'-$&what()(mul(573,832)),?{mul(953,794)why()^what()-*,/?)mul(511,634):how()/how()'what()what()mul(709,593)]mul(721,842)(!&why()where()&mul(259,304/$[*why()+#mul(932,748)? {mul(979,591)mul(576,282)(-when():^,select()>@mul(146,41){[<#(#'*}mul(615,174)&>when()what()&(mul(914,488)[~why(267,875)mul(167,385)+<%~}@![why()mul(221,316):,;[:@(!who()mul(340,617)&*how()%mul(151,744) >},-)'?mul(414,238)mul(100,868)%%what()where()mul(467,880):mul(266,276)!@!#'who()'mul(500,629)[#^select()*+how()(mul(538,599):* [;'mul(919,315)mul(760,200) <$/$}{why()'(mul(794,683)from()**'$,}}mul(915,608)>$$mul(114,893)what()select()do():^from()??from()from()^mul(316,793)>'/when()+mul(199,368)[~mul(539,838) ^(*??%mul(162,286){mul(647,357)who()$(>what()?,why()>from()mul(239,449){select()who()mul(408,790)mul(567,879)
when(),who()[what()mul(874,22)mul*'mul(908,653)>~)@mul(773,355)#mul(716,195) ?@who()mul(128,574)^select(),{:mul(799,387)who()-)+]select()'mul[mul(153,811)from(854,516)select()'(',#mul(760,387from()mul(434,344)@?what(),&!'mul(108,675) 'who()%>+why()mul>]%select()[mul(793,13)mul(333,332)~why()/what()mul(774,658)**mul(375,739)[)*what()what(),>::>mul(702,335)%}{-@'~who();mul(992,903)}where()$(~@)'%mul(488,891)where()*);why()what():{&why()mul(29,881)&]where()where()~*mul(886,964)}&):where()who(){?mul(60,664)why()from()< +select()[when(789,49)$mul(40,510)<how()who()mul(755,503)mul(851,686)?#;}{{from()~'do()>from()~ who()>?from(431,14)%[mul(313,439)mul(999,227)[how()']what()(%,don't()who()><{#~'where()?mul(796,988)what()$/why()#select()/#what();mul(401{~mul(949,141)when()why())/^$$}^(mul(472,738){]:+mul(372,612)mul(647,895)>&$***mul(619,883)(;^mul(864,456-}#/?mul(68,612)~,}>from()!>-when()mul(997,365)mul(524,378)where()where()/!mul(301,937) ++?^what()mul(656,303)}{}mul(953,842);select()select()~[)<mul(617,87)where()what(517,442)~{mul(412,205)-?^?from()],+mul#?%#mul(389,357)how()!$<mul(809,511)who()>do() !;!mul(344,321)from()mul(819,403)+how()where()where()<($mul(908(,>%*why()what()^mul(533,374)-,select()mul(905,803)mul(140,691)what()([mul(874,79)]?how()what()?->mul(344,908)$#&#;from()!mul(256,631){where()#@,]~*:why()mul(225,679)where()?[mul(141,585)+)@~#how()mul(933,177)((+select()mul(312,241)+mul(247,632)how()^[,&from():where()%mul(663,72)![@@when()mul(274,536)>who()@mul(269,240)mul(732,115)!%@'%mul(479,836)-why()mul(502,828)#mul(548,385))mul(312,586)/&{//+{^mul(275,705)where(377,884)$ *!who()mul(382,713)+<@(<>)[select()'don't()mul(182,291)select()]:*select()where(872,531)what()&)mul(361,941)why()/+mul(832,469),-$)mul(753,874)^when(){,@mul(865,352),+#what()mul(749,612)!?#]from(),#mul(734,31)when()^mul(992,318)mul(396,187where()mul(134,182)&<&%$[>,mul(527,215)mul(400,794)'~what()mul(427,148)where()from()<<mul(867,258)<>-mul(495,578)where()}-don't()select()%+^{]what()where()mul(730,966)%$where()'mul(507,416)from()~)how(488,343) %<%>$mul(486,368)what()why()[mul}^^{who()what()[select()'why()who()mul(214,853)from()how(301,437)^):)]how()mul(657,161))(^@select()'mul(313,702)(mul(486,323)*&;&why(){'&how()-mul(911,603)-what()%mul(519,498))select():from()mul(652,991)!!/,mul(308,418)- &#+(who())~)mul(749,786);what()(mul(731,76)<!mul(572,33)/%:;select()from()mul(509,810)~mul(861,431)>do(){&what()$+-^how()mul(214,122)mul(540,414)from()mul(640,157)select()< #:;]^mul~mul(705,467)(?[}when()>where()?mul(45,584)~when()^;mul(519,782)}#when()+[mul(670,319?>]mul(451,604):mul(646,328)when()^mul(326,180)why();who();'$mul(642,425)from();?+when()]mul(907,636)what()%;do()what()?{who()mul(974,27)>{how()(^}mul(357,294)${~[@mul(983,221)who(){(!~from()^mul(128,197)*mul(942,48)>:+]{/from()#mul(237,772)<+select()@mul(361,84);why()]!)who()}+mul(740,305)&,[>]how()mul(660,613):)from()do() select()?when()%select() (mul(835,437)why();)</? how()mul(417,353)-( !select(480,286)mul(935,409)who()/*^+$mul(48,5)>how()mul(819<%/{how(675,621)where()@(>from()mul(722,49)
+)do()%;!who()who(772,423)]$<-mul(328,361))mul(149,957))do(){#!where()>#what()(select()/mul(756,781) *-select()?why(713,643)mul(514,277)$]how()/^mul(7,203)%when()how()who()mul(389,589~]who()*>$^@mul(129,92)~;mul(759,369)how()*!&from()/when()%mul(650,562),*who()*'%when()mul(236,299) }?how()how():don't(),who()how()'why()who()what()@mul(322,510):-@:$@^mul(634,343)-what()#what()from(38,805),<+mul*where(835,107)where()&where(816,43)(%{mul(617,254)where()!^![ who()?;<mul(166,155),$*:<mul(827>/~*;why()mul(788,442))-what())!?(mul(662,916)mul(401,521)mul(234,405)+~,{>from() :{select()mul(635,416)+[~[,mul(562,550)mul(152,551)#]mul(164,957)~<what()#where()>from() mul(761$who()?--<where()+mul(795,259)[~{?<select()&:mul(229,87)mul(864,182)how()?mul(974,34),mul(627-mul(177,523);,^mul(45,82)[-!}mul(370,437)(#:];:(mul(818,270)'}^]when()how(934,258)don't()'{+*why()}mul(530,297)]^/$from()<who()*$mul(842,310)from()^/)%select())+mul(482why()select()&from(415,942)!]how()why()mul(279,984)~when()>}~'/who()when();mul(796,168)what()mul(199,983)>:]when()?why() mul(410,263) when()how()?mul(413,448)]mul(825,830)# mul$mul(261,686)@~{>{what(276,567)mul(341,638)who(){?*$[why(831,759)^ from()mul(741,711)'who()select(){mul(61,52)[what(){%don't():who()@mul(219!)?];where();' *mul(371,514)>[:mul(53,428!mul(538,853)]$#~do()@mul(200%{$$[$#$)mul(57,357)/mul(399,855)~<(*@~what()(@mul(814select():what()]~[#mul(507,982)**mul(68,893)}#mul(631,348)from()mul(205,133)mul(497,687from() !mul(728,117)[;)'@/}@{mul(678,169)who()@$@@~%how()mul(959,969)%@^&{~! ]%mul(324,123)'from()who()}^%mul(763,855)from()^when()#{ /from()#]mul(316,502)what())^<^%%mul(813,959)&why()~~-?-mul(798,375)$>{#'why()&:,why()mul(83,95)(don't()mul(798,687)when(506,624)from()(,how()^: ]>mul(149,563)why()~mul(41,612)-:?when()^/)mul(974,373)>when()?how()*mul(36,761)what(){&@)mul(390,671)when()mul(696,964,@when()@$/?~>~mul(548,987)select()what()% who();$mul(80,587)&^{+,don't()?what()*why(),( mul(124-^>how()/>'mul(155,901)?<;when()!!mul(90,13))/'^from()&[,)mul(805,998):@select()/~from()+(^/mul(823,626)%where()select()how()%&>mul(257,517))#->mul(304,899))mul(255?mul(302,286)>?@<mul(777,721)^&what() !from()/*where()mul(817,696)why()#+&who()why(351,81)}where()$mul(237,864)<&(do()^?from():*{<who()select())mul(975,616),{+where()/@@who()mul(549,977)@<)when(),mul(508+<$mul(716,515)^,-]who()#select()<+mul(118,226how()mul(543,380)(how()?select()from()@}mul(28,144);;'>mul(899,21)@mul(619,488)$->&^@from()(*-mul(266,282)/]from()@who(109,244)()mul(98,720)why()what()>;% mul(681,256)#~)]from()@&mul(517,40)@@what())mul(725,452)mul(852,71)?$mul(612,673*select()what())#mul(120,4),where()who())mul(808,259)who()'^~mul(325,215)!>select()~mul(853,581)%why()mul(652,100)%<select()##what()~mul(237,441)when()!how(753,120)^mul(890,518)from():,who(196,65)+#$ mul(664,43)}%^how()/from()[[when()mul(39,906)mul(324,714)#[#from()mul(569,489)'<who()*@mul(167,880)*select(){>^@don't()/,when()~what(),+&mul(975,420){+*when()]^how()*why()who()mul(448,331)!/when()~mul(235,190)^$}+*++{#mul(96,137):?%where()mul(511,78)};^{&:when()!don't()&when()''&#:{mul(205,318)*!where()?when()~/&from(733,701)?mul*#&#where()where()]{select()mul(474,265)from(755,678)why()!;#]'>-]mul(132,817);&)]^*what()[mul(831,118)select()<mul(181,530)%)mul,])!<>+how()how()mul(292,875)%&select()[@*mul(868,274)&@select(),{mul(427,903)/@]mul(620,307-+what()select()-where()mul(206,860)-mul(937,784):where()!+mul(347,517)#!/usr/bin/perl(select()~from()mul(730-,what()!where(360,351)what()*how(600,916)mul(929,974)
~]#<!when()[~*<mul(132-+why()#%*~:@mul(416,703){@#';>mul(190,848)?{from() }where()<mul(527,529)-mul(209,184)?[what()when()mul(77,529)why()how()<#who(360,918)-mul(417,741)where()what(269,273)from()(mul(322,695)select()@^][don't()]mul(739,357)']when(789,549)/:&when()>mul(532,685)#+~^&]^where(947,658){mul(835,556)mul(785,197)@mul(20,129)>(%*$?,%^]mul(309,855)(!select(){[?](mul(408,217)+;who()why()-&$ ,$mul(824,38)&mul(848,553)@where()who(774,973)-[;mul(590,491)what()'/mul(625,672)!}~~%>-{]-mul(113,831)}+//>(what()mul(822,256):<*$!select()mul(743,335)how()^* (<mul(341,513)do() {,(how()*,^&mul(777,587){>^what()'{[,select(249,901)mul(795,853)@$;mul(486,10)>>?~mulwhere()<~}mul(375,790)/}when()*!mul~-select(){select()select()<]don't()''-'mul(934,731)select()';*select()&why()mul(280,932>mul(530,961)how(),-{how()&what()>(mul(285,204)who()+select()>~>?/<)mul(791,587)from();~mul(142,801),from()~>when()mul(636,737)mul(122,583)select()mul(29,534)[<}>~?;++,mul(853,461)where()&/where()>do()what()where()mul(224,748)when()(from()$%>mul(537,689)@how()from(97,626)%!mul(854,118)when(998,592)-+>how()'when()/mul(548,649)who()who()#) &@!,do()}[^[@mul(154,777)mul(96,225)when()mul(951,144)what()mul(358,785)select()+from()what()-$mul(507,770);select()where()where()mul(696,121)who()when()]&$}how()what(){mul(63,669)+*where()/why()mul}&@where()!?'@;mul(81,559)*]how(372,376)mul(602,773)+mul(511,514)) (,}mul!#%$where()from()%~?>+mul(451,596);from()mul(719,514)^who(533,943)}how()@mul(382,562)!#[,@*)>mul(234,778)&-mul(280,479){, [do()how()!&{mul(971,30)'@why()) ?:+>don't()where()%from()/*&&!mul(551,129)where()!when()@@>[$mul(266,378)&mul(354,236)where()who()mul(198,648)when()~<[what()what()mul(215,213)mul(687,432){,mul(595,927)+<why()*@how()*{%mul(764,459)>who(829,436)^+mul(424,283)@why(),mul(169,939)/[*from()> %!(mul(537,425)%^mul(352,791)*#when()when()-&;what()mul(904,80) select() how()how()mul(34,66)@%<mul(276,65)where()when()how()})mul(52,448)who();select()mul(692,130)what()${%&^%mul(444,170)[)(,<mul(297,209)%&]select(170,397)$mul(577,234),select()^:~,[*>do()mul(921,346)/#what()mul(49,901)mul(734,885)/)(:mul(553,997)(who()mul(62,853)from(535,930);where()#what()mul(457,969)&(+(*}why()mul(317,972)where()when()$do()why() why():~%:^mul(447,529){mul(612,477)how()$when()mul(66,532)>$$*mul(945+*<how(289,725) who() what()how()how()}mul(304,883)select()^':{/':'-mul(715,525)!mul(270,804)from()::['when()why()mul(93,166),-when()!mul(736,616)+;mul(531,606)<how()&[+&mul(967-^'}+-}from()mul(178,389)who()<*mul(116,273)#);#select()mul(628,521)@}where()<where()(;how(376,88)<mul(99,450)}<how()$mul(612(mul(214,455)?:mul(841,59)~~mul(162,250)^]#&>*^)who()mul(291,880)/mul(903,311)*;how()mul(58,539)]-@+&%),what()mul(501,878)*[[mul(626,427)]}how()?when()[mul(280,653)/when()]-<mul(765,466)~-<(select()}{){do()from()*where()!;mul(701,836)'~mul(529,579);!:'+@/'mul(54,282)^<'mul(792,927)&mul(470,236)who() @ ])+??mul(693,230#+~?:-^mul(814,574)from()<when()@#mul(430,705)where(),when()@*$!what()$how()mul(95,323)who()when()mul(38,704)@{where()why(),from()where()[{<mul(455,604)}where()from()~mul(719,681)mul(131why()^where(389,683)**mul(331,541)-}{mul(320,970)
:}#mul(737,307) *?)~,]mul(740,642))><mul(666,137)why()where()where()from()why()$ mul(709when(),select()*]when()(mul(510,937)&+>where()why()mul(235,299){;select()mul(543,852)>mul(456,133)(>mul(671,153)'?*who()(mul(12,640)<{##+mul(432,266)*>)'[~>$~?mul(816,840)what()-mul(698,399)how()mul(45,603))~*what()mul(737,715){when()why()~from()mul(995,968)where()mul(262,96)^?who(){; )from()who(615,278)mulhow()mul(838,616)}from())mul(865,576))~-;how()mul(192,403)))[-$]^select(),mul(184,369)#why()*^;)(do()#,'mul(423,897);)]what()/[$]mul(867,533)select(138,395)*-how()mul+#<why()}[~{mul(925,163)<mul(798,343):mul(137,381)~/>;mul(515,882)]:(mul(364,946)&!&,how()select()- mul(111,167):~$from()^]don't()&mul(829,425)!'/how()where()]/<what()mul(521,742)mul(316,792)mul(311,104)from()<%mul(869,189)^&why()[&:mul(683,138)how()mul(533,311)from()%what()@mul(785;select()~?{}++where()mul(102,590)}&what()}(^[<:mul(997,376)'@/$;mul(25,111)~+$]^;+?mul(786,845)@why()&mul(737,79)''from(340,968) how()where()^?mul(803$select()*why()!select()*/%-mul(450,746)who()-(from()where()when(525,894)mul(110,878)-%select()$)@;mul(445)]-~~*/)&mul(205,632)$[^}select(599,536)how()how()who()]mul(952,986)who()/#*:]who()+/mul(346,355)^where() don't()@who()?+&;mul(617,393)&how()>mul(195,257)*mul(953,79);who()when()$,from()<>why()mul(529,405)from()&mul(492,793)&#*[;+;-mul(331,898)?/{+}mul(424,343)$~[mul(523,74)why();mul(772,703):;mul(17,157)! }why()/]!^mul(979,338when()$?mul(898,616)}why(359,279)+from()what())}$from()!mul(612,784)(where()mul(640,368){#!mul(69,807)]how()( #mul(739,987)'*~&%who()!}@mul(834,525)when())::$mul(122,894)%+^(who()@when()%mul>when()from()?mul(464,80)$^! !/@?@,mul-what()!!@:[mul(283,21)([how()[mul(11,617)]}where()/mul(976,268)mul(843,731)<how()why()[mul(601,412)%how()!]@*why(136,791) -mul(371,365)@~$*'~[/ mul(15,594)how(),/{#-}>'mul(676,131)where()}{(]'where()mul(459,88);(where():mul(64,747);[&$})+select()&;mul(750#[{;*&mul(458,334)?where()select()%)mul what()?when()mul(808,879)what()*}-$+from()where()@mul(152,857)'#%where() /<:+?mul(304,149)from()!<when(865,985)mul(238,815))~!+<)@from()mul(401,975)%&mul(625>*!mul(802,11)!*select(),; )-;how()mul(199,993)/!when()^;[)mul(577,723)!?^who()+what()<mul(489,809)~what(625,812)<?;*#)how()do()!(]who()what()where()*from()+mul(705,108)(who()why(815,180)[]^[mul(821,379)&^(&<,%mul(197,678)%-what()mul(944,295)select()how()!mul(357,711))$-what()'&)'mul(114,910)}<*@-from(688,563)[mul(279,269)from()}$mul(707,287)<;*+what()*>when()mul(447,881)+'(+&@&do()mul(192]what()%/mul(463,832)mul?^*>why()where()from()what(){*mul(456,920) $where(911,93)select()+who()select()}don't()}!how()what()~+what()mul(404,558)>,>{(?{'&,mul(936,304);mul(232,989~;>]who()mul(582,897)*!mul(11,23),~>!{<who()$>mul(542,522)^;,from()(?mul(177,928)how(985,316)}who()@](-#why()mul>~why(851,863)[)!@>mul(101,448)select()+?%&select()~((mul(11,450)how()^)mul(344,639)}+;mul(343,648)^why()!where()&{/'#mul(9,810)where()-%mul(877,263)&select();where(240,275)[mul(289,282)how()&<{who()} ['do(){mul(818,421)/}$]mul(617,829)~['why()?&~)mul(741,559)mul(133,701)$]:@&mul(594,307)[',how()^{how()mul(388,657!({'mul(492,896)#@/why()why()mul(127,225)}>where()-/,^mul(219,314))mul(682,893)what()why(){(,from()(?mul(219,360)what()' ](mul(80,569)
select(82,585)mul(693,510)%$what()from()mul(740,749){~'<]mul(281,263)when()(!?>/% +mul(116,41)-*-when(506,165)?^}mul(651,943){~,/what(){#{!mul(629,41)/mul(74,998)?mul(525,86)&how()do()+/%mul(15,103)#select(671,57)from()who()]mul(309,559)%>mul(311,459)'when()@#mul(980,750)when()+%how()how()~:mul(484,554) )+{ - :]mul(113,626)[^<%,mul(187,326)*:!]*!mul(374,45)from(),mul(41,137),^)-,#when()?who()mul(93,289)select(853,56)]^where()mul(43,349)*where()mul(406,653)from()from()*&*mul(486,350);)*~how()mul(817,387)>>when()who():mul(417,224)^!&{from()}@mul(342,365)why()^who()+~!}when()do()why()when(939,686)^)((mul(160,438)what()>mul(23,766)+]*mul(618,433[/~where()[;why()what(){mul(292,318)*$why(664,963)how(68,975)why()who(276,89)where()!why(777,555){mul(875,358)@'[#who();)mul(198,992)?:(?~where()what()how()-'mul(956,332)mul(889,561)from()((what()mul(753,443)#>? , -mul(267,527):when()+mul(225,923)>>?^mul(726,980)~when()'mul(760,283)!;why(),;when()mul(358,713)//select()]%^{why()*'mul(406,429,(: {how()!^;mul(363,272)--where()*:select()when()?when()mul(242,130);why()>:!&why()$mul(386,685)@!}>when()why()>how()how(872,684)mul(418,627)why()[{:[-%mul(946,701)(}mul(10,874)&mul(109,151)],mul(676,79:;]}),mul(206,822)mul(228,261)-how()?]+mul(295,706)/]@( how()-mul(558,819)@::!>where()*when()?}mul(709,558)*)~;?}> how()from()mul(489,495)[*where():}(*%mul(189,692)how()/where()why()(mul(895,190))]<select();'who()when(309,317)mul(204,524)from(),&# mul(563,48)what()mul(207,241)&mul(450,18)when()what()select()^]{$why(565,783): mul(422,431){,}?+how()what()where()mul(782,229)[%}:~mul(994,946)){,$*,mul(84,333)#?@^]mul(324,259)<mul(723,626)*)/select()mul(22,373)from()mul(158,952) #mul(862,250)'$#;{mul(816,365)&$who(930,819) mul(440,442)^@@mul(35,883))>{+mul(904,446)~(?-*:select():]?mul(21,770){&?/what()mul(810,761)( <{#^why()select()mul(542,583)mul(517,719)*who()]mul(229,391)^:,;where()who()[&mul(181,416)>when()( %+{mul(376,885)+}/}*what()[%when()mul(412,213)who() mul(151,478)do()+when()mul(683,117)@how()[@>(*%mul(666,434)%+mul(83,30)^}:mul(983,213)@-what()mul(36,788)';%-#+]#mul(575,6)#when()'&@who()<$ who()mul(764,292)<,where()where()mul(230,519)<<^('mul(384,769)%,what()@who()when()where()when()mul(104,361)&select()what()-!mul(523,283)do()mul(920,551)mul(589,394)$(select()?#>&*'mul(672,365)+:]@$)mul(373,982)mul(810,292)-mul(990,386)?mul(372,766)where(),]^mul(651,898)from()from(){?;select()mul(293,197)why()( [;&^~@mul(505,310)what()what()select():]-what(873,670)mul(885,505);-#{';-how(967,119)select() mul(956,774)mul(51,516)mul(756,597)^~select()how()%&from()mul(463,747)&why()who()())mul(193,948)from()when()what()why()from():select()%select();mul(143,694)(mul(448,194)@<(-where(536,660)?select()mul(280,832)select()#^}mul(296,908)where()@{> #*do(); ;how()mul(417,4)mul(939,57)&'~?-'(#do())[where()+<<where()mul(223,643):%/mul(367,601)}*}[mul(451,653)why()<when()from();(#<;mul(960,745)>%:?(}mul(975,356):,select(275,833),#?(when()&]

1
2024/3/data_test.txt Normal file
View File

@@ -0,0 +1 @@
xmul(2,4)&mul[3,7]!^don't()_mul(5,5)+mul(32,64](mul(11,8)undo()?mul(8,5))

74
2024/3/main.cpp Normal file
View File

@@ -0,0 +1,74 @@
#include <fstream>
#include <iostream>
#include <regex>
#include <set>
#include <string>
#include <vector>
int main()
{
const std::string filename = "data.txt";
std::ifstream ifs(filename);
if(!ifs.is_open())
{
std::cerr << "Missing " << filename << "." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
bool multiplying = true;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
std::regex pattern("do\\(\\)|don't\\(\\)|mul\\((\\d+),(\\d+)\\)");
auto pattern_begin = std::sregex_iterator(line.begin(), line.end(), pattern);
auto pattern_end = std::sregex_iterator();
for (std::sregex_iterator i = pattern_begin; i != pattern_end; ++i)
{
std::string result = i->str();
if(i->str() == "do()")
multiplying = true;
else if(i->str() == "don't()")
multiplying = false;
else
{
std::smatch::iterator ip_it = i->begin();
std::vector<long> numbers;
for (std::advance(ip_it, 1);
ip_it != i->end();
advance(ip_it, 1))
{
std::string n = *ip_it;
try {
numbers.push_back(std::atoi(n.c_str()));
} catch(const std::exception &e) {
std::cout << "ERROR: " << e.what() << std::endl;
exit(-1);
}
}
long result = 1;
if(numbers.size())
{
for(auto n : numbers)
result *= n;
if(multiplying)
total_pt2 += result;
total += result;
}
}
}
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

2
2024/4/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

140
2024/4/data.txt Normal file
View File

@@ -0,0 +1,140 @@
MMSAXXMMMMSMSMXMXSSMAMSMSXMASMMAXMASMMSMMAMXXMASXMXXXMSASXSSMMXSAMXXMAXXSMSMSMXXAMXAXMMMSMXAMMASMSMXAMXXMMMMSMSXSAAMXMMMSAMXSMMMMMSAMMSMSXXX
MASMMSMMAMMAMMASXMXXAMXMSXAAXAXAMXMXMASXXASXSSSMXXMAMAASXXSAMXASASASXSSMMASAAMSMSMSXSAAAAMMMSMMMMAMSASMMMMXAAXXAXMMSAMMSAMXAAMASAMMASAAMSMMS
MMSMASMSAMMAMSMSAASMMSAMSMMXXMMXXASXSXXASXSAASAMXAAAMMSAMXSXMMMSAMASMAAXMAXMAMSAAMAAMMMSASAAAAXASMMAAMMAXAMMSSMXMMASASXSAMMSMSAXAXSAMMMSXMAA
XSXMXSASASXMMMASMMMAXXAMXAXMXSAMSXSASMXMSSMMMXMSSSSXSMMASASASAMMAMSMMSMMMMSSMAMSMMXSSMMMMAMMSSMASXMMXMXXMSSXAAAAMMAMSMXSAMAAAMMSSMMASAMSAMSS
MMMSMMAMAMXAAXXXMXMXMMMMSMMAMMAMXA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XMXMAXASASMMSMSXXXSMSXAAMXXMAMXMMSXXMAM
MSAXAMMAMAASMMAMAXSXSMSMSSMSMXMAMAMXASASMSMAAXMAAMAMMSXMXXAMXMMMXXAAXXAAXXXXASXSXMMSSMMMMSMSXSAMXMSMSSMSSSSXMASAAAAMMMMSAMSMSMASXMASMAXMMSXX
XMAMSMMAMMXXAMMMSMMAAAXAAXMAMAXAXXAMAMAMXAMMMSXSASMSXMAMMASMMASAMMMSSMSAMXMXMMMMAMXXMASMXAAXMAXXAXXAMXAAAAXMMXMMSMSMAAXMSMXXXMASAMASMSXXASMM
SMXMMASMSMXXXMXAMAMXMXMSMMXASMSSMMSAAMAMXAMXXAAXMMMSASXMAXAASAMASAAXAMXMSMSMMAAMAMMMMAMXXMSMMXSXAAMMMMMMMMMMXMAXAMXMSMMXMMMSXMMSMMASMXAMXSAS
XXSASMMAAASMSMMXSAMMSAMXXMMMSXSAAXMSMSXSMMMSAMMAXAAMXMASXMMXMASAMMSSSMAXAAAMSMMSAMSAMSSSMXXAMAMMMMAAAXAAXXMAAXMMMSSMMSMMXMASAMAMMMMSASXSASMM
SMMXMMMMMSMAASAASAMXAASAAAXAMXXMMMXAMXAXXAAXAAXXSMMSAMXMASXASMMMAXAAASASMSMMAAXSAMMASXAAXAXXMASAXXXSASXSSMMSXSAXSAAAAAXSSMASAMXSAASMAMAMASMX
XXMASXASXXMSMMMXSAMXSXMXXSMXSAXXMXSMSMXMMMSSSMAAMAXSAXASAASMMXMASAMSMMMSAXXSMSMSSMSXMMSMMMSXSMSMSXMXMMMAXXMAXSAMMSSMMXSAAMMSMMSSMSSMXMXMAMAS

10
2024/4/data_test.txt Normal file
View File

@@ -0,0 +1,10 @@
MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX

169
2024/4/main.cpp Normal file
View File

@@ -0,0 +1,169 @@
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
int main()
{
const std::string filename = "data.txt";
std::ifstream ifs(filename);
if(!ifs.is_open())
{
std::cerr << "Missing " << filename << "." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::vector<std::vector<char>> game;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
// Add new row to fill out:
game.push_back({});
// for each value in the line:
for(const char &c : line)
{
// Fill out the row:
game.back().push_back(c);
}
}
// DEBUG:
// for(auto row : game)
// {
// for(auto c : row)
// std::cout << c;
// std::cout << std::endl;
// }
for(int y = 0; y < game.size(); ++y)
{
for(int x = 0; x < game[y].size(); ++x)
{
// right:
if(x + 3 < game[y].size())
{
if(game[y][x] == 'X' &&
game[y][x+1] == 'M' &&
game[y][x+2] == 'A' &&
game[y][x+3] == 'S')
++total;
}
// down right:
if(x + 3 < game[y].size() &&
y + 3 < game.size())
{
if(game[y][x] == 'X' &&
game[y+1][x+1] == 'M' &&
game[y+2][x+2] == 'A' &&
game[y+3][x+3] == 'S')
++total;
}
// down:
if(y + 3 < game.size())
{
if(game[y][x] == 'X' &&
game[y+1][x] == 'M' &&
game[y+2][x] == 'A' &&
game[y+3][x] == 'S')
++total;
}
// down left:
if(x - 3 >= 0 &&
y + 3 < game.size())
{
if(game[y][x] == 'X' &&
game[y+1][x-1] == 'M' &&
game[y+2][x-2] == 'A' &&
game[y+3][x-3] == 'S')
++total;
}
// left:
if(x - 3 >= 0)
{
if(game[y][x] == 'X' &&
game[y][x-1] == 'M' &&
game[y][x-2] == 'A' &&
game[y][x-3] == 'S')
++total;
}
// up left:
if(x - 3 >= 0 &&
y - 3 >= 0)
{
if(game[y][x] == 'X' &&
game[y-1][x-1] == 'M' &&
game[y-2][x-2] == 'A' &&
game[y-3][x-3] == 'S')
++total;
}
// up:
if(y - 3 >= 0)
{
if(game[y][x] == 'X' &&
game[y-1][x] == 'M' &&
game[y-2][x] == 'A' &&
game[y-3][x] == 'S')
++total;
}
// up right:
if(x + 3 < game[y].size() &&
y - 3 >= 0)
{
if(game[y][x] == 'X' &&
game[y-1][x+1] == 'M' &&
game[y-2][x+2] == 'A' &&
game[y-3][x+3] == 'S')
++total;
}
}
}
for(int y = 1; y < game.size() - 1; ++y)
{
for(int x = 1; x < game[y].size() - 1; ++x)
{
if(game[y][x] != 'A')
continue;
int good = 0;
// top left to bottom right
if((game[y-1][x-1] == 'M' &&
game[y+1][x+1] == 'S')
||
(game[y-1][x-1] == 'S' &&
game[y+1][x+1] == 'M'))
++good;
// top right to bottom left
if((game[y-1][x+1] == 'M' &&
game[y+1][x-1] == 'S')
||
(game[y-1][x+1] == 'S' &&
game[y+1][x-1] == 'M'))
++good;
if(good == 2)
++total_pt2;
}
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

2
2024/5/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

1387
2024/5/data.txt Normal file

File diff suppressed because it is too large Load Diff

28
2024/5/data_test.txt Normal file
View File

@@ -0,0 +1,28 @@
47|53
97|13
97|61
97|47
75|29
61|13
75|53
29|13
97|29
53|29
61|53
97|53
61|29
47|13
75|47
97|75
47|61
75|61
47|29
75|13
53|13
75,47,61,53,29
97,61,53,29,13
75,29,13
75,97,47,61,53
61,13,29
97,13,75,29,47

160
2024/5/main.cpp Normal file
View File

@@ -0,0 +1,160 @@
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>
bool IsBad(const std::vector<long> &row, const std::map<long, std::set<long>> &rules, size_t &bad_i);
int main()
{
const std::string filename = "data.txt";
std::ifstream ifs(filename);
if(!ifs.is_open())
{
std::cerr << "Missing " << filename << "." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::map<long, std::set<long>> rules;
std::vector<std::vector<long>> production;
bool reading_page_numbers = true;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
{
// one blank line is the break between reading page numbers and records.
if(reading_page_numbers)
reading_page_numbers = false;
continue;
}
std::istringstream input(line);
if(reading_page_numbers)
{
// for each value in the line:
std::vector<long> numbers;
for(std::string value; std::getline(input, value, '|'); )
{
try {
numbers.push_back(std::atoi(value.c_str()));
} catch (const std::exception &e) {
std::cout << "Error parsing rule number from " << value << std::endl;
exit(-1);
}
}
if(numbers.size() != 2)
{
std::cout << "Error: Incorrect amount of page numbers (" << numbers.size()
<< ") in rules import sequence." << std::endl;
exit(-1);
}
rules[numbers[0]].insert(numbers[1]);
}
else
{
// for each value in the line:
production.push_back({});
for(std::string value; std::getline(input, value, ','); )
{
try {
production.back().push_back(std::atoi(value.c_str()));
} catch (const std::exception &e) {
std::cout << "Error parsing production number from " << value << std::endl;
exit(-1);
}
}
}
}
// // Debug:
// std::cout << "RULES:" << std::endl;
// for(auto rule : rules)
// {
// std::cout << rule.first << " prints before ";
// for(auto page : rule.second)
// std::cout << page << ",";
// std::cout << std::endl;
// }
// std::cout << std::endl;
// std::cout << "PRODUCTION:" << std::endl;
// for(auto row : production)
// {
// for(auto num : row)
// std::cout << num << ",";
// std::cout << std::endl;
// }
// For each production run:
for(auto row : production)
{
size_t bad_idx;
auto bad = IsBad(row, rules, bad_idx);
// Part 1:
if(!bad)
total += row[row.size() / 2];
// Part 2:
else
{
std::vector<long> working;
for(auto n : row)
working.push_back(n);
while(IsBad(working, rules, bad_idx))
{
auto temp = working[bad_idx];
working.erase(working.begin() + bad_idx);
working.insert(working.begin(), temp);
// Debug Sort:
// std::cout << "Trying again: ";
// for(auto i : working)
// std::cout << i << ",";
// std::cout << std::endl;
}
total_pt2 += working[working.size() / 2];
}
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}
bool IsBad(const std::vector<long> &row, const std::map<long, std::set<long>> &rules, size_t &bad_i)
{
std::set<long> already_passed;
bool bad = false;
// For each page number in that production run:
int i = 0;
for(auto num : row)
{
// Check against all page numbers it shouldn't print after
for(auto before : rules.at(num))
{
// If found, it's a bad row!
if(std::find(already_passed.begin(), already_passed.end(), before) != already_passed.end())
{
bad = true;
bad_i = i;
break;
}
}
// Keep track of numbers we've looked at already:
already_passed.insert(num);
++i;
}
return bad;
}

2
2024/6/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

130
2024/6/data.txt Normal file
View File

@@ -0,0 +1,130 @@
.......................#....#....................#....#..##.##.........................................#...........#...........#..
.............#........................................#....................#............#.......................#............#....
.........#.............#..#....#..........................#.......#.#.......#...............................................##....
..........#....#....................................................#....................#...........#....#.......................
.............#...#....................#...........#.........#...........................#............#............................
..........................................................................................#.....#.......#...................##....
...............................................#.#......#..............#...#...................##...........#....#..#...#.........
..#.................#......#........#......................#.......#...............................#..............................
.........................#...............#.....................................#....#..#..#............................#..........
......................#.................................................................#..........#..............#...#......#....
............................#.....##..........#.....................#..........#..#.......#.......................................
......#...###...........#.................................................................#.......................................
......................#.#..#................#..........#................#...........#............#..............#...#.........#...
....#.........................#..#...............................................#....#.............#.............................
..#............#...#............#..........#...............#.....#....##.........................#........#.......................
..................#............#..............#..........................................................#..#..#........#.........
.......#...#............#..........................................................#..............................#.............#.
..#................#....................#.#...#.................................#.........#....................#.........#........
...................................#..#..........................#........#.....#.........................................#.......
...........##.................##............#................#...#..................................##...#........................
..............#..................#....................................................................#...........................
.#...#....#..........##..................................#.............................................................#......#...
......#.....#................................#...............................................................#......#.............
..........#.............................................#............................##....#.........................#............
..........#......#.................#...#........#...........#.#..........#........#....................................#..........
.#..................#.#............................#.......................#.........#.......#....................................
.....................#....#..................#..................................................##..#................#............
......#......................#..#..............##.......#..................................................#..............#.......
..........................................................................#........#...#..............#.................#.........
....................##....#.......................#........#...................#.............##.......#...........................
.........#............#..................................................................................#........................
........................................................................#................#........................#.............#.
............#.......#.................................#............#..............................................................
.#.............#...............................................#....#.........#....#..................................#.#.........
.......................................#.....................................................................................#....
........#........................................#...............#........................................................#.......
...............................#.........#........#...........#.......................................................#.........#.
.....................##...#....................................................#............#..................#..#..........##...
................#..........#...#............................................................#...##................................
...................#........#...............................#.................#.........#.........................................
.................................................................................................................#................
............................#......................................................#.....................................#......#.
......#................#............................#.............................................................................
..#...........#.....#.........#....#................#............................................#................................
..................................#.......#.......#...........#.........#................#.....................................#.#
...............................................#............................................#.#.....................#.......##....
..............................#...............#..............................#...#...#.............................#...........#..
.......#...........#..........................................................#........#..#.........#.....#.....#...#.............
......................................................#.#............#.........#.#...........#........##.....#....................
...........................................................................#..........#.........................#.........#.......
....#.........................#.....................................................................................#...#......#..
...#.......#............................................................#...............................#....................##.#.
.................................#.....#................................................................#.........................
.....................................#........................#....................................#..............................
..............#.......................................................................#.......#....................#..........#...
................................#..........................................#.................................#.....#..............
...........#.......................................................#...............#.....................#..............#......#..
..................................#..........................#.................................................................#..
.............##......#....................................................#......#...............................................#
#.......#...................#..........#...................#.................#..................................................#.
.......#..........#.....##...........#.......................#............#..............................#.............#..........
.............#...................##......................................................................................#........
#.............................#...................................................................#...............................
.#...................................#....##..................................................................................#...
.................................#.#..................#..#..#..........................#.......#..................................
..................#....#....#....................................................#....................................#........#..
..........................................#...#.....#...........#.........#............#............#..........................#..
...............................................................................#..............................................#...
.............................#......#....................#....#....................................................#.#.#..........
................##......#........#........#...........#..........................#......................#..............#..........
.....................#.....#..#.............................................................................................#.....
.......#..#...........#................................................................#..........................................
#.......................................................................................................#...#.....................
.#..........................................................#.....................................................#...............
#.....#...#...............#..#......#........#..#...................#...................#.................#.......................
..#.................................................................................#.#......................#....................
.......................#.............#..........#.......................#...................................#.....................
.................#......#......#...#.#.#.............................#.......................................................#....
..#...........................................................................................................#...................
.................................#..................#.....#........#.........................................................#....
.............#......................#...............................................#...#.............................#...#....#..
.#............................#..........................#.#...........................#..........................#.#.............
.............................#.........#.................##............................#...................#......................
.........#......#....#.........#..............................................................................................#..#
.....................#......#.................#..#..........................#..................#..............................#.#.
........................................................#......................#............#.......#......#......................
........................................#....##.#........#......#..............................#..........#..........#.##.........
.............#.......#.......#......................#..........................................#.........#............#...#...#.#.
..................#........................................................#...............................#.....#.....#..........
.........#.................#........#..............^..............#.................##......#...................................#.
....#...................#.#.................................#...#.................................................#...............
.................#.............................................#................#.....#......#.......#...................#........
...............#...............................................................................#..#...............#...............
........................................##..........................................................................##............
............................................#...................#........#...#...#....#.........#...................#.............
.....#...#...................#....................................#......#...........#...............#............................
........................#..................#.....................#.................................................#......##......
...#.................#....................#..................................#.#.........................#.......#................
....................#............#..................................#...#......#....................#...............#.............
.....#...............#.......###........#............#......................#.......#....#........................................
....................#........#...........#..................................#..#................#.............#...................
.....#..................#...................#.#..................................#.......#..#.....................................
..#..#.......#........................................#.................................................................#.........
.......#............#...#....#.......................#.#...................................#.........................#..#.#.......
..............#......................................................................................................#............
............#....................#........................#.........#...#.........................................................
...................................#..............................#.........................................................#.....
......##...........#.#........................#.........................................................................#.........
..........................#.....................................................#..............................#..............#...
.........................#...#.....................#..#................#................................................#....#....
...#.................................#...#.......#...............................................................#................
..................................#....................................#...........................##..#.#.....................#..
.#.............#.....#...............................................................#...............#...............#..#.........
.........#.............................#........................#.............#......................#........#............#......
...................................#..#...#.....................................#.................................................
........................................##..........#..............................................#.....................#........
......#...........................................#....#.....................#...................#..#.........#...................
.#....#.....#........##..................................#......#................................................#....#..##.......
..........#....................................................................##.........................#...........#...........
...........#.#......#.......#..................#............#...............................................#...#..............#..
.................................................................#.......#.........#.....#........#....##....#..........#.........
.............................#......................................................#.....#...#...#....#...........#..........#.#.
.....................#........#.........................#......................................#................#...............#.
.........................................................................#...................................................#....
..............#...#..#................#....................................#.......#....#.#...............#.........#.............
.......#......#.#............................................#.......#............................................................
##......................................................#..#.................................##...................#..#...........#
...........#.#...#........#............#..............................#........................#.........................#..#.....
................................................##.........................................#.................#....................
............................#....................................................#...#........................#.#......#........#.

10
2024/6/data_test.txt Normal file
View File

@@ -0,0 +1,10 @@
....#.....
.........#
..........
..#.......
.......#..
..........
.#..^.....
........#.
#.........
......#...

277
2024/6/main.cpp Normal file
View File

@@ -0,0 +1,277 @@
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <unistd.h>
#include <vector>
enum Direction {
UP = 0,
RIGHT,
DOWN,
LEFT
};
struct Position {
// NOTE(dev): Could do enum empty/reached/blocked, but I'm not interested.
bool blocked = false;
std::map<Direction, bool> reached;
bool Reached() const {
return reached.size();
}
char ReachedChar() const {
bool up_or_down = false;
bool left_or_right = false;
if(reached.contains(Direction::UP) || reached.contains(Direction::DOWN))
up_or_down = true;
if(reached.contains(Direction::LEFT) || reached.contains(Direction::RIGHT))
left_or_right = true;
if(up_or_down != left_or_right)
{
if(up_or_down)
return '|';
else
return '-';
}
else if(up_or_down)
return '+';
else
return ' ';
};
};
struct Player {
std::pair<int, int> location;
Direction direction = Direction::UP;
};
int main()
{
const std::string filename = "data_test.txt";
std::ifstream ifs(filename);
if(!ifs.is_open())
{
std::cerr << "Missing " << filename << "." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::map<std::pair<int, int>, Position> level;
Player player;
int max_x = 0;
int max_y = 0;
bool first_row = true;
int y = 0;
auto DebugPrint = [&]()
{
std::cout << std::endl;
for(auto y = 0; y < max_y; ++y)
{
for(auto x = 0; x < max_x; ++x)
{
if(player.location.first == x && player.location.second == y)
{
switch(player.direction)
{
case Direction::UP:
std::cout << "^";
break;
case Direction::RIGHT:
std::cout << ">";
break;
case Direction::DOWN:
std::cout << "v";
break;
case Direction::LEFT:
std::cout << "<";
break;
};
}
else
{
const auto &pos = level[{x, y}];
if(pos.Reached())
std::cout << pos.ReachedChar();
else if(pos.blocked)
std::cout << "#";
else
std::cout << ".";
}
}
std::cout << std::endl;
}
std::cout << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
};
// Parse Input
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
int x = 0;
for(const char &value : line)
{
Position pos;
if(value == '#')
pos.blocked = true;
if(value == '^') // always up?
{
pos.reached[Direction::UP] = true;
player.location = {x, y};
}
level[{x, y}] = pos;
++x;
}
if(first_row)
{
max_x = x;
first_row = false;
}
++y;
}
max_y = y;
// DEBUG:
DebugPrint();
std::cout << std::endl;
while(true)
{
std::pair<int, int> next_location = player.location;
switch(player.direction)
{
case Direction::UP:
--next_location.second;
break;
case Direction::RIGHT:
++next_location.first;
break;
case Direction::DOWN:
++next_location.second;
break;
case Direction::LEFT:
--next_location.first;
break;
};
if(!level.contains(next_location))
{
player.location = next_location;
break;
}
if(level[next_location].blocked)
{
// NOTE(dev): Also check if the next potential position is the last space before a turn,
// as then the up/down or left/right flag wouldn't be set, but the
// left/right or up/down flag would be.
level[player.location].reached[player.direction] = true;
player.direction = static_cast<Direction>(((int(player.direction)) + 1) % 4);
level[player.location].reached[player.direction] = true;
}
else
{
// TODO(dev): Need to handle the scenario where you've yet to explore a section but it
// would result in a loop.
// e.g.: Placing a stopping point at the O
//
// # #
// +->O #
// #| #
// S # #
// # #
// # #
//
// IDEA: Follow turns when exploring a direction like that. Snake your way until
// you fall off the map or you line up with a square you've been in before
std::map<Direction, bool> could_loop;
// Part 2: If you could loop in this next position, COUNT IT
if(player.direction == Direction::DOWN)
{
// search left of new position to see if you've been in this horizontal bit:
for(int x = next_location.first; x >= 0; --x)
{
std::pair<int,int> potential_position = { x, next_location.second };
if(level[potential_position].reached.contains(Direction::LEFT))
{
could_loop[Direction::LEFT] = true;
break;
}
}
}
else if(player.direction == Direction::UP)
{
// search right of new position to see if you've been in this horizontal bit:
for(int x = next_location.first; x < max_x; ++x)
{
std::pair<int,int> potential_position = { x, next_location.second };
if(level[potential_position].reached.contains(Direction::RIGHT))
{
could_loop[Direction::RIGHT] = true;
break;
}
}
}
else if(player.direction == Direction::LEFT)
{
// search left of new position to see if you've been in this horizontal bit:
for(int y = next_location.second; y >= 0; --y)
{
std::pair<int,int> potential_position = { next_location.first, y };
if(level[potential_position].reached.contains(Direction::UP))
{
could_loop[Direction::UP] = true;
break;
}
}
}
else
{
// search left of new position to see if you've been in this horizontal bit:
for(int y = next_location.second; y < max_y; ++y)
{
std::pair<int,int> potential_position = { next_location.first, y };
if(level[potential_position].reached.contains(Direction::DOWN))
{
could_loop[Direction::DOWN] = true;
break;
}
}
}
total_pt2 += could_loop.size();
level[next_location].reached[player.direction] = true;
player.location = next_location;
DebugPrint();
usleep(500000);
}
}
DebugPrint();
for(auto y = 0; y < max_y; ++y)
for(auto x = 0; x < max_x; ++x)
if(level[{x,y}].Reached())
++total;
std::cout << std::endl;
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}

2
2024/7/Makefile Normal file
View File

@@ -0,0 +1,2 @@
a.out: main.cpp
clang++ -std=c++2b -g -O0 main.cpp

9
2024/7/data_test.txt Normal file
View File

@@ -0,0 +1,9 @@
190: 10 19
3267: 81 40 27
83: 17 5
156: 15 6
7290: 6 8 6 15
161011: 16 10 13
192: 17 8 14
21037: 9 7 18 13
292: 11 6 16 20

49
2024/7/main.cpp Normal file
View File

@@ -0,0 +1,49 @@
#include <fstream>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
int main()
{
std::ifstream ifs("data_test.txt");
if(!ifs.is_open())
{
std::cerr << "Missing data.txt." << std::endl;
return -1;
}
unsigned long total = 0;
unsigned long total_pt2 = 0;
std::vector<std::vector<long>> cals;
for(std::string line; std::getline(ifs, line); )
{
if(line == "")
continue;
cals.push_back({});
std::istringstream input(line);
// for each value in the line:
std::vector<long> nums;
for(std::string value; std::getline(input, value, ' '); )
cals.back().push_back(std::atoi(value.c_str()));
}
for(auto cal : cals)
{
for(auto num : cal)
{
std::cout << num << " ";
}
std::cout << std::endl;
}
std::cout << " Total: " << total << std::endl;
std::cout << "PT2 Total: " << total_pt2 << std::endl;
return 0;
}