Compare commits
29 Commits
641a176c77
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 0cb627b873 | |||
| d7ee7bdf6c | |||
| 6f37408485 | |||
| 5704c6bd8d | |||
| d9ae111b2c | |||
| 16c6f4bcc3 | |||
| 6b02bdfb80 | |||
| 10bd7c4997 | |||
| dfe8f1dfe8 | |||
| c56fcff09c | |||
| e197a5c546 | |||
| 56c99bc5a9 | |||
| ad92e950a9 | |||
| daf0ca92e4 | |||
| d0b6ebc6f5 | |||
| d61d4c9324 | |||
| 6983ebdf26 | |||
| 8e0fe281e2 | |||
| 0f24617da4 | |||
| 9dea01af07 | |||
| 6a7cfae109 | |||
| cff618714a | |||
| f4cc030adb | |||
| 50f57ef13d | |||
| 507c35c813 | |||
| c69470afa5 | |||
| 15dc98a4bd | |||
| d76692ba8d | |||
| 9f900b1f52 |
8
december_10/Cargo.toml
Normal file
8
december_10/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december-10"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
10
december_10/example.txt
Normal file
10
december_10/example.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
[({(<(())[]>[[{[]{<()<>>
|
||||
[(()[<>])]({[<{<<[]>>(
|
||||
{([(<{}[<>[]}>{[]{[(<()>
|
||||
(((({<>}<{<{<>}{[]{[]{}
|
||||
[[<[([]))<([[{}[[()]]]
|
||||
[{[{({}]{}}([{[{{{}}([]
|
||||
{<[[]]>}<{[{[{[]{()[[[]
|
||||
[<(<(<(<{}))><([]([]()
|
||||
<{([([[(<>()){}]>(<<{{
|
||||
<{([{{}}[<[[[<>{}]]]>[]]
|
||||
94
december_10/input.txt
Normal file
94
december_10/input.txt
Normal file
@@ -0,0 +1,94 @@
|
||||
<[<<({{<{<[[([()][()()])<{[]<>}{<>}>><<<[]{}>>{<<><>>({}{})}>][<<<{}<>>([])>{<{}><()>}>]><(<{(()[]){[](
|
||||
<{([({{[(<[({({}{})[()<>]}{{<>{}}[(){}]})]>({(<<<><>>{{}()}>)<<<[]><{}<>>><[{}[]]<<>[]>>>}))[{(<{([]
|
||||
([<([({(<([<({()()}(<>[]))[<[]()>{<>{}}]>]<{{{{}{}}{()()})({[]}[<>{}])}>)>)}){<<{{(<<<()<>><<><>>>
|
||||
[{{[<<[{([[{{[<>{}]<()<>>}[(()<>)[{}<>]]}<<[{}[]]([]<>)>{{[]{}}{()()}}>]][[{<({}{})<[]{}>>
|
||||
<<{{<([(((([{<[]<>>{()<>}}(<<>[]>{(){}})]([{{}<>}<[]>](<[][]><{}()>)))))[({{{<[]{}>[()]}<<<><>>
|
||||
<(<[{(<[{{{<{[[]<>]{<>()}}><[[{}()][(){}]]>}}<[<[<()()>({}<>)]><[{[]()}([][])](<(){}>[<><>])>]{
|
||||
{[[<{{<<[[<<(({}<>){<><>})[[<>()][[]{})]>[[[{}[]]<<>>]{(<>[])}]>{{<<()[]>{<>{}}>[{[]<>}<[]{}>]
|
||||
({[((((([{[({[{}[]]<[]()>}[({}{})<<>[]>])<[(()[])<{}()>]{[[]<>]{[]()})>](([({}<>)(()[])][<[]{}>])
|
||||
{[[{[({(<<{<([{}<>])<({}<>)({}<>}>>[<[{}()]([]<>)>((<>())<[]{}>)]}<([(<>())[(){}]]{[{}<>]<[][]>}){<{<><
|
||||
(<{<<[<<([[([<<><>>]<<{}()><[]<>>>)]][{(({<>{}}(()())))(<[()()]<[]()>>)}[[<<<>()><<>{}>>([{}<>][{}[]])]{<{(
|
||||
<<[({{{{{[<([((){})([]())]<((){})({}[])>)[{[{}()]{[]<>}}]>([<{{}<>}><({}<>)({}[])>]<[{<>{}}
|
||||
(([[{{({{{[<<{[]()}({})>{{{}()}[[]<>]}>{<([])>[[[]{}]]}](([<[]{}>]<<[]<>><{}[]>>))}}}(([[[{[<><>
|
||||
<<[(<[{{<((<[<()>[<><>]][[<><>]([]())]>[({<>})<<()<>><{}[]>>])[[(<[]<>>([]())){{<>[]}(()())}]]){(<(<[]<>>
|
||||
({[<<[[{<[[{{[()()]{()[]}}}]<{([{}{}]{[]()})[[()[]]<<>>]}>]>}[({((<{<><>)>{{[]()}{{}[]}}){([{}[]]<{}{}>)<
|
||||
([{{<{[(<[<<[({}())({}())]>>[{[<<>[]>[<>()]]<(<>[]){()[]}>}(<<<>[]>[<>[]]>{<<>[]>{{}()}})]]{
|
||||
<[{{<[((<([[{<<><>>{()}}{<{}[]><[]()]}]])<{({<()>{()[]}}(<(){}><[]<>>)){[({}[]){<>[]}]}}<<([()()]<()(
|
||||
<{<{[(({(({({<[]>([])}<<()<>>{<>()}>){[[()[]]<{}()>]{({}[])[()<>]}}}<[<<{}()><[]{}>>({[][]}[()<>])}{<<[]
|
||||
<[{{[<({(<[<[[()<>]({}[])]([{}[]]([]))>]{[{{<>[]}[[]{}]}(({}<>)<()[]>)]<<[()[]]>({(){}}<{}()>)>}>)}<<[[[[<<>(
|
||||
{{<(<[((({(<[<[]{}>[(){}]](<{}<>>((){}))>){(({[]{}}<{}[]>){{<><>}[[]{}]}))}<([<(<>)>[<<>{}>[{}
|
||||
<([({[<[(({[(({}))(<{}()><<>{}>)]<[{{}[]}{{}<>}]{[{}()]{{}()}}>})([[<(<>())({}{})>[<[]<>>[
|
||||
{((<<<{<(<[[[<{}<>}]<(<><>)>]]<(([(){}]{[]()}))<({{}<>}<()<>>){<()<>>{(){}}}>>>{({({()[]}[<>
|
||||
([<[[((<(<[<([{}[]])>{<(()<>)((){})>{<<>>(()<>)}}][{[(<>[])(<>[])]}[[{{}[]}[()()]]<<[]<>>{(){}}>]]><({(
|
||||
[{<([[[{([{<<([]<>){<><>}>[<(){}>]><{[<>[]](()<>)}[{()()}]>}<({{{}{}}}{[{}{}]<<>()>})<(<[]<
|
||||
(<({[{{[[(<[<(<>[])[[][]]>]{((<>[])({}<>))({[]<>})}>({<[()[]]]<{()[]}>})){(<(<<>[]>[<>{}])>{[({}<
|
||||
(<{<(({[(({[[<<>{}>({}<>)]{({}{}){(){}}}]{(<(){}>[[][]])<{()<>}>}}[[[{[]{}}[()]]](([[]()][(){}]))])
|
||||
([({<{[{<[{<({{}()}{{}()})>}]>}<<[[{{((){})<<>{}>}(({}[]){<>[]})}]]><[{{<({}<>)(()())>[{<>()}{{}()}]}{<{
|
||||
<[{[({[<<[[<<{{}{}}<{}{}>>([<>][(){}])><<<{}{}>>>]]{([{[[]()][[][]]}<{[]<>}>]<<[<>[]][[]()]><<()[
|
||||
[{({{{<<{[{([[()]({}[])]{[()()]})(((<>{})[[][]])<{{}{}}>)}]}>>}[((({{<([[]()][[]])}}{{<({}[])[{}
|
||||
{[({<{<<{[(([<<>[]>({}{})>))]{(<{{{}<>}<<>{}>}>)}}><(<(({([]())(<>[])}{{[]()}{[][]}})<{(()[])[<>{}]}>){({
|
||||
[<((<[<<(<<{<(<>)<[]{}>>[<[]{}><[]()>]}<((()[])((){}))[({}[]){[]{}}]>>([<[{}()][[]{}]>{{()[]}}][{[{}<>]<[]<
|
||||
[<[({({[([{<(([]<>)({}[]))<{{}[]}[<>[]]>><[<{}[]>({}<>)]<(())>>]]([[[{[]<>}({}[])](<[]{}>{<>()
|
||||
{[<<{(<[{(<[({[]{}}{[]{}}}]({<()[]><<>[]>}{<[]()>[{}{}]})>)}{[{(((<><>))(<[]<>>(()[])))[[<[]()>[{}()]](((
|
||||
({[<<([[{(<<<{<>()}<{}<>>>[[[]{}){()}]><[[(){}]<[]<>>]({(){}}[[]{}])>>{[{[()<>][{}()]}][[[{}{}]<<>()
|
||||
([(<((<{[[[[[{{}()}{()[]}]]<([[]<>])<[()<>][[][]]>>]][{([{()[]}(()[])]({<>{}}{[]()}))}({([[]
|
||||
(({{[<<{(([{<{()()}[[]()]>{<()<>>[[]{}]}}{[<()()>[[]{}]]{([]())({}[])}}][(<{<>[]}[()()]><<()>(()())>)
|
||||
[<(<{{{<{(<{(<<>[]><<>()>){<{}()><()<>>}}(<[<>{}]{<>{}}><[{}{}][<>()]>)>)}{{{(<(<><>)(<>())><{[]}([][
|
||||
<<<{([[<[[[(([[]{}])<({}())(<>())>)({[<>{}]{[]()}}<<(){}>{(){}}>)]{([(()()>({}[])]((<><>)<
|
||||
{{({<<<[[<(<{{{}<>}({}[])}{<{}<>><<>()>}>{({{}<>}({}()}){[[]<>]([]{})}}){{[[[][]](()())]}([<<>{}
|
||||
<<[[<{{({<{[{<<>()><()()>}<[()<>]<()()>>]{(([]<>)[{}[]]){{{}<>}{[]<>})}}>{{<[<{}<>>({}())]
|
||||
({[<[[{<<{{[{(<>{})}]{<[{}{}][[]()]>[[[]{}][()()]]}}[(<<{}[]>{<>[]}>{{{}<>}[(){}]}){{[<>{}]<{}{}>}{
|
||||
(([<{<[[([[(((()<>))({{}[]}<()<>>))[[({}[])(())]<{(){})>]][{((()){[]()}){{()<>}{<><>}}}[{{()}{()[]}}]]]){{(({
|
||||
{<[{(<[{[{{[<([]<>)<{}<>>>]}}]}]><{{<[[([{<>()}[[]{}]]({{}()}{<>{}}))]{([<[]{}>(()<>)]<[[]<>]([])
|
||||
{[<<[<(<[{<<[{{}()}{<>{}}](<{}<>>({}<>))>><{<({}[])<()<>>>[[<>[]][<><>]]}[<(<><>){{}<>}>[<[]()>{[]}]]>}]{[<{<
|
||||
(<({{[{<(<<<{[{}<>]({}[])}{[[]{}]<()[]>}>(<[[]()][()()]><[()[]][<>()]>)>>[(<<<{}()>{<><>}>>){<<{<><>}(
|
||||
(<{[[{{<(<(<({{}<>}{{}()}){[()<>]<{}[]>}>[(<{}{}><[]()>)<({}<>){()()}>]){[[([]{}){{}[]}]<[{}{}]<[][]>>][{<()
|
||||
[(<([({[[[<[[[[][]][{}{}]]([{}()]{<>{}})]{<{()()}<()<>>><{{}<>}<(){}>>}>]{{[([[][]]<()()>)
|
||||
(<(<<({{(<[{{[()<>][<>{}]}[<[]<>>]}<<{[]{}}>[[{}()]{()()}]>]{[([()()]<<>>)({()<>}[<>[]])][{{[][]}(<>())}
|
||||
[[((({(({{{[{{<>[]}[<>{}]}[[{}<>]([]())]][{(<><>)}]}][(<{{[][]}(<><>)}<[[]()]>>([[{}()]<[]<>>][<[][]>[()()]])
|
||||
<{({(([((<[<{(()[])<[][]>}{<<><>><[]<>>}><<([]<>)([]<>)>>]{[<([]{}]{<>{}}>]}>[{[(([]{})[{}{}])[<<>{}
|
||||
{(([<{(({<({{{{}{}}}[[[]]{[]()}]}{<[[]]<<>()>>(<()>[()<>])})>{{[(([]<>){{}()}){[{}]{{}<>}}]}([[([]{})]<[[](
|
||||
<{[({<{[[[{{{[{}{}]}}([<[][]>[<>[]}][<<>()>{()}])}((<({}[])[<><>]>(((){})[{}()]))[[<{}[]>[(
|
||||
{<[([(<((<<<<[{}[]]({}{})>((()())[(){}])><([[]{}][()<>])<<<>[]>([]<>)>>><[[((){}){[][]}}{[[]]
|
||||
[{(<{<{<<({({(()<>){{}[]}}([[]()]{()<>}))(([[]<>](())))}<{({()[]}{[][]})}])>>}>(({[{[{{([]())(<><>)
|
||||
<[[<([<<({[[(<[]()><<><>>)({<>})]{{<<><>>[()[]]}([()<>](()[]))}]((<{<>{}}<(){}>>))}<<[(<(){}><<>{}>)[[()[
|
||||
<[{<<<{[{<{(<[<>{}][{}()]>((<>[])[<><>]))<[({}<>)<<>[]>]<(<><>)(<>{})>>}({<<[][]>([]<>)>([<>{}><<>[]>
|
||||
[<<(<{((<([<({{}{}](<>[]))[[()<>]([][])]>((([])<(){}>))]){<{{<()[]>(()<>)}(<[]<>>([][]))}><[([(
|
||||
{[[[{{<[[{<[<<<>[]>{<><>}>{<<>{}><[]<>>}]((<{}()>(<>[])))><<{<<>{}>{(){}}}([{}{}]<<>()>)><[{<>{}}]>>}]
|
||||
((((([[(([{<({()[]}<()<>>)><<<<>()>({}{})>{{(){}}(<>[])}>}<<<{<><>}>><(((){})<[]()>){{()()}({}<>)}>
|
||||
<<[<[{<[<[<{[[()[]]({}[])]{<{}<>>[{}{}]}}[([[][]])[([]())[[]<>]]]>[(<<{}()>(()<>)>{{[]{}}<{}{}>})({([
|
||||
[{<(<{(<[<[[[{()<>}[[][]]][(()<>){{}[]}]](<{<>{}}[()[]]>(<[]>[{}()]))]([([<>{}]<()[]>){{<>{}}{()
|
||||
<[<({<({[{({{(<>{}){[]()}}<{[]<>}[(){}]>}({[<>[]]{[]<>}}))<{([{}[]])(({}[]){(){}})}[{[[]<>]}[({}())[(){}]]]
|
||||
[[[{<[((<[<{([[]<>]{<><>})<<{}[]>[[][]]>}{[[<>{}]]<<{}>([]<>)>}>{<{{<>[]}}[(<><>)[[]<>]])<{[(){}]<()()>}>}]{{
|
||||
([(<({[[{<([{{<>{}}([]<>)}[[{}[]]{<>{}}]](<[{}<>]{[]()}><((){})[[][])>)){({{{}{}}{{}{}}}[<{}{}>({}<
|
||||
<[{(((({[[{{({{}[]]<<>>)<{[]()}<()<>>>}((<(){}>([]{})))}{({[()()]([]<>)}<([]<>)[()()]>)<[{{}[
|
||||
<[({[<<<<{[({{(){}}[{}<>}}(<<>[]>[[]()])){(<()[]><<>()>)}]}><({<[{()()}]({[]{}}<{}>)>[({[]
|
||||
<<([[<{{([{<{([]{})[(){}]}{([]{})<{}[]>}><<(<>{})[<>()]>({{}<>})>}<[(<<>()><{}()>)<{()<>}<<>>
|
||||
<[[[({[({<[{((<>[]]<{}<>>){<<>()>{[]()}}}<{<{}{}>[<>{}]}{{{}[]}{{}()}}>]{<{{()()}<[]<>>}((
|
||||
[[({(([[(([<[([]<>){{}()}]>(<{{}{}}(()<>)>[{<><>}{{}<>}])]{{<[[]<>]>[[{}()]]}([<{}()>][([]{})<{}
|
||||
<(([<{([[<[((([]<>)<<><>>){[[]()]({}{})})({{(){}}((){}]}({{}()}))]([<{<>()}<[]{}>><{[]{}}<(){}>>])>
|
||||
<<[[{<<{[(<<{{[][]}[[]<>]}<<[][]><<>[]>]>([{<>}[<>[]]]{{[]()}<{}()>})>{({({}<>){[]<>}}[{<>{}}[<>[]]
|
||||
((<<<<[[(({[[<()<>>[(){}]]{(<>()){<>{}}}]}{(([<>[]><<>()>)<<(){}><()()>>)[(<{}{}>((){}))[{[][]}(()<>)]]})){
|
||||
[({(<{{<<<{<[{[]()}<<><>>][[()[]][<>[]]]>}>([([<[]<>>]{<<>()><()<>>})({<{}[]><()()>}[[[]()]])]<{<(()
|
||||
([(<({[([{{{((()())[<>[]]){{[]<>}[{}{}]}}([{()<>}<{}()>])}}<{[({(){}}(<><>)}<(<>())>][<[(){}]{(){}}
|
||||
{[[{((((([[{{[[]{}]({}{})}{[[]<>](()[])}}[{[()()]}((<>{})<(){}>)]]{(<{<>()}<(){}>>){(<{}()>{{}<>})({<>(
|
||||
([[{<[<[[<<{<{()<>}[<>()]>[[[]{}]{{}{}}]}<[{{}[]}]>>{<{{<>{}}([]())}>[(<<>()>)(<{}()>[<>()])]}>{({<[()<>]
|
||||
{(([{[{{(({(<[()[]][<>[]]>)<[(()<>){{}{}}]>}[(<<{}{}><{}<>>>){<[()()]<()()>>({[][]}<<><>>)}
|
||||
<[{<(<<[{[({[({}<>)<<>[]>](<<>()>(<><>))})[([{<><>}<()()>])]]}]><<[<({{{<>}}<([]][<>{}]>}[<(())<<><>>>])
|
||||
(<(({<[[{{[<[{<>[]}[()<>])((()()){{}[]})>]}}]]((<<<((({}{})<{}>){{{}<>}{<>}})[({{}()}{<>()}){{{}()}}]
|
||||
{[<[{(([<[{{[([]{})<[][]>]{([][])[()<>]}}<<(()<>)>>}[[(({}{}){{}<>})]]]{{[(<{}{}>[{}()])({()()}
|
||||
[{{((<<[[((<<{[]<>}<{}>>(<{}<>>{[]()})>({<()>([][])><[{}{}]{{}()}>))(({([]<>)([]())}<{[][]}<()>>)
|
||||
({([{({[({[<({{}{}}([]()))(((){}){{}{}}>>({(()()){{}()}})]<[[{{}{}}<{}[]>]{<[][]><<>[]>}]({<<>[]>
|
||||
{[({[{{[<[{([<{}{}>[(){}]](<{}<>>{{}()}))([([]()){()[]}]([{}<>]{<>{}}))}]>[{{[[{[][]}]]<((()[])([]{}))<[()
|
||||
[[(({{{(([[[{[()()]([]())}((<>){{}{}])]]({<[<>]({}{})>([<>{}]{{}{}})})]))}[(<[[(([[][]]{<>{}}){{(){}}})
|
||||
<(<({<{<[<(<{<()><<><>>}<<{}[]>([]<>)>>)<{<{[]{}}[{}()]>}([(()[]){[]<>}]{{<>()}{{}<>}})>}{[[{(()[]){(
|
||||
[(<(<([{<[{<(<()>([]<>))[{()()}<{}<>>]><{([]())<<>()>}(<{}{}>[()[]])>}]<{<({[][]}<[]()>){{{}[
|
||||
[<({<{(<<[[[<{()[]}{{}[]}>{[<><>]}]{[<()<>>({}<>)]}]][[{<[<>[]>([]())><{()()}{[]{}}>}([({}{})[[](
|
||||
<<[[{{<<([[{[(()())[()]][[{}[]]{{}}]}[[({}<>){[]{}}]{{<><>}[()[]]}]]{<[(<>())]>{({{}()}(()<>))}}])
|
||||
{<[{({[({{<({[{}()]([][])}([{}<>]{[]()}))[<(<><>)([]{})><{()()}(<>[])>]>{{(<[]<>>[{}])}[<{(){}}(<>
|
||||
<{{(({([[<[{<(<>)([]{})>{<<>{}>{(){}}}}]{[<([]{})<{}{}>>[[<>{}]{()<>}]][{{<><>}([]())}({()<>}<()>)]}>]
|
||||
{<{[{[({[(({<[{}()]({}[]}>[<()>]}{(<<>>)}))]})]{<{<{[[{(<>())[()[]]}[[{}{}][[]]]][([[]()]<{}<>>)[<[]{}>([]<>
|
||||
((<{{<[[<{{([([]{})<<>()>]<(<>{})(()<>)))([{()()}(<><>)]<(<>)(<>{})>)}([<{(){}}<<>{}>>]<[([]<
|
||||
[<<<{(((<<{([<()[]>({})]({<>()}(()())))({([])<<>>}((()[])[()[]]))}{<[<{}()>]<[{}{}]({}<>)>>{<<
|
||||
[[[<<<<[{(<<[{{}[]}]<(<><>)(<>[])>><<<<><>][[][]]>(([]{}))>>([<[[]<>]<[]<>>><{()<>}([][])>]))}<(
|
||||
<<{[[[{{{{[[(([]{}))([<>[]]<()>)][{(<>()){[]()}})]{(({<><>}{<>[]})[<<>[]>[()()]])}}}<{(<((<><>)(<>{}))<{
|
||||
122
december_10/src/main.rs
Normal file
122
december_10/src/main.rs
Normal file
@@ -0,0 +1,122 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut line_vec: Vec<Vec<char>> = Vec::new();
|
||||
|
||||
for line in reader.lines(){
|
||||
let line_as_string = line.unwrap();
|
||||
let line_as_char_vec = line_as_string.chars().collect::<Vec<char>>();
|
||||
line_vec.push(line_as_char_vec);
|
||||
}
|
||||
|
||||
let mut round_depth: u32 = 0;
|
||||
let mut square_depth: u32 = 0;
|
||||
let mut curly_depth: u32 = 0;
|
||||
let mut pointy_depth: u32 = 0;
|
||||
let mut current_opened: Vec<char> = Vec::new();
|
||||
let mut corrput: bool = false;
|
||||
let mut error_scores_2: Vec<u64> = Vec::new();
|
||||
|
||||
let mut illegal_chars: Vec<char> = Vec::new();
|
||||
|
||||
for (index, line) in line_vec.iter().enumerate() {
|
||||
current_opened = Vec::new();
|
||||
for symbol in line {
|
||||
match symbol {
|
||||
'(' => {round_depth += 1; current_opened.push('(');},
|
||||
'[' => {square_depth += 1; current_opened.push('[');},
|
||||
'{' => {curly_depth += 1; current_opened .push('{');},
|
||||
'<' => {pointy_depth += 1; current_opened.push('<');},
|
||||
')' => {
|
||||
if round_depth > 0 && current_opened[current_opened.len()-1] == '(' {
|
||||
round_depth -= 1;
|
||||
current_opened.pop();
|
||||
} else {
|
||||
corrput = true;
|
||||
illegal_chars.push(symbol.to_owned());
|
||||
break;
|
||||
}
|
||||
},
|
||||
']' => {
|
||||
if square_depth > 0 && current_opened[current_opened.len()-1] == '[' {
|
||||
square_depth -= 1; current_opened.pop();
|
||||
} else {
|
||||
corrput = true;
|
||||
illegal_chars.push(symbol.to_owned());
|
||||
break;
|
||||
}
|
||||
},
|
||||
'}' => {
|
||||
if curly_depth > 0 && current_opened[current_opened.len()-1] == '{' {
|
||||
curly_depth -= 1;
|
||||
current_opened.pop();
|
||||
} else {
|
||||
corrput = true;
|
||||
illegal_chars.push(symbol.to_owned());
|
||||
break;
|
||||
}
|
||||
},
|
||||
'>' => {
|
||||
if pointy_depth > 0 && current_opened[current_opened.len()-1] == '<' {
|
||||
pointy_depth -= 1;
|
||||
current_opened.pop();
|
||||
} else {
|
||||
corrput = true; illegal_chars.push(symbol.to_owned());
|
||||
break;
|
||||
}
|
||||
},
|
||||
_ => println!("No")
|
||||
}
|
||||
}
|
||||
if corrput {corrput = false}
|
||||
else if round_depth == 0 && square_depth == 0 && curly_depth == 0 && pointy_depth == 0 {
|
||||
|
||||
} else {
|
||||
round_depth = 0;
|
||||
square_depth = 0;
|
||||
curly_depth = 0;
|
||||
pointy_depth = 0;
|
||||
|
||||
let mut score: u64 = 0;
|
||||
for i in 0..current_opened.len() {
|
||||
|
||||
let symbol = current_opened[current_opened.len()-1 - i];
|
||||
score = score * 5;
|
||||
match symbol {
|
||||
'(' => score += 1,
|
||||
'[' => score += 2,
|
||||
'{' => score += 3,
|
||||
'<' => score += 4,
|
||||
_ => println!("ERROR")
|
||||
}
|
||||
}
|
||||
error_scores_2.push(score);
|
||||
score = 0;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
let mut error_score: u32 = 0;
|
||||
for symbol in illegal_chars {
|
||||
match symbol {
|
||||
')' => error_score += 3,
|
||||
']' => error_score += 57,
|
||||
'}' => error_score += 1197,
|
||||
'>' => error_score += 25137,
|
||||
_ => println!("ERROR")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
println!("Error score: {}", error_score);
|
||||
error_scores_2.sort();
|
||||
println!("Error scores 2: {}", error_scores_2[(error_scores_2.len()-1) /2 ] );
|
||||
|
||||
}
|
||||
8
december_11/Cargo.toml
Normal file
8
december_11/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_11"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
10
december_11/example.txt
Normal file
10
december_11/example.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
5483143223
|
||||
2745854711
|
||||
5264556173
|
||||
6141336146
|
||||
6357385478
|
||||
4167524645
|
||||
2176841721
|
||||
6882881134
|
||||
4846848554
|
||||
5283751526
|
||||
10
december_11/input.txt
Normal file
10
december_11/input.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
6318185732
|
||||
1122687135
|
||||
5173237676
|
||||
8754362612
|
||||
5718474666
|
||||
8443654137
|
||||
1247634346
|
||||
1446514585
|
||||
6717288267
|
||||
1727871228
|
||||
92
december_11/src/main.rs
Normal file
92
december_11/src/main.rs
Normal file
@@ -0,0 +1,92 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
|
||||
const RADIX: u32 = 10;
|
||||
|
||||
static mut LINE_VEC: Vec<Vec<u32>> = Vec::new();
|
||||
static mut TOTAL_FLASHES: u32 = 0;
|
||||
|
||||
const STEPS: u32 = 300;
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
|
||||
|
||||
for line in reader.lines(){
|
||||
let line_as_string = line.unwrap();
|
||||
let line_as_int_vec = line_as_string.chars().map(|x| x.to_digit(RADIX).unwrap()).collect::<Vec<u32>>();
|
||||
unsafe{LINE_VEC.push(line_as_int_vec);}
|
||||
|
||||
}
|
||||
unsafe {
|
||||
let height = LINE_VEC.len();
|
||||
let width = LINE_VEC[0].len();
|
||||
|
||||
|
||||
for _i in 1..=STEPS {
|
||||
// Energy of each Octopus increases by 1
|
||||
for line_nr in 0..height {
|
||||
for column_nr in 0..width {
|
||||
LINE_VEC[line_nr][column_nr] += 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Flash all Octopus over 9 and reset to 9
|
||||
for line_nr in 0..height {
|
||||
for column_nr in 0..width {
|
||||
if LINE_VEC[line_nr][column_nr] > 9 {
|
||||
flash(line_nr, column_nr, height, width);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Reset all flashed to 0
|
||||
for line_nr in 0..height {
|
||||
for column_nr in 0..width {
|
||||
if LINE_VEC[line_nr][column_nr] >98 {
|
||||
LINE_VEC[line_nr][column_nr] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Check if all flash
|
||||
let mut all_flashed = true;
|
||||
for line_nr in 0..height {
|
||||
for column_nr in 0..width {
|
||||
if LINE_VEC[line_nr][column_nr] != 0 {
|
||||
all_flashed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if all_flashed {println!("All Flashed at step {}", _i);}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unsafe { println!("Total flashes: {}", TOTAL_FLASHES); }
|
||||
}
|
||||
|
||||
|
||||
fn flash(line_nr: usize, column_nr: usize, height: usize, width: usize) {
|
||||
unsafe {
|
||||
//Set Current Octopus to 0
|
||||
if LINE_VEC[line_nr][column_nr] == 10 || LINE_VEC[line_nr][column_nr] == 9 {
|
||||
LINE_VEC[line_nr][column_nr] = 99;
|
||||
TOTAL_FLASHES += 1;
|
||||
|
||||
if line_nr > 0 && column_nr > 0 {flash(line_nr - 1, column_nr - 1, height, width);}
|
||||
if line_nr > 0 {flash(line_nr - 1, column_nr, height, width);}
|
||||
if line_nr > 0 && column_nr < width - 1 {flash(line_nr - 1, column_nr + 1, height, width);}
|
||||
|
||||
if column_nr > 0 {flash(line_nr, column_nr - 1, height, width);}
|
||||
if column_nr < width - 1 {flash(line_nr , column_nr + 1, height, width);}
|
||||
|
||||
if line_nr < height - 1 && column_nr > 0 {flash(line_nr + 1, column_nr - 1, height, width);}
|
||||
if line_nr < height - 1 {flash(line_nr + 1, column_nr, height, width);}
|
||||
if line_nr < height - 1 && column_nr < width - 1 {flash(line_nr + 1, column_nr + 1, height, width);}
|
||||
} else {
|
||||
LINE_VEC[line_nr][column_nr] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
8
december_12/Cargo.toml
Normal file
8
december_12/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_12"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
10
december_12/example.txt
Normal file
10
december_12/example.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
dc-end
|
||||
HN-start
|
||||
start-kj
|
||||
dc-start
|
||||
dc-HN
|
||||
LN-dc
|
||||
HN-end
|
||||
kj-sa
|
||||
kj-HN
|
||||
kj-dc
|
||||
21
december_12/input.txt
Normal file
21
december_12/input.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
cz-end
|
||||
cz-WR
|
||||
TD-end
|
||||
TD-cz
|
||||
start-UM
|
||||
end-pz
|
||||
kb-UM
|
||||
mj-UM
|
||||
cz-kb
|
||||
WR-start
|
||||
WR-pz
|
||||
kb-WR
|
||||
TD-kb
|
||||
mj-kb
|
||||
TD-pz
|
||||
UM-pz
|
||||
kb-start
|
||||
pz-mj
|
||||
WX-cz
|
||||
sp-WR
|
||||
mj-WR
|
||||
113
december_12/src/main.rs
Normal file
113
december_12/src/main.rs
Normal file
@@ -0,0 +1,113 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut unique_points: Vec<String> = Vec::new();
|
||||
let mut neighbours: Vec<Vec<usize>> = Vec::new();
|
||||
|
||||
let mut line_vec = Vec::new();
|
||||
|
||||
for line in reader.lines() {
|
||||
line_vec.push(line.unwrap());
|
||||
}
|
||||
|
||||
unique_points.push("start".to_string());
|
||||
for line in &line_vec{
|
||||
let split_line: Vec<&str> = line.split('-').collect();
|
||||
let origin = split_line[0].to_owned();
|
||||
let destination = split_line[1].to_owned();
|
||||
|
||||
if !unique_points.contains(&origin) && origin != "end" && origin != "start" {unique_points.push(origin)}
|
||||
if !unique_points.contains(&destination) && destination != "end" && destination != "start" {unique_points.push(destination)}
|
||||
}
|
||||
unique_points.push("end".to_string());
|
||||
|
||||
for _i in 0..unique_points.len() {
|
||||
neighbours.push(Vec::new());
|
||||
}
|
||||
|
||||
for line in &line_vec{
|
||||
let split_line: Vec<&str> = line.split('-').collect();
|
||||
let origin = split_line[0].to_owned();
|
||||
let destination = split_line[1].to_owned();
|
||||
|
||||
let origin_int = unique_points.iter().position(|r| r == &origin).unwrap();
|
||||
let destination_int = unique_points.iter().position(|r| r == &destination).unwrap();
|
||||
|
||||
if !neighbours[origin_int].contains(&destination_int) {neighbours[origin_int].push(destination_int)}
|
||||
if !neighbours[destination_int].contains(&origin_int) {neighbours[destination_int].push(origin_int)}
|
||||
}
|
||||
|
||||
|
||||
let mut possible_paths: Vec<Vec<usize>> = Vec::new();
|
||||
//let mut empty_path = ;
|
||||
possible_paths.append(&mut check_neighbours(&neighbours, 0, Vec::new(), &unique_points)
|
||||
);
|
||||
|
||||
let mut possible_paths_converted = Vec::new();
|
||||
|
||||
for path in &possible_paths{
|
||||
let mut temp_vec = Vec::new();
|
||||
for symbol in path {
|
||||
temp_vec.push(&unique_points[symbol.to_owned()]);
|
||||
}
|
||||
possible_paths_converted.push(temp_vec);
|
||||
}
|
||||
|
||||
|
||||
println!("Number of paths: {}", &possible_paths.len());
|
||||
|
||||
}
|
||||
|
||||
fn check_neighbours(neighbours: &Vec<Vec<usize>>, new_node: usize, path: Vec<usize>, unique_points: &Vec<String>) -> Vec<Vec<usize>> {
|
||||
let mut local_path = path.to_owned();
|
||||
let mut return_list = Vec::new();
|
||||
if unique_points[new_node] == "end" {
|
||||
local_path.push(new_node);
|
||||
return_list.push(local_path);
|
||||
return return_list;
|
||||
}
|
||||
local_path.push(new_node);
|
||||
|
||||
|
||||
|
||||
let mut number_caves = Vec::new();
|
||||
for _ in unique_points {
|
||||
number_caves.push(0);
|
||||
}
|
||||
for node in &local_path{
|
||||
number_caves[node.to_owned()] += 1;
|
||||
}
|
||||
|
||||
let mut allowed_to_visit_twice = true;
|
||||
for node in &local_path{
|
||||
let lowercase = unique_points[node.to_owned()] == unique_points[node.to_owned()].to_lowercase();
|
||||
if lowercase && number_caves[node.to_owned()] > 1 {
|
||||
allowed_to_visit_twice = false;
|
||||
}
|
||||
}
|
||||
|
||||
print!("");
|
||||
for neighbour in &neighbours[new_node] {
|
||||
let n = neighbour.to_owned();
|
||||
let lowercase = unique_points[n] == unique_points[n].to_lowercase();
|
||||
let uppercase = unique_points[n] == unique_points[n].to_uppercase();
|
||||
let _valid = ( uppercase || ((lowercase && allowed_to_visit_twice) || (lowercase && number_caves[n] < 1) ) ) && unique_points[n] != "start";
|
||||
print!("");
|
||||
if ( uppercase || ((lowercase && allowed_to_visit_twice) || (lowercase && number_caves[n] < 1) ) ) && unique_points[n] != "start" {
|
||||
let mut temp = check_neighbours(&neighbours, n, local_path.to_owned(), unique_points);
|
||||
return_list.append(&mut temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return return_list;
|
||||
|
||||
|
||||
|
||||
}
|
||||
8
december_13/Cargo.toml
Normal file
8
december_13/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_13"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
21
december_13/example.txt
Normal file
21
december_13/example.txt
Normal file
@@ -0,0 +1,21 @@
|
||||
6,10
|
||||
0,14
|
||||
9,10
|
||||
0,3
|
||||
10,4
|
||||
4,11
|
||||
6,0
|
||||
6,12
|
||||
4,1
|
||||
0,13
|
||||
10,12
|
||||
3,4
|
||||
3,0
|
||||
8,4
|
||||
1,10
|
||||
2,14
|
||||
8,10
|
||||
9,0
|
||||
|
||||
fold along y=7
|
||||
fold along x=5
|
||||
920
december_13/input.txt
Normal file
920
december_13/input.txt
Normal file
@@ -0,0 +1,920 @@
|
||||
949,224
|
||||
398,211
|
||||
402,700
|
||||
900,890
|
||||
1197,304
|
||||
333,809
|
||||
681,705
|
||||
769,864
|
||||
975,465
|
||||
639,523
|
||||
445,313
|
||||
912,99
|
||||
502,894
|
||||
703,343
|
||||
572,598
|
||||
1232,759
|
||||
277,640
|
||||
700,761
|
||||
919,429
|
||||
678,141
|
||||
1054,795
|
||||
934,750
|
||||
760,73
|
||||
268,627
|
||||
336,859
|
||||
1096,135
|
||||
646,176
|
||||
55,404
|
||||
932,872
|
||||
1168,338
|
||||
569,842
|
||||
904,863
|
||||
647,168
|
||||
509,606
|
||||
42,525
|
||||
607,343
|
||||
947,861
|
||||
1002,537
|
||||
1230,368
|
||||
186,274
|
||||
363,690
|
||||
1073,663
|
||||
868,312
|
||||
646,718
|
||||
385,210
|
||||
961,660
|
||||
1277,0
|
||||
470,228
|
||||
127,705
|
||||
894,89
|
||||
500,704
|
||||
994,361
|
||||
87,582
|
||||
985,378
|
||||
557,607
|
||||
75,872
|
||||
1068,647
|
||||
686,138
|
||||
358,84
|
||||
957,415
|
||||
325,516
|
||||
711,169
|
||||
1287,252
|
||||
619,242
|
||||
329,516
|
||||
821,714
|
||||
514,844
|
||||
632,358
|
||||
549,252
|
||||
442,302
|
||||
619,652
|
||||
5,809
|
||||
276,530
|
||||
15,75
|
||||
653,266
|
||||
632,536
|
||||
731,648
|
||||
237,231
|
||||
1266,19
|
||||
966,205
|
||||
360,37
|
||||
522,3
|
||||
1255,725
|
||||
833,840
|
||||
898,728
|
||||
805,162
|
||||
294,261
|
||||
1250,833
|
||||
403,151
|
||||
1288,564
|
||||
7,465
|
||||
350,274
|
||||
1133,478
|
||||
408,526
|
||||
1079,493
|
||||
310,205
|
||||
420,507
|
||||
1310,596
|
||||
639,824
|
||||
328,257
|
||||
30,417
|
||||
845,511
|
||||
196,683
|
||||
1002,201
|
||||
719,96
|
||||
15,457
|
||||
276,812
|
||||
760,43
|
||||
979,95
|
||||
319,429
|
||||
661,429
|
||||
654,298
|
||||
584,421
|
||||
372,355
|
||||
351,252
|
||||
430,453
|
||||
113,304
|
||||
701,772
|
||||
107,628
|
||||
549,700
|
||||
629,551
|
||||
492,851
|
||||
427,101
|
||||
278,666
|
||||
246,856
|
||||
194,82
|
||||
417,439
|
||||
433,712
|
||||
425,229
|
||||
308,89
|
||||
1275,652
|
||||
1193,316
|
||||
482,190
|
||||
955,245
|
||||
465,511
|
||||
688,37
|
||||
788,525
|
||||
92,235
|
||||
644,417
|
||||
1247,877
|
||||
25,327
|
||||
1255,404
|
||||
502,0
|
||||
960,760
|
||||
431,570
|
||||
741,702
|
||||
728,606
|
||||
1086,453
|
||||
1198,694
|
||||
181,208
|
||||
401,327
|
||||
959,194
|
||||
729,863
|
||||
1295,819
|
||||
7,271
|
||||
263,456
|
||||
132,868
|
||||
318,849
|
||||
242,726
|
||||
1133,392
|
||||
631,294
|
||||
410,302
|
||||
654,582
|
||||
649,465
|
||||
622,709
|
||||
805,284
|
||||
1300,533
|
||||
731,22
|
||||
579,470
|
||||
177,392
|
||||
1079,849
|
||||
252,397
|
||||
898,871
|
||||
634,618
|
||||
427,653
|
||||
433,630
|
||||
1228,851
|
||||
686,865
|
||||
1079,32
|
||||
105,252
|
||||
372,761
|
||||
15,864
|
||||
644,222
|
||||
1134,122
|
||||
572,851
|
||||
1303,429
|
||||
991,726
|
||||
304,620
|
||||
962,446
|
||||
899,586
|
||||
667,44
|
||||
786,228
|
||||
719,93
|
||||
411,742
|
||||
1031,110
|
||||
33,0
|
||||
646,483
|
||||
482,288
|
||||
885,47
|
||||
1250,609
|
||||
632,330
|
||||
594,833
|
||||
1178,868
|
||||
68,542
|
||||
482,480
|
||||
818,851
|
||||
278,592
|
||||
898,726
|
||||
141,660
|
||||
360,857
|
||||
515,651
|
||||
30,532
|
||||
865,540
|
||||
1168,500
|
||||
1022,525
|
||||
80,526
|
||||
975,429
|
||||
401,159
|
||||
1256,523
|
||||
1300,809
|
||||
410,598
|
||||
537,540
|
||||
482,606
|
||||
25,551
|
||||
229,709
|
||||
1096,555
|
||||
952,756
|
||||
23,70
|
||||
584,38
|
||||
810,288
|
||||
495,416
|
||||
278,358
|
||||
900,43
|
||||
550,43
|
||||
895,582
|
||||
1221,213
|
||||
1205,252
|
||||
1180,732
|
||||
524,3
|
||||
850,641
|
||||
1054,421
|
||||
865,581
|
||||
376,37
|
||||
751,233
|
||||
72,64
|
||||
969,717
|
||||
1032,666
|
||||
1170,50
|
||||
112,200
|
||||
279,784
|
||||
818,43
|
||||
810,704
|
||||
972,222
|
||||
738,296
|
||||
1285,791
|
||||
162,403
|
||||
333,85
|
||||
1168,786
|
||||
1161,51
|
||||
840,498
|
||||
3,351
|
||||
966,644
|
||||
522,891
|
||||
666,222
|
||||
751,592
|
||||
842,50
|
||||
480,446
|
||||
885,847
|
||||
7,623
|
||||
137,638
|
||||
1208,703
|
||||
668,716
|
||||
477,416
|
||||
1307,351
|
||||
981,555
|
||||
117,578
|
||||
430,254
|
||||
1280,417
|
||||
428,809
|
||||
743,312
|
||||
634,620
|
||||
1225,724
|
||||
10,869
|
||||
631,700
|
||||
87,312
|
||||
1237,689
|
||||
388,285
|
||||
358,810
|
||||
1111,894
|
||||
1133,499
|
||||
113,752
|
||||
666,670
|
||||
1198,200
|
||||
196,451
|
||||
1079,302
|
||||
1098,521
|
||||
987,95
|
||||
1295,523
|
||||
1275,591
|
||||
1131,855
|
||||
440,583
|
||||
1171,691
|
||||
955,201
|
||||
112,135
|
||||
291,861
|
||||
50,588
|
||||
1032,358
|
||||
678,330
|
||||
689,446
|
||||
30,815
|
||||
411,152
|
||||
505,610
|
||||
251,246
|
||||
1052,430
|
||||
427,793
|
||||
1173,383
|
||||
1143,431
|
||||
607,791
|
||||
189,32
|
||||
1057,7
|
||||
1307,543
|
||||
1173,374
|
||||
430,677
|
||||
313,289
|
||||
624,756
|
||||
1048,429
|
||||
1205,70
|
||||
231,862
|
||||
947,690
|
||||
966,250
|
||||
1220,851
|
||||
1253,210
|
||||
269,427
|
||||
850,701
|
||||
1034,812
|
||||
748,211
|
||||
868,73
|
||||
279,110
|
||||
664,624
|
||||
971,506
|
||||
1009,327
|
||||
214,555
|
||||
80,632
|
||||
1136,648
|
||||
1133,854
|
||||
557,5
|
||||
997,605
|
||||
1079,45
|
||||
174,648
|
||||
159,351
|
||||
341,717
|
||||
934,218
|
||||
549,194
|
||||
1079,862
|
||||
774,467
|
||||
423,177
|
||||
1126,50
|
||||
1039,255
|
||||
154,717
|
||||
1256,75
|
||||
1006,620
|
||||
1136,757
|
||||
73,831
|
||||
65,441
|
||||
95,415
|
||||
0,596
|
||||
455,33
|
||||
460,641
|
||||
528,427
|
||||
15,437
|
||||
627,201
|
||||
142,786
|
||||
714,386
|
||||
922,144
|
||||
97,606
|
||||
455,57
|
||||
1084,309
|
||||
840,725
|
||||
840,396
|
||||
428,533
|
||||
679,600
|
||||
607,103
|
||||
965,662
|
||||
674,542
|
||||
199,894
|
||||
691,425
|
||||
728,382
|
||||
636,352
|
||||
251,85
|
||||
149,527
|
||||
181,686
|
||||
253,119
|
||||
1124,172
|
||||
1059,757
|
||||
25,383
|
||||
15,371
|
||||
540,347
|
||||
793,638
|
||||
1305,809
|
||||
1221,231
|
||||
681,479
|
||||
870,107
|
||||
818,512
|
||||
427,457
|
||||
174,757
|
||||
559,233
|
||||
1263,343
|
||||
11,626
|
||||
174,246
|
||||
44,875
|
||||
211,453
|
||||
1000,250
|
||||
160,714
|
||||
802,698
|
||||
181,9
|
||||
883,101
|
||||
994,415
|
||||
1262,106
|
||||
715,548
|
||||
934,228
|
||||
378,82
|
||||
262,429
|
||||
23,252
|
||||
495,351
|
||||
885,665
|
||||
656,582
|
||||
1111,837
|
||||
609,324
|
||||
704,788
|
||||
994,733
|
||||
348,620
|
||||
877,642
|
||||
971,850
|
||||
1242,430
|
||||
513,234
|
||||
341,157
|
||||
221,476
|
||||
443,441
|
||||
159,767
|
||||
907,295
|
||||
1287,824
|
||||
622,485
|
||||
1297,659
|
||||
863,455
|
||||
1266,133
|
||||
596,386
|
||||
1042,85
|
||||
566,805
|
||||
711,404
|
||||
1019,204
|
||||
904,479
|
||||
1310,760
|
||||
1164,877
|
||||
1054,235
|
||||
986,392
|
||||
952,84
|
||||
468,50
|
||||
231,302
|
||||
1159,716
|
||||
979,799
|
||||
1178,815
|
||||
686,29
|
||||
336,35
|
||||
796,844
|
||||
1059,375
|
||||
445,130
|
||||
644,533
|
||||
865,537
|
||||
542,86
|
||||
1130,129
|
||||
1196,750
|
||||
162,627
|
||||
95,849
|
||||
339,492
|
||||
1173,256
|
||||
489,597
|
||||
972,415
|
||||
877,630
|
||||
885,717
|
||||
726,38
|
||||
1288,834
|
||||
934,302
|
||||
870,364
|
||||
711,649
|
||||
773,130
|
||||
410,43
|
||||
1133,395
|
||||
1091,714
|
||||
900,296
|
||||
258,240
|
||||
1144,852
|
||||
982,596
|
||||
1129,885
|
||||
960,386
|
||||
786,443
|
||||
378,872
|
||||
1130,765
|
||||
348,274
|
||||
1230,526
|
||||
415,312
|
||||
729,31
|
||||
1180,162
|
||||
793,704
|
||||
448,525
|
||||
149,630
|
||||
816,180
|
||||
555,121
|
||||
974,45
|
||||
1143,687
|
||||
214,87
|
||||
48,788
|
||||
499,367
|
||||
412,728
|
||||
796,396
|
||||
1260,812
|
||||
679,376
|
||||
65,383
|
||||
591,96
|
||||
512,52
|
||||
420,828
|
||||
589,889
|
||||
435,649
|
||||
149,591
|
||||
1114,666
|
||||
231,849
|
||||
1151,351
|
||||
64,205
|
||||
1240,856
|
||||
970,436
|
||||
145,457
|
||||
579,648
|
||||
50,193
|
||||
1168,108
|
||||
22,834
|
||||
885,495
|
||||
1218,235
|
||||
70,347
|
||||
1293,353
|
||||
632,834
|
||||
278,857
|
||||
1213,453
|
||||
971,268
|
||||
514,396
|
||||
957,479
|
||||
619,649
|
||||
490,736
|
||||
1302,849
|
||||
1086,640
|
||||
890,380
|
||||
619,591
|
||||
671,70
|
||||
159,655
|
||||
10,421
|
||||
862,369
|
||||
441,192
|
||||
818,64
|
||||
1183,705
|
||||
679,824
|
||||
1196,185
|
||||
114,302
|
||||
633,660
|
||||
1228,40
|
||||
435,245
|
||||
256,235
|
||||
651,351
|
||||
410,296
|
||||
947,21
|
||||
992,859
|
||||
89,213
|
||||
482,177
|
||||
112,459
|
||||
999,630
|
||||
774,203
|
||||
763,628
|
||||
985,516
|
||||
1261,640
|
||||
828,187
|
||||
562,211
|
||||
923,10
|
||||
87,309
|
||||
1146,736
|
||||
512,500
|
||||
305,234
|
||||
1295,371
|
||||
647,271
|
||||
1096,584
|
||||
508,353
|
||||
1297,812
|
||||
972,448
|
||||
688,485
|
||||
1081,512
|
||||
104,403
|
||||
401,703
|
||||
1073,231
|
||||
311,883
|
||||
833,812
|
||||
1032,857
|
||||
239,582
|
||||
503,716
|
||||
343,152
|
||||
664,176
|
||||
1168,672
|
||||
167,207
|
||||
401,775
|
||||
1116,474
|
||||
398,683
|
||||
331,799
|
||||
952,532
|
||||
1228,647
|
||||
1287,600
|
||||
908,642
|
||||
402,642
|
||||
355,245
|
||||
335,465
|
||||
788,891
|
||||
678,536
|
||||
8,493
|
||||
318,859
|
||||
1235,872
|
||||
177,873
|
||||
748,659
|
||||
242,168
|
||||
796,641
|
||||
440,331
|
||||
162,491
|
||||
1171,203
|
||||
477,840
|
||||
350,162
|
||||
524,666
|
||||
591,877
|
||||
22,330
|
||||
962,274
|
||||
629,567
|
||||
977,809
|
||||
828,480
|
||||
291,413
|
||||
1211,569
|
||||
1193,764
|
||||
468,274
|
||||
805,591
|
||||
395,45
|
||||
589,511
|
||||
1299,388
|
||||
883,437
|
||||
1302,483
|
||||
1097,702
|
||||
868,821
|
||||
423,401
|
||||
972,446
|
||||
30,79
|
||||
376,218
|
||||
899,742
|
||||
339,44
|
||||
721,63
|
||||
67,54
|
||||
795,651
|
||||
353,415
|
||||
805,723
|
||||
246,247
|
||||
261,5
|
||||
1047,456
|
||||
706,82
|
||||
344,644
|
||||
1170,760
|
||||
984,596
|
||||
493,297
|
||||
253,735
|
||||
349,234
|
||||
155,840
|
||||
349,660
|
||||
736,695
|
||||
994,670
|
||||
199,837
|
||||
221,712
|
||||
423,65
|
||||
1083,101
|
||||
386,732
|
||||
346,245
|
||||
1133,873
|
||||
1121,63
|
||||
1255,714
|
||||
880,441
|
||||
514,641
|
||||
1299,836
|
||||
1108,33
|
||||
1278,400
|
||||
241,500
|
||||
788,79
|
||||
1056,569
|
||||
810,190
|
||||
584,856
|
||||
1043,548
|
||||
1285,103
|
||||
1288,249
|
||||
1004,274
|
||||
1034,530
|
||||
244,890
|
||||
1192,691
|
||||
401,31
|
||||
155,591
|
||||
72,736
|
||||
351,642
|
||||
487,416
|
||||
934,37
|
||||
319,255
|
||||
1136,137
|
||||
442,73
|
||||
169,170
|
||||
1295,75
|
||||
862,525
|
||||
388,526
|
||||
831,58
|
||||
1119,649
|
||||
411,84
|
||||
902,247
|
||||
253,7
|
||||
840,617
|
||||
1000,196
|
||||
821,138
|
||||
1000,205
|
||||
710,819
|
||||
13,235
|
||||
914,654
|
||||
1161,527
|
||||
1262,261
|
||||
492,830
|
||||
455,705
|
||||
622,185
|
||||
1047,793
|
||||
140,760
|
||||
1275,649
|
||||
316,733
|
||||
345,662
|
||||
267,884
|
||||
1141,618
|
||||
1299,58
|
||||
440,107
|
||||
991,175
|
||||
852,451
|
||||
23,824
|
||||
375,110
|
||||
468,172
|
||||
541,590
|
||||
1001,801
|
||||
773,481
|
||||
442,373
|
||||
788,369
|
||||
500,288
|
||||
960,610
|
||||
894,252
|
||||
224,631
|
||||
1111,189
|
||||
1059,533
|
||||
1029,716
|
||||
114,709
|
||||
768,883
|
||||
541,752
|
||||
1076,514
|
||||
1277,894
|
||||
1133,306
|
||||
202,861
|
||||
798,52
|
||||
845,383
|
||||
647,726
|
||||
833,416
|
||||
584,473
|
||||
841,234
|
||||
1245,5
|
||||
30,756
|
||||
818,267
|
||||
885,512
|
||||
572,488
|
||||
417,614
|
||||
1155,840
|
||||
774,691
|
||||
149,51
|
||||
786,732
|
||||
10,701
|
||||
689,33
|
||||
440,364
|
||||
681,63
|
||||
643,44
|
||||
294,633
|
||||
786,666
|
||||
411,586
|
||||
256,795
|
||||
793,714
|
||||
32,494
|
||||
768,135
|
||||
378,530
|
||||
196,228
|
||||
164,736
|
||||
822,490
|
||||
495,767
|
||||
105,264
|
||||
1073,679
|
||||
445,242
|
||||
719,877
|
||||
146,698
|
||||
1262,358
|
||||
736,526
|
||||
1237,831
|
||||
965,93
|
||||
177,588
|
||||
877,712
|
||||
75,22
|
||||
887,65
|
||||
915,849
|
||||
1016,261
|
||||
22,141
|
||||
227,457
|
||||
540,99
|
||||
8,411
|
||||
701,570
|
||||
629,343
|
||||
261,453
|
||||
154,707
|
||||
117,255
|
||||
72,830
|
||||
691,652
|
||||
751,302
|
||||
447,455
|
||||
890,507
|
||||
209,354
|
||||
1238,736
|
||||
338,448
|
||||
574,526
|
||||
1000,698
|
||||
324,502
|
||||
1066,4
|
||||
44,19
|
||||
632,60
|
||||
768,459
|
||||
25,567
|
||||
1034,364
|
||||
949,670
|
||||
231,829
|
||||
924,610
|
||||
166,42
|
||||
703,103
|
||||
738,851
|
||||
212,521
|
||||
898,168
|
||||
664,718
|
||||
683,201
|
||||
358,756
|
||||
45,527
|
||||
1235,22
|
||||
666,533
|
||||
686,756
|
||||
132,369
|
||||
1252,715
|
||||
1016,270
|
||||
828,288
|
||||
226,309
|
||||
358,138
|
||||
1066,247
|
||||
960,162
|
||||
517,399
|
||||
401,607
|
||||
301,327
|
||||
8,483
|
||||
482,704
|
||||
882,585
|
||||
744,805
|
||||
406,863
|
||||
1148,627
|
||||
44,133
|
||||
1253,684
|
||||
1129,9
|
||||
1193,191
|
||||
815,351
|
||||
738,406
|
||||
388,592
|
||||
515,243
|
||||
155,303
|
||||
447,439
|
||||
917,677
|
||||
1041,609
|
||||
10,361
|
||||
137,383
|
||||
858,861
|
||||
1012,441
|
||||
1173,404
|
||||
1041,427
|
||||
137,520
|
||||
442,750
|
||||
166,852
|
||||
147,263
|
||||
835,396
|
||||
912,211
|
||||
209,481
|
||||
879,570
|
||||
959,600
|
||||
495,655
|
||||
1119,21
|
||||
253,241
|
||||
631,642
|
||||
492,512
|
||||
719,798
|
||||
344,205
|
||||
599,245
|
||||
997,289
|
||||
703,791
|
||||
1124,274
|
||||
1071,582
|
||||
909,607
|
||||
|
||||
fold along x=655
|
||||
fold along y=447
|
||||
fold along x=327
|
||||
fold along y=223
|
||||
fold along x=163
|
||||
fold along y=111
|
||||
fold along x=81
|
||||
fold along y=55
|
||||
fold along x=40
|
||||
fold along y=27
|
||||
fold along y=13
|
||||
fold along y=6
|
||||
112
december_13/src/main.rs
Normal file
112
december_13/src/main.rs
Normal file
@@ -0,0 +1,112 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut line_vec = Vec::new();
|
||||
|
||||
for line in reader.lines() {
|
||||
line_vec.push(line.unwrap());
|
||||
}
|
||||
|
||||
let mut coordinates: Vec<(i32, i32)> = Vec::new();
|
||||
let mut folds: Vec<(char, i32)> = Vec::new();
|
||||
|
||||
let mut processing_coordinates = true;
|
||||
|
||||
// Get coordinates
|
||||
for line in &line_vec {
|
||||
let _t = line.trim();
|
||||
if line.trim().len() < 2 {
|
||||
processing_coordinates = false;
|
||||
} else if processing_coordinates {
|
||||
let split_string = line.split(",").collect::<Vec<&str>>();
|
||||
let x: i32 = split_string[0].to_owned().parse().unwrap();
|
||||
let y: i32 = split_string[1].to_owned().parse().unwrap();
|
||||
coordinates.push( (x, y) );
|
||||
} else {
|
||||
let split_string = line.split(" ").collect::<Vec<&str>>();
|
||||
let split_coords = split_string[2].split("=").collect::<Vec<&str>>();
|
||||
let split_direction: char = split_coords[0].to_owned().parse().unwrap();
|
||||
let split_cord: i32 = split_coords[1].to_owned().parse().unwrap();
|
||||
folds.push((split_direction, split_cord));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
println!("There are {} lights", coordinates.len());
|
||||
|
||||
for fold in folds {
|
||||
let line = fold.1;
|
||||
let mut new_cords = Vec::new();
|
||||
if fold.0 == 'x' {
|
||||
for cord in &coordinates {
|
||||
let mut x = cord.0;
|
||||
let mut y = cord.1;
|
||||
|
||||
if x > line {
|
||||
let diff = x - line;
|
||||
x = line - diff;
|
||||
}
|
||||
|
||||
new_cords.push((x,y));
|
||||
|
||||
}
|
||||
} else {
|
||||
for cord in &coordinates {
|
||||
let mut x = cord.0;
|
||||
let mut y = cord.1;
|
||||
|
||||
if y > line {
|
||||
let diff = y - line;
|
||||
y = line - diff;
|
||||
}
|
||||
|
||||
new_cords.push((x,y));
|
||||
|
||||
}
|
||||
}
|
||||
coordinates = new_cords;
|
||||
coordinates.sort_unstable();
|
||||
coordinates.dedup();
|
||||
println!("There are {} lights", coordinates.len());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
let mut width = 0;
|
||||
let mut height = 0;
|
||||
|
||||
for cord in &coordinates {
|
||||
if cord.0 + 1 > width {
|
||||
width = cord.0 + 1;
|
||||
}
|
||||
if cord.1 + 1 > height {
|
||||
height = cord.1 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
println!("Grid is {} high and {} wide", height, width);
|
||||
|
||||
for y in 0..=height {
|
||||
for x in 0..=width {
|
||||
let mut exists = false;
|
||||
for cord in &coordinates {
|
||||
if cord.0 == x && cord.1 == y {
|
||||
exists = true;
|
||||
}
|
||||
}
|
||||
if exists {
|
||||
print!("X");
|
||||
} else {
|
||||
print!(" ");
|
||||
}
|
||||
}
|
||||
println!("");
|
||||
}
|
||||
}
|
||||
8
december_14/Cargo.toml
Normal file
8
december_14/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_14"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
18
december_14/example.txt
Normal file
18
december_14/example.txt
Normal 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
|
||||
102
december_14/input.txt
Normal file
102
december_14/input.txt
Normal file
@@ -0,0 +1,102 @@
|
||||
PHOSBSKBBBFSPPPCCCHN
|
||||
|
||||
KO -> H
|
||||
OK -> P
|
||||
BO -> C
|
||||
SH -> V
|
||||
PC -> F
|
||||
NK -> N
|
||||
PH -> K
|
||||
VH -> S
|
||||
NN -> S
|
||||
VC -> P
|
||||
OF -> O
|
||||
HH -> S
|
||||
VP -> K
|
||||
KP -> O
|
||||
NP -> F
|
||||
SS -> V
|
||||
HP -> S
|
||||
PS -> F
|
||||
BV -> P
|
||||
KS -> H
|
||||
SO -> H
|
||||
NF -> N
|
||||
CO -> V
|
||||
HK -> F
|
||||
OO -> N
|
||||
KN -> F
|
||||
SP -> V
|
||||
OP -> S
|
||||
OV -> V
|
||||
HO -> V
|
||||
PK -> N
|
||||
FF -> N
|
||||
CV -> S
|
||||
PP -> B
|
||||
CF -> P
|
||||
HF -> B
|
||||
BN -> C
|
||||
FH -> S
|
||||
ON -> K
|
||||
SN -> N
|
||||
CP -> N
|
||||
OB -> O
|
||||
HC -> F
|
||||
KH -> P
|
||||
OS -> S
|
||||
NS -> C
|
||||
BK -> H
|
||||
PB -> P
|
||||
SV -> F
|
||||
FV -> C
|
||||
BC -> K
|
||||
HS -> N
|
||||
PF -> V
|
||||
NC -> N
|
||||
CH -> H
|
||||
VF -> H
|
||||
KK -> B
|
||||
OH -> K
|
||||
HB -> C
|
||||
SC -> B
|
||||
VK -> C
|
||||
FP -> C
|
||||
SK -> N
|
||||
VO -> K
|
||||
FB -> S
|
||||
KB -> N
|
||||
BS -> S
|
||||
VS -> C
|
||||
CN -> K
|
||||
KF -> F
|
||||
NB -> O
|
||||
BB -> C
|
||||
CS -> C
|
||||
FC -> K
|
||||
NO -> B
|
||||
SB -> C
|
||||
CB -> N
|
||||
BP -> S
|
||||
NV -> H
|
||||
NH -> N
|
||||
PV -> K
|
||||
PO -> C
|
||||
VB -> O
|
||||
FK -> P
|
||||
HV -> O
|
||||
KC -> S
|
||||
VV -> O
|
||||
VN -> H
|
||||
BH -> K
|
||||
FS -> O
|
||||
KV -> K
|
||||
HN -> P
|
||||
OC -> B
|
||||
SF -> V
|
||||
CC -> F
|
||||
CK -> P
|
||||
FO -> C
|
||||
PN -> K
|
||||
BF -> C
|
||||
FN -> O
|
||||
132
december_14/src/main.rs
Normal file
132
december_14/src/main.rs
Normal file
@@ -0,0 +1,132 @@
|
||||
use std::collections::{HashMap};
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
|
||||
const STEPS: u32 = 40;
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut line_vec = Vec::new();
|
||||
|
||||
for line in reader.lines() {
|
||||
line_vec.push(line.unwrap());
|
||||
}
|
||||
|
||||
let input_seq: Vec<char> = line_vec[0].chars().collect();
|
||||
let mut rules: Vec<( (char, char) , char )> = Vec::new();
|
||||
|
||||
for i in 2..line_vec.len() {
|
||||
let split_vec: Vec<&str> = line_vec[i].split(" -> ").collect();
|
||||
let input_vec: Vec<char> = split_vec[0].to_owned().chars().collect();
|
||||
let input_tuple = (input_vec[0], input_vec[1]);
|
||||
|
||||
let output = split_vec[1].chars().collect::<Vec<char>>()[0];
|
||||
|
||||
rules.push( ( input_tuple, output ) );
|
||||
}
|
||||
|
||||
let mut pair_map: HashMap<String, u128> = HashMap::new();
|
||||
|
||||
for i in 0..input_seq.len()-1 {
|
||||
let mut str = String::from(input_seq[i]);
|
||||
str.push(input_seq[i + 1]);
|
||||
*pair_map.entry(str).or_insert(0) += 1 ;
|
||||
}
|
||||
|
||||
|
||||
for _step in 0..STEPS {
|
||||
let mut output_map = HashMap::new();
|
||||
let temp_pair_map = pair_map.clone();
|
||||
for rule in &rules {
|
||||
let mut key_string = String::from(rule.0.0);
|
||||
key_string.push(rule.0.1);
|
||||
if temp_pair_map.contains_key(&key_string) {
|
||||
//pair_map.remove(&key_string);
|
||||
|
||||
let count = temp_pair_map.get(&key_string).unwrap();
|
||||
|
||||
let mut pair_1 = String::from(rule.0.0);
|
||||
pair_1.push(rule.1);
|
||||
let mut pair_2 = String::from(rule.1);
|
||||
pair_2.push(rule.0.1);
|
||||
|
||||
*output_map.entry(pair_1).or_insert(0) += count ;
|
||||
*output_map.entry(pair_2).or_insert(0) += count ;
|
||||
}
|
||||
}
|
||||
pair_map = output_map;
|
||||
}
|
||||
|
||||
let mut letter_map = HashMap::new();
|
||||
|
||||
for pair in &pair_map {
|
||||
let char_1 = pair.0.chars().collect::<Vec<char>>()[0];
|
||||
let char_2 = pair.0.chars().collect::<Vec<char>>()[1];
|
||||
let count = pair.1;
|
||||
*letter_map.entry(char_1).or_insert(0) += count ;
|
||||
*letter_map.entry(char_2).or_insert(0) += count ;
|
||||
}
|
||||
|
||||
let mut out_map = HashMap::new();
|
||||
|
||||
for letter in &letter_map {
|
||||
let current_char = letter.0.to_owned();
|
||||
let count = letter.1.to_owned();
|
||||
let mut new_count = 0;
|
||||
if count % 2 == 1 {
|
||||
new_count = ((count - 1 )/2) + 1;
|
||||
} else if count == 1 {
|
||||
new_count = 1;
|
||||
} else {
|
||||
new_count = count / 2;
|
||||
}
|
||||
*out_map.entry(current_char).or_insert(0) += new_count ;
|
||||
|
||||
}
|
||||
|
||||
|
||||
let max = out_map.iter().max_by_key(|&(_, count)| count).unwrap().1.to_owned();
|
||||
let min = out_map.iter().min_by_key(|&(_, count)| count).unwrap().1.to_owned();
|
||||
println!("Diff: {}", max - min);
|
||||
|
||||
|
||||
|
||||
// for step in 0..STEPS {
|
||||
// let mut output_seq: Vec<char> = Vec::new();
|
||||
// for i in 0..input_seq.len() - 1 {
|
||||
// let first = input_seq[i];
|
||||
// let second = input_seq[i + 1];
|
||||
|
||||
// output_seq.push(first);
|
||||
// for rule in &rules {
|
||||
// let r_in = rule.0;
|
||||
// let r_out = rule.1;
|
||||
// if first == r_in.0 && second == r_in.1 {
|
||||
// output_seq.push(r_out);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
// output_seq.push(input_seq[input_seq.len()-1]);
|
||||
|
||||
// println!("Step: {}", step);
|
||||
// input_seq = output_seq;
|
||||
// }
|
||||
|
||||
// let mut counts = BTreeMap::new();
|
||||
// for word in input_seq.iter() {
|
||||
// *counts.entry(word).or_insert(0) += 1;
|
||||
// }
|
||||
|
||||
// let max = counts.iter().max_by_key(|&(_, count)| count);
|
||||
// let min = counts.iter().min_by_key(|&(_, count)| count);
|
||||
|
||||
// println!("Max: {:?}, Min: {:?}, Diff: {}", min.unwrap(), max.unwrap(), max.unwrap().1 - min.unwrap().1) ;
|
||||
|
||||
|
||||
|
||||
}
|
||||
8
december_15/Cargo.toml
Normal file
8
december_15/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_15"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
10
december_15/example.txt
Normal file
10
december_15/example.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
1163751742
|
||||
1381373672
|
||||
2136511328
|
||||
3694931569
|
||||
7463417111
|
||||
1319128137
|
||||
1359912421
|
||||
3125421639
|
||||
1293138521
|
||||
2311944581
|
||||
3
december_15/example2.txt
Normal file
3
december_15/example2.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
19999
|
||||
19111
|
||||
11191
|
||||
100
december_15/input.txt
Normal file
100
december_15/input.txt
Normal file
@@ -0,0 +1,100 @@
|
||||
1964778752979887222739789777935919929996793679617497991954953881381939846468999159686925929898196249
|
||||
8759189989991999115121999113211788158983883981916933973182798769168715496674423979199573198873854989
|
||||
2916817799179797949192724497956464139512861918986689421481689714471669982489852996119597949888649993
|
||||
3429492714828168979771398891678818935485694839763399796988678112189583269768679792191755489996819818
|
||||
7956995159237939293319975584779958986526992814763894821138352743589946198365389719619992176545838879
|
||||
6894733223797749829183642911499532916859775927195417482554567729418599872969862136349799419994687895
|
||||
2759239975966982742446721118515649658718899983621767679758422696981391642329892996989459995669798697
|
||||
4871846878568885679911989919675587272979337779997878941142835988221478131873935963978729297886139169
|
||||
7999959169281333751174889518989895572896163199221368686388799926519794699799923174194941238928589796
|
||||
9673899872976699541997289776451458192595451289851921695168998599956996287274974589993895999911968979
|
||||
2189799897986439761837888853324829341216529742299672852941871997559375864789386122271746495896794791
|
||||
9938386946518957531699878681584584964918976817297812956462471969177758385919189982296399838923928939
|
||||
4275189819452758426829188964681958425813889249999799196398898929428939818471881449812315725979925948
|
||||
7839191997723839711989597539332999799698291856397972249727787849495896789269554411391811373488912969
|
||||
9991932961553536898969691427116875526215696896938613596999539698956698498155643927131628839711918729
|
||||
9689481119559879668959932516469834984764657446183977948691462949415366788398622963991783197189499749
|
||||
7893891719779792989279958991976795699181589597959138897764521861982247998328792718743913147198513966
|
||||
9229398293621962999951889798191298941966911561894718699997528891728499799769299594844878826379212229
|
||||
8114755891869969978798891934912769591996819776399989765797896128921791896759288599146617996799938892
|
||||
5972439691937789543995348496582934955419378443786946743176772134892759981289214999252492789994912519
|
||||
9999878284296198978291425928754817436271169898969986169389621659848796896718349699944959841976887979
|
||||
8995172699256977369819859998243969598411799887371899978965729218569995255335578989297761711979697279
|
||||
5964929613931779238784627758412212181166181675691169528311979637962893954537763982917915779197598919
|
||||
9329999971496358947166338919899899416981161169866529652865685792919877767118176597496599597196924899
|
||||
7271975999674778999171971959191993946848163989989997969948924863192929224488787991896699281749827981
|
||||
7699689989198719837571649869869997239499861716884656858395517769988394779311619459491989383499197268
|
||||
8138528939235689938575248913721989783488836178269759533138953836592979449873625149573891997212479889
|
||||
1194186961217198193988498992355788419825494192989525159689798712975319599971827597742959843955911979
|
||||
9991363768629695336799575699999721989989917969232982174499837972549921599924797598996111985425191495
|
||||
6224199895942439267375819799214473982598281689668323916911879197967989217151818849734921868839889953
|
||||
2797891953385665166198975159893818966216198377578712873269784989492119916357987941796591437988938957
|
||||
9779821394499494593989986959996998692998298791629567995816849947192476378699325431774652164876319399
|
||||
8279883158919549641581758481988868892673899854755757655799879479727992921235786698877699587719557817
|
||||
8994986299499779981878149737914546992923788331973355557931912813487414849169586776188929999316996999
|
||||
3499941923877958919184968172278689699896918797161441492525291995817947177988899429956927999874117615
|
||||
9518735698739793988999949283669535854518279898395156698682921779151989183918899376431178719847211917
|
||||
8959569562449992579869539699738394615824477992978595158952999831143599733757959319878895488818466994
|
||||
4771221597963589993951489919897987919972847979856478899532499699995165221761395991179429879943877199
|
||||
9358396988965649992967998569567913995272198899939966249136998289878785998148692727934781927566617716
|
||||
9695897663786123274922829519725449941162197499897582997999837678932164486457189978772888188949785949
|
||||
2229629789279799955899167476898994839159369899619998578354226667829287299556269181995691312568798773
|
||||
8986191398899845547849998899881493546398886844887168962985891999929956754259992377999937693899755175
|
||||
7175873171397179677593515237961898681148199598839711877778496983153317579398682998411683978987881997
|
||||
1298538869811849383999117371323559984927944988899199699928999419957218968156974484868752469129262989
|
||||
9731561977991246175968959799134367415782961298978241777998529577773489176786529999298276919819282278
|
||||
5139485996594989893145888798563499416819996991199156853594539997297977872962913739949965145219399965
|
||||
8983481898839581176999892935177977798924747335789486142969991819778229398776888781189418591899219928
|
||||
5991279788897976346748147414862695456951589321587991882347718411894488859198898259759815513119791569
|
||||
8227945959958298837959782585999896633581225814664916697479824997438358779792895774979843752914453972
|
||||
4969151368678265681558739735791991537887198957112191497717769345618978852795923288497297897895929999
|
||||
1519799684949231934618481659618992524489812446699528583999896615941151949985499999993886929639497791
|
||||
1919828829886491381185477846954179789637515617553898959167959989111765297739994219233999883196929166
|
||||
9998739993999963799842299399178749796575293889914288923995766963218597719191435991789849824475293761
|
||||
6292981699893999814978995879985986732598297996514589923713342895999879593853119193717396792997847699
|
||||
9995978699659218782765696299479144716993781213851813753413888998887766896164659855572836992467197889
|
||||
9217712236953916773136797729855561896118885989789931276897245797585829719971197298416959471465967299
|
||||
8749983199162381588749185138547797187291312282935858898773319299528189947814491298821948298698917998
|
||||
8869537419399779797931123692837166294495799967721996873988844831152966589773118129996872129174245734
|
||||
6999949888788198499769769893119838727389879594985996264338836189769745171919499431598495487598996829
|
||||
2643438319977946618997882718739614961945999488979133494999859875958989978289978891995578284983191769
|
||||
9711343348446947989897455526854391996559785892751279911869879891927989217818761659468859389913918159
|
||||
4684878627919284791377127887978412232228626693294949676597441174499789199371869999845955919776487925
|
||||
7336328939319927281586293939269992937969668286319998679381249791842789823962288582686236183876186189
|
||||
8498199998653599954199689592971461496115597192381769198382378211678161716941995196615974678163278978
|
||||
2998646498892845989822928114511999895167278839959595169842949959999918557832795946119311714389383991
|
||||
9984244818187938587919721975981668841119986975695637997888658465896898817589749499729979598979727197
|
||||
3863786997161389931987278761687458498299597892974921921998696597634973915194429518998588919819992157
|
||||
3119918226997269698895866728999573113997218692982671793292949996198899525937453993612931127922615284
|
||||
6379719955643911286241981859839442769958499849676976399619189989256898582949928891859195489926593225
|
||||
9466177592439495219155699988857895114899757931376891988791861639981429819498859829699953915984557119
|
||||
5374978935117993911513985778249971394799996215739819192271757989986194819377829685788878384186668579
|
||||
5996948596188399596276916591738868899415917585689991911459474597973519819254199897579188972591385492
|
||||
9322616873977891567797785992628933998998689889969238979881992269985738953791967118985999822789973433
|
||||
9199392396987912599354118198522389299456969987319191279618989499499887993924599797794177285631979167
|
||||
8855183914541833731439967697497418572879596386674694298959932189933841866512369842921637392699374912
|
||||
8988284461979263735382265499953696978939495465937911934474937417988811279816877822138921898948376181
|
||||
5437381949531929775936998169527199196578734594998292179919393485374186397999598711914297897676779586
|
||||
2396881448499782771276998937887566187891818989841832748994742788697928591911992786489698526461694989
|
||||
4246912291936687945949431175795992778687971357323979793399128579749866596897749827138281972961559158
|
||||
8647699922398842951889916948999698459962477299829918411933795388631159575199881299857589572777687999
|
||||
1311988719839948383899391321597894992589538493239179737996223383196197788192688789936916569885746193
|
||||
7954826979959947682969468987879991533849653569579969694792898697776848612986289349116791369579963519
|
||||
6593461421187759143952361892951669186319499192899168818751698499375889498194687225996979991984182191
|
||||
9335328245597991499897759977969229696591989282589998699129519144748578917798947994995199792918282991
|
||||
9398849415997381994698899787899727198999987399289971848636857987925948679582957479378858514993191181
|
||||
4149987331746768149745999853585139629671813691691596384395667999149381812199968928229665789284992374
|
||||
7427922988292997779559894894993998973997839317916919959899499493579911986477729836979789677259549118
|
||||
2642977979999586628631219897898878639971585969663183921898877933957895824999784889149738669989189789
|
||||
9762493593855472517917523499451984451888889977182975177177631967968932881279659956186784398919998985
|
||||
6432918193479269929129386389769916441769189759989721934769679259263889887181527989833327889848697941
|
||||
1393231159891181194862992269761747833947956873525561418387821863318689879524877738438288899299953799
|
||||
3842851494837961961556887296519919879914829134229941988917932644519999778998783391698499139917994989
|
||||
6459949159299986724199928878695399917976578879189193215239688557999671187992222149868714176139783787
|
||||
8463293782889894999994957687196286799689666437669478542975956699912379182795887258767997618178425918
|
||||
1953199634739829152796952926222792594239959671973846419654368418698936881329847929915911741616629164
|
||||
7845537283597249729992171128489499424199835337125999796988893187159337984973899291199499518477759357
|
||||
8997952978886957899187992878357919738776489938875699819693849929789872998684248986998859178999693399
|
||||
1138799983929178584919823996794446498474269912579351992888547384896372519992979599519718742166879882
|
||||
7298971978993365997919769838756115168896812437881278598927724918958597279567156161156299352891298849
|
||||
9179979719419789581891969361814895646898199782835916681989892966646599953969992849273537533978176119
|
||||
112
december_15/src/main.rs
Normal file
112
december_15/src/main.rs
Normal file
@@ -0,0 +1,112 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
|
||||
const RADIX: u32 = 10;
|
||||
|
||||
struct Node {
|
||||
distance: u32,
|
||||
previous: Option<(usize, usize)>,
|
||||
neigbours: Vec<(usize, usize)>,
|
||||
visited: bool
|
||||
}
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut weight_vec = Vec::new();
|
||||
|
||||
for line in reader.lines() {
|
||||
let mut temp_vec = Vec::new();
|
||||
for symbol in line.unwrap().chars() {
|
||||
let symbol_as_int = symbol.to_digit(RADIX).unwrap();
|
||||
temp_vec.push(symbol_as_int)
|
||||
}
|
||||
weight_vec.push(temp_vec);
|
||||
}
|
||||
|
||||
let mut weight_vec_big_temp = Vec::new();
|
||||
for line in 0..weight_vec.len() {
|
||||
let mut new_line_vec = Vec::new();
|
||||
for i in 0..weight_vec.len() * 5 {
|
||||
let coordinate_from = i % weight_vec[line].len();
|
||||
let add_val = i / weight_vec[line].len();
|
||||
let mut new_value = weight_vec[line][coordinate_from] + add_val as u32;
|
||||
if new_value > 9 {
|
||||
new_value -= 9;
|
||||
}
|
||||
new_line_vec.push(new_value);
|
||||
}
|
||||
weight_vec_big_temp.push(new_line_vec);
|
||||
}
|
||||
|
||||
let mut final_vector = Vec::new();
|
||||
|
||||
for line in 0..weight_vec_big_temp.len() * 5 {
|
||||
let add_val = line / weight_vec_big_temp.len();
|
||||
let mut temp_vec = Vec::new();
|
||||
for i in 0..weight_vec_big_temp[0].len() {
|
||||
let mut new_value = weight_vec_big_temp[line % weight_vec_big_temp.len()][i] + add_val as u32;
|
||||
if new_value > 9 {
|
||||
new_value -= 9;
|
||||
}
|
||||
temp_vec.push(new_value)
|
||||
}
|
||||
final_vector.push(temp_vec);
|
||||
}
|
||||
|
||||
println!("Finished generating Vec");
|
||||
weight_vec = final_vector;
|
||||
|
||||
let height = weight_vec.len();
|
||||
let width = weight_vec[0].len();
|
||||
|
||||
let mut graph = HashMap::new();
|
||||
|
||||
for x in 0..width {
|
||||
for y in 0..height {
|
||||
let mut neighbours = Vec::new();
|
||||
if x > 0 { neighbours.push((x-1,y)) }
|
||||
if x < width - 1 { neighbours.push((x+1,y)) }
|
||||
if y > 0 { neighbours.push((x,y-1)) }
|
||||
if y < height - 1 { neighbours.push((x,y+1)) }
|
||||
graph.insert((x,y) , Node{distance: u32::MAX, previous: None, neigbours: neighbours, visited: false});
|
||||
}
|
||||
}
|
||||
|
||||
let default_node = Node { distance: 0, previous: None, neigbours: Vec::new(), visited: false };
|
||||
|
||||
let start_node = (0,0);
|
||||
let end_node = (width-1, height-1);
|
||||
|
||||
graph.entry(start_node).or_insert(default_node).distance = 0;
|
||||
|
||||
loop {
|
||||
let active_node = &graph.iter().filter(|x| x.1.visited == false).min_by_key(|x| x.1.distance).expect("").0.to_owned();
|
||||
|
||||
if active_node == &end_node {
|
||||
break;
|
||||
}
|
||||
let distance = graph.get(active_node).expect("PANIK").distance;
|
||||
//graph.entry(active_node.to_owned()).or_insert(Node { distance: 0, previous: None, neigbours: Vec::new(), visited: false }).visited = true;
|
||||
graph.get_mut(active_node).unwrap().visited = true;
|
||||
|
||||
for neighbour in graph.get(active_node).expect("PANIK").neigbours.clone() {
|
||||
|
||||
let old_distance = graph.get(&neighbour).expect("PANIK").distance;
|
||||
let new_distance = distance + weight_vec[neighbour.1][neighbour.0];
|
||||
if new_distance < old_distance.to_owned() {
|
||||
graph.get_mut(&neighbour).unwrap().distance = new_distance;
|
||||
graph.get_mut(&neighbour).unwrap().previous = Some(active_node.to_owned());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let distance = graph.get(&end_node).unwrap().distance;
|
||||
|
||||
println!("{}", distance);
|
||||
}
|
||||
9
december_16/Cargo.toml
Normal file
9
december_16/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "december_16"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
hex = "0.4.3"
|
||||
1
december_16/example.txt
Normal file
1
december_16/example.txt
Normal file
@@ -0,0 +1 @@
|
||||
A0016C880162017C3686B18A3D4780
|
||||
1
december_16/input.txt
Normal file
1
december_16/input.txt
Normal file
@@ -0,0 +1 @@
|
||||
C20D42002ED333E7774EAAC3C2009670015692C61B65892239803536C53E2D307A600ACF324928380133D18361005B336D3600B4BF96E4A59FED94C029981C96409C4A964F995D2015DE6BD1C6E7256B004C0010A86B06A1F0002151AE0CC79866600ACC5CABC0151006238C46858200E4178F90F663FBA4FDEC0610096F8019B8803F19A1641C100722E4368C3351D0E9802D60084DC752739B8EA4ED377DE454C0119BBAFE80213F68CDC66A349B0B0053B23DDD61FF22CB874AD1C4C0139CA29580230A216C9FF54AD25A193002A2FA002AB3A63377C124205008A05CB4B66B24F33E06E014CF9CCDC3A2F22B72548E842721A573005E6E5F76D0042676BB33B5F8C46008F8023301B3F59E1464FB88DCBE6680F34C8C0115CDAA48F5EE45E278380019F9EC6395F6BE404016849E39DE2EF002013C873C8A401544EB2E002FF3D51B9CAF03C0010793E0344D00104E7611C284F5B2A10626776F785E6BD672200D3A801A798964E6671A3E9AF42A38400EF4C88CC32C24933B1006E7AC2F3E8728C8E008C759B45400B4A0B4A6CD23C4AF09646786B70028C00C002E6D00AEC1003440080024658086A401EE98070B50029400C0014FD00489000F7D400E000A60001E870038800AB9AB871005B12B37DB004266FC28988E52080462973DD0050401A8351DA0B00021D1B220C1E0013A0C0198410BE1C180370C21CC552004222FC1983A0018FCE2ACBDF109F76393751D965E3004E763DB4E169E436C0151007A10C20884000874698630708050C00043E24C188CC0008744A8311E4401D8B109A3290060BE00ACEA449214CD7B084B04F1A48025F8BD800AB4D64426B22CA00FC9BE4EA2C9EA6DC40181E802B39E009CB5B87539DD864A537DA7858C011B005E633E9F6EA133FA78EE53B7DE80
|
||||
96
december_16/src/main.rs
Normal file
96
december_16/src/main.rs
Normal file
@@ -0,0 +1,96 @@
|
||||
use std::{fs::read_to_string, env::current_exe};
|
||||
|
||||
extern crate hex;
|
||||
|
||||
static mut version_sum: u32 = 0;
|
||||
|
||||
fn main() {
|
||||
let input_char_vec = read_to_string("./input.txt").expect("ERROR reading file");
|
||||
//let split_input: Vec<char> = input_char_vec.chars().collect();
|
||||
let test = hex::decode(input_char_vec).expect("Decoding failed");
|
||||
|
||||
let mut bit_vec: Vec<bool> = Vec::new();
|
||||
|
||||
for t in test{
|
||||
for n in 0..8 {
|
||||
bit_vec.push( (t >> 7-n & 1) == 1);
|
||||
}
|
||||
}
|
||||
process_packet(bit_vec);
|
||||
unsafe {println!("Package Version Sum: {}", version_sum);}
|
||||
}
|
||||
|
||||
fn process_packet(bit_vec: Vec<bool>) -> usize {
|
||||
let version = (bit_vec[0] as u32 * 4) + (bit_vec[1] as u32 * 2) + (bit_vec[2] as u32);
|
||||
let packet_type = (bit_vec[3] as u32 * 4) + (bit_vec[4] as u32 * 2) + (bit_vec[5] as u32);
|
||||
println!("Packet Version: {}, Packet type: {}", version, packet_type);
|
||||
unsafe { version_sum += version}
|
||||
let mut end_bit = 0;
|
||||
if packet_type == 4 {
|
||||
// This is a decimal value, print for now return later
|
||||
let mut last_bit = false;
|
||||
let mut current_byte = 0;
|
||||
let mut out_vec = Vec::new();
|
||||
while !last_bit {
|
||||
let last_bit_identifier = bit_vec[6 + (5*current_byte)];
|
||||
let bit1 = bit_vec[7 + (5*current_byte)];
|
||||
let bit2 = bit_vec[8 + (5*current_byte)];
|
||||
let bit3 = bit_vec[9 + (5*current_byte)];
|
||||
let bit4 = bit_vec[10 + (5*current_byte)];
|
||||
if last_bit_identifier == false { last_bit = true }
|
||||
end_bit = 10 + (5*current_byte) + 1;
|
||||
current_byte += 1;
|
||||
out_vec.push(bit1);
|
||||
out_vec.push(bit2);
|
||||
out_vec.push(bit3);
|
||||
out_vec.push(bit4);
|
||||
}
|
||||
|
||||
println!("{}", to_dec(out_vec));
|
||||
} else {
|
||||
let mut lenght_length = 0;
|
||||
let mut length = 0;
|
||||
let base: i32 = 2;
|
||||
if bit_vec[6] {
|
||||
lenght_length = 11;
|
||||
} else {
|
||||
lenght_length = 15;
|
||||
}
|
||||
for i in 1..=lenght_length {
|
||||
length += bit_vec[ (7 + lenght_length) - i ] as i32 * base.pow((i - 1) as u32);
|
||||
}
|
||||
|
||||
println!("length {}", length);
|
||||
let mut data_end_bit = 0;
|
||||
let mut end = false;
|
||||
|
||||
if lenght_length == 15 {
|
||||
while !end {
|
||||
let vec_start = 7+lenght_length + data_end_bit;
|
||||
let vec_end = 7+lenght_length+length as usize;
|
||||
let vec_slice: Vec<bool> = bit_vec[vec_start..vec_end].to_vec();
|
||||
data_end_bit = process_packet(vec_slice);
|
||||
end_bit = vec_start + data_end_bit;
|
||||
if data_end_bit + vec_start >= vec_end { end = true}
|
||||
}
|
||||
} else {
|
||||
for subblock in 0..length {
|
||||
let vec_start = 7+lenght_length + data_end_bit;
|
||||
let vec_end = bit_vec.len();
|
||||
let vec_slice: Vec<bool> = bit_vec[vec_start..vec_end].to_vec();
|
||||
data_end_bit += process_packet(vec_slice);
|
||||
end_bit = vec_start + data_end_bit;
|
||||
}
|
||||
}
|
||||
}
|
||||
return end_bit;
|
||||
}
|
||||
|
||||
fn to_dec(bit_vec: Vec<bool>) -> u128 {
|
||||
let mut out_val = 0;
|
||||
let base: i128 = 2;
|
||||
for i in 1..=bit_vec.len() {
|
||||
out_val += bit_vec[bit_vec.len() - i] as i128 * base.pow((i - 1) as u32);
|
||||
}
|
||||
return out_val as u128;
|
||||
}
|
||||
1
december_3/.gitignore
vendored
Normal file
1
december_3/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
8
december_3/Cargo.toml
Normal file
8
december_3/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_3_1"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
12
december_3/example.txt
Normal file
12
december_3/example.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
00100
|
||||
11110
|
||||
10110
|
||||
10111
|
||||
10101
|
||||
01111
|
||||
00111
|
||||
11100
|
||||
10000
|
||||
11001
|
||||
00010
|
||||
01010
|
||||
1000
december_3/input.txt
Normal file
1000
december_3/input.txt
Normal file
File diff suppressed because it is too large
Load Diff
149
december_3/src/main.rs
Normal file
149
december_3/src/main.rs
Normal file
@@ -0,0 +1,149 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
|
||||
const NUMBER_OF_BITS: u8 = 4; //12
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut line_vec = Vec::new();
|
||||
//let mut gamma_bits = Vec::new();
|
||||
|
||||
let all_lines = reader.lines();
|
||||
let mut most_common_val = Vec::new();
|
||||
let mut least_common_val = Vec::new();
|
||||
|
||||
|
||||
for line in all_lines{
|
||||
let line_as_string = line.unwrap();
|
||||
line_vec.push(line_as_string);
|
||||
}
|
||||
|
||||
for i in 0..NUMBER_OF_BITS {
|
||||
let mut ones = 0;
|
||||
let mut zeros = 0;
|
||||
for l in &line_vec{
|
||||
match l.chars().nth(i.into()).unwrap() {
|
||||
'0' => {
|
||||
zeros += 1;
|
||||
},
|
||||
'1' => {
|
||||
ones += 1;
|
||||
},
|
||||
_ => println!("you should never be here"),
|
||||
}
|
||||
}
|
||||
if zeros > ones {
|
||||
print!("0");
|
||||
most_common_val.push('0');
|
||||
} else {
|
||||
print!("1");
|
||||
most_common_val.push('1');
|
||||
}
|
||||
if zeros > ones {
|
||||
print!("1");
|
||||
least_common_val.push('1');
|
||||
} else {
|
||||
print!("0");
|
||||
least_common_val.push('0');
|
||||
}
|
||||
}
|
||||
println!();
|
||||
// 101001001011 2635
|
||||
// 010110110100 1460
|
||||
|
||||
//part 2
|
||||
let mut result_vec = line_vec.to_owned();
|
||||
let mut i: u8 = 0;
|
||||
loop {
|
||||
let mut temp_vec = Vec::new();
|
||||
let most_common: char = get_most_common(i, &result_vec);
|
||||
for l in &result_vec{
|
||||
if most_common == l.chars().nth(i.into()).unwrap(){
|
||||
let l_as_string = l.to_owned();
|
||||
temp_vec.push(l_as_string);
|
||||
}
|
||||
}
|
||||
if temp_vec.len() < 2 {
|
||||
result_vec = temp_vec;
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
result_vec = temp_vec;
|
||||
}
|
||||
|
||||
println!("oxygen generator rating: {}", result_vec[0]);
|
||||
|
||||
let mut result_vec = line_vec.to_owned();
|
||||
let mut i: u8 = 0;
|
||||
loop {
|
||||
let mut temp_vec = Vec::new();
|
||||
let least_common: char = get_least_common(i, &result_vec);
|
||||
for l in &result_vec{
|
||||
if least_common == l.chars().nth(i.into()).unwrap(){
|
||||
let l_as_string = l.to_owned();
|
||||
temp_vec.push(l_as_string);
|
||||
}
|
||||
}
|
||||
if temp_vec.len() < 2 {
|
||||
result_vec = temp_vec;
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
result_vec = temp_vec;
|
||||
}
|
||||
|
||||
println!("co2 scrubber rating: {}", result_vec[0]);
|
||||
|
||||
}
|
||||
|
||||
// 101001001011 2635
|
||||
// 010110110101 1461
|
||||
// 2635 * 1461 = 3849735
|
||||
|
||||
fn get_most_common(bit: u8, in_vec:&Vec<String>) -> char {
|
||||
let mut ones = 0;
|
||||
let mut zeros = 0;
|
||||
for l in in_vec{
|
||||
match l.chars().nth(usize::from(bit)).unwrap() {
|
||||
'0' => {
|
||||
zeros += 1;
|
||||
},
|
||||
'1' => {
|
||||
ones += 1;
|
||||
},
|
||||
_ => println!("you should never be here"),
|
||||
}
|
||||
}
|
||||
if zeros > ones {
|
||||
return '0';
|
||||
} else {
|
||||
return '1';
|
||||
}
|
||||
}
|
||||
|
||||
fn get_least_common(bit: u8, in_vec:&Vec<String>) -> char {
|
||||
let mut ones = 0;
|
||||
let mut zeros = 0;
|
||||
for l in in_vec{
|
||||
match l.chars().nth(usize::from(bit)).unwrap() {
|
||||
'0' => {
|
||||
zeros += 1;
|
||||
},
|
||||
'1' => {
|
||||
ones += 1;
|
||||
},
|
||||
_ => println!("you should never be here"),
|
||||
}
|
||||
}
|
||||
if zeros > ones {
|
||||
return '1';
|
||||
} else {
|
||||
return '0';
|
||||
}
|
||||
}
|
||||
|
||||
//2735
|
||||
//1501
|
||||
8
december_4/Cargo.toml
Normal file
8
december_4/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_4"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
20
december_4/example.txt
Normal file
20
december_4/example.txt
Normal file
@@ -0,0 +1,20 @@
|
||||
7,4,9,5,11,17,23,2,0,14,21,24,10,16,13,6,15,25,12,22,18,20,8,19,3,26,1
|
||||
|
||||
22 13 17 11 0
|
||||
8 2 23 4 24
|
||||
21 9 14 16 7
|
||||
6 10 3 18 5
|
||||
1 12 20 15 19
|
||||
|
||||
3 15 0 2 22
|
||||
9 18 13 17 5
|
||||
19 8 7 25 23
|
||||
20 11 10 24 4
|
||||
14 21 16 12 6
|
||||
|
||||
14 21 17 24 4
|
||||
10 16 15 9 19
|
||||
18 8 23 26 20
|
||||
22 11 13 6 5
|
||||
2 0 12 3 7
|
||||
|
||||
601
december_4/input.txt
Normal file
601
december_4/input.txt
Normal file
@@ -0,0 +1,601 @@
|
||||
62,55,98,93,48,28,82,78,19,96,31,42,76,25,34,4,18,80,66,6,14,17,57,54,90,27,40,47,9,36,97,56,87,61,91,1,64,71,99,38,70,5,94,85,49,59,69,26,21,60,0,79,2,95,11,84,20,24,8,51,46,44,88,22,16,53,7,32,89,67,15,86,41,92,10,77,68,63,43,75,33,30,81,37,83,3,39,65,12,45,23,73,72,29,52,58,35,50,13,74
|
||||
|
||||
10 83 98 12 33
|
||||
38 68 2 99 85
|
||||
16 89 54 50 97
|
||||
31 8 17 11 76
|
||||
0 55 66 32 87
|
||||
|
||||
77 60 61 59 16
|
||||
17 46 97 9 73
|
||||
42 82 25 32 29
|
||||
48 94 52 55 50
|
||||
95 14 67 79 34
|
||||
|
||||
6 31 5 74 67
|
||||
76 89 15 78 47
|
||||
54 49 62 32 38
|
||||
35 43 61 22 58
|
||||
75 97 33 8 16
|
||||
|
||||
37 58 22 47 30
|
||||
4 86 77 42 54
|
||||
73 94 87 34 55
|
||||
72 53 14 64 88
|
||||
23 21 36 52 66
|
||||
|
||||
59 16 18 85 93
|
||||
96 56 50 53 94
|
||||
68 95 77 0 27
|
||||
47 30 88 46 65
|
||||
75 82 41 31 23
|
||||
|
||||
88 96 94 75 3
|
||||
31 26 74 90 36
|
||||
59 22 41 84 54
|
||||
6 68 37 20 93
|
||||
10 66 46 9 79
|
||||
|
||||
33 78 12 62 73
|
||||
18 37 7 44 66
|
||||
69 15 54 53 82
|
||||
98 20 30 58 81
|
||||
56 95 36 91 99
|
||||
|
||||
47 89 86 58 43
|
||||
49 72 84 94 51
|
||||
69 73 15 50 0
|
||||
46 81 76 31 61
|
||||
96 91 56 2 34
|
||||
|
||||
22 91 70 68 99
|
||||
25 28 3 42 1
|
||||
21 19 79 54 4
|
||||
97 88 49 8 78
|
||||
44 98 84 83 6
|
||||
|
||||
21 0 62 2 9
|
||||
49 81 50 66 10
|
||||
24 72 45 96 6
|
||||
51 82 17 58 91
|
||||
18 56 39 11 25
|
||||
|
||||
22 25 42 98 93
|
||||
1 26 0 67 65
|
||||
31 11 37 7 96
|
||||
28 17 40 79 12
|
||||
95 5 2 66 10
|
||||
|
||||
63 8 97 64 82
|
||||
43 12 83 1 11
|
||||
69 84 74 7 59
|
||||
25 48 38 89 62
|
||||
22 93 39 71 76
|
||||
|
||||
92 94 20 49 21
|
||||
34 41 61 98 28
|
||||
93 62 74 12 31
|
||||
63 77 87 36 55
|
||||
23 7 4 69 53
|
||||
|
||||
61 27 76 56 12
|
||||
60 7 36 33 97
|
||||
4 16 89 44 40
|
||||
51 43 75 79 28
|
||||
14 69 35 90 8
|
||||
|
||||
12 34 94 77 87
|
||||
24 61 19 23 41
|
||||
75 46 9 21 64
|
||||
88 15 40 89 86
|
||||
32 47 93 3 58
|
||||
|
||||
74 16 44 21 30
|
||||
1 11 71 97 42
|
||||
88 59 52 28 75
|
||||
58 26 23 76 8
|
||||
33 65 80 95 14
|
||||
|
||||
54 29 7 80 33
|
||||
20 18 82 26 93
|
||||
72 4 45 89 98
|
||||
99 16 8 22 34
|
||||
86 61 51 43 64
|
||||
|
||||
96 20 88 78 73
|
||||
65 84 93 79 48
|
||||
25 99 13 60 41
|
||||
37 24 82 8 89
|
||||
44 10 4 58 57
|
||||
|
||||
28 70 42 66 15
|
||||
3 35 52 49 4
|
||||
77 23 16 30 24
|
||||
67 75 8 29 47
|
||||
39 32 80 22 55
|
||||
|
||||
70 61 5 77 9
|
||||
3 23 42 86 31
|
||||
99 22 41 14 17
|
||||
93 63 25 10 30
|
||||
28 52 81 89 40
|
||||
|
||||
78 18 42 48 14
|
||||
4 95 87 64 32
|
||||
13 10 72 90 46
|
||||
68 16 57 80 77
|
||||
50 69 5 63 96
|
||||
|
||||
89 15 13 68 84
|
||||
37 79 56 97 34
|
||||
60 48 91 87 96
|
||||
32 25 78 55 11
|
||||
1 67 57 93 92
|
||||
|
||||
89 94 12 46 21
|
||||
61 67 26 40 76
|
||||
86 78 6 41 56
|
||||
35 64 28 73 98
|
||||
30 17 88 70 71
|
||||
|
||||
37 57 36 6 32
|
||||
89 26 27 22 29
|
||||
80 49 88 0 46
|
||||
70 18 50 14 19
|
||||
34 84 79 90 98
|
||||
|
||||
41 23 10 4 88
|
||||
26 55 17 71 15
|
||||
68 49 0 14 97
|
||||
27 61 31 74 99
|
||||
89 33 64 32 5
|
||||
|
||||
63 44 98 56 47
|
||||
72 2 28 89 77
|
||||
36 24 26 14 21
|
||||
7 58 32 31 86
|
||||
33 0 57 54 4
|
||||
|
||||
2 89 46 59 6
|
||||
62 67 84 95 98
|
||||
8 12 75 70 88
|
||||
45 93 38 61 47
|
||||
37 55 76 82 92
|
||||
|
||||
2 50 19 35 34
|
||||
94 0 48 75 16
|
||||
18 92 46 38 32
|
||||
65 78 22 85 77
|
||||
69 73 88 30 60
|
||||
|
||||
98 21 79 41 39
|
||||
64 1 91 7 44
|
||||
45 32 72 22 38
|
||||
78 28 97 69 33
|
||||
55 12 53 9 61
|
||||
|
||||
94 39 67 82 18
|
||||
11 86 43 92 0
|
||||
44 8 66 3 91
|
||||
62 56 38 32 89
|
||||
27 2 76 90 31
|
||||
|
||||
21 79 89 70 85
|
||||
73 76 92 15 33
|
||||
36 63 44 99 19
|
||||
35 75 88 65 3
|
||||
48 54 97 27 2
|
||||
|
||||
35 8 51 77 29
|
||||
1 11 38 67 99
|
||||
2 18 94 32 24
|
||||
54 82 21 98 7
|
||||
20 0 48 83 74
|
||||
|
||||
77 82 68 18 58
|
||||
9 78 85 59 55
|
||||
15 73 56 46 10
|
||||
80 38 26 8 96
|
||||
41 84 35 86 12
|
||||
|
||||
36 89 27 38 22
|
||||
53 46 5 84 90
|
||||
23 7 63 29 17
|
||||
92 41 97 0 43
|
||||
74 33 26 98 19
|
||||
|
||||
69 40 35 84 3
|
||||
56 49 55 2 28
|
||||
85 14 50 12 27
|
||||
65 73 6 42 23
|
||||
64 68 48 62 22
|
||||
|
||||
57 8 21 98 66
|
||||
39 92 16 95 87
|
||||
49 1 51 68 48
|
||||
46 84 17 35 80
|
||||
20 47 3 75 34
|
||||
|
||||
23 15 77 3 91
|
||||
33 58 69 66 14
|
||||
88 47 18 16 99
|
||||
62 89 86 7 67
|
||||
90 57 35 45 29
|
||||
|
||||
89 12 29 39 78
|
||||
26 52 10 47 97
|
||||
68 90 65 56 33
|
||||
63 8 13 27 42
|
||||
30 66 91 16 51
|
||||
|
||||
95 91 88 40 97
|
||||
63 54 68 26 52
|
||||
56 76 78 83 62
|
||||
13 65 90 49 94
|
||||
44 74 79 48 81
|
||||
|
||||
24 27 11 74 0
|
||||
38 56 53 25 60
|
||||
50 51 49 10 72
|
||||
76 34 52 81 9
|
||||
80 99 82 1 67
|
||||
|
||||
90 88 71 53 26
|
||||
70 19 57 61 89
|
||||
64 30 0 9 56
|
||||
4 21 62 38 82
|
||||
51 40 55 81 20
|
||||
|
||||
66 14 90 76 93
|
||||
21 57 27 55 32
|
||||
22 43 67 29 81
|
||||
49 53 39 96 79
|
||||
12 48 88 63 33
|
||||
|
||||
15 7 99 55 84
|
||||
53 80 47 75 36
|
||||
1 22 39 91 82
|
||||
13 76 40 27 81
|
||||
57 93 8 48 28
|
||||
|
||||
82 58 5 84 25
|
||||
61 19 83 22 44
|
||||
85 3 14 10 97
|
||||
35 26 79 20 73
|
||||
99 21 51 47 81
|
||||
|
||||
14 32 63 18 70
|
||||
50 91 67 1 19
|
||||
7 31 54 11 8
|
||||
51 78 35 72 77
|
||||
47 73 22 5 76
|
||||
|
||||
2 22 11 31 13
|
||||
66 21 83 94 87
|
||||
69 5 59 14 53
|
||||
95 41 90 43 92
|
||||
42 77 10 88 8
|
||||
|
||||
19 88 91 43 17
|
||||
62 83 68 94 28
|
||||
73 36 58 21 66
|
||||
55 24 90 12 77
|
||||
45 6 49 27 63
|
||||
|
||||
6 73 93 67 18
|
||||
29 33 94 24 34
|
||||
57 96 27 37 60
|
||||
92 88 81 12 16
|
||||
49 98 30 10 72
|
||||
|
||||
17 40 36 96 68
|
||||
91 38 88 9 6
|
||||
16 35 63 25 37
|
||||
81 43 78 64 52
|
||||
46 44 69 67 13
|
||||
|
||||
73 36 70 5 57
|
||||
66 55 27 54 44
|
||||
20 4 68 58 26
|
||||
96 37 76 80 47
|
||||
61 2 92 71 64
|
||||
|
||||
12 51 54 34 68
|
||||
69 99 64 44 98
|
||||
79 67 90 46 65
|
||||
31 56 45 43 30
|
||||
29 18 94 19 59
|
||||
|
||||
70 26 91 97 0
|
||||
46 56 93 80 52
|
||||
47 25 12 31 77
|
||||
95 72 36 74 2
|
||||
38 48 68 54 73
|
||||
|
||||
79 89 77 24 21
|
||||
30 14 46 11 38
|
||||
3 70 84 67 48
|
||||
45 20 40 63 35
|
||||
86 74 2 76 43
|
||||
|
||||
97 20 2 82 84
|
||||
8 92 71 88 33
|
||||
64 26 99 93 66
|
||||
30 40 28 38 73
|
||||
62 43 5 81 22
|
||||
|
||||
9 47 50 8 62
|
||||
42 1 80 21 84
|
||||
66 19 32 2 30
|
||||
76 97 85 65 45
|
||||
70 26 73 72 93
|
||||
|
||||
80 99 91 96 25
|
||||
22 76 81 62 51
|
||||
10 64 53 54 70
|
||||
55 8 49 60 1
|
||||
40 67 14 89 16
|
||||
|
||||
92 19 72 71 40
|
||||
29 22 86 43 12
|
||||
0 65 78 93 10
|
||||
54 55 42 61 82
|
||||
52 47 81 99 83
|
||||
|
||||
81 22 90 66 82
|
||||
92 56 63 79 32
|
||||
72 60 30 42 20
|
||||
91 38 10 70 13
|
||||
46 52 47 11 69
|
||||
|
||||
11 86 32 54 47
|
||||
87 38 74 41 69
|
||||
17 23 36 61 29
|
||||
97 68 62 65 83
|
||||
30 0 28 72 19
|
||||
|
||||
55 65 28 7 5
|
||||
90 93 99 48 80
|
||||
34 94 82 19 86
|
||||
49 39 69 75 71
|
||||
8 24 43 33 21
|
||||
|
||||
39 70 7 56 20
|
||||
24 67 86 45 1
|
||||
33 44 83 76 2
|
||||
46 78 17 94 48
|
||||
28 4 30 77 79
|
||||
|
||||
18 99 73 55 30
|
||||
88 92 13 97 1
|
||||
91 49 11 48 83
|
||||
94 41 5 29 72
|
||||
61 17 84 64 90
|
||||
|
||||
9 13 65 1 85
|
||||
11 20 30 86 84
|
||||
35 83 99 32 38
|
||||
41 7 6 49 58
|
||||
90 87 76 23 28
|
||||
|
||||
89 16 91 76 78
|
||||
29 26 27 3 90
|
||||
42 94 43 9 57
|
||||
59 66 80 11 24
|
||||
31 53 75 28 20
|
||||
|
||||
82 65 50 30 79
|
||||
19 53 94 17 59
|
||||
33 47 78 75 7
|
||||
84 25 80 83 76
|
||||
81 95 72 11 21
|
||||
|
||||
28 26 52 5 3
|
||||
4 59 51 32 41
|
||||
19 58 42 90 43
|
||||
22 89 39 40 24
|
||||
36 57 64 20 9
|
||||
|
||||
44 65 41 79 75
|
||||
63 76 6 51 30
|
||||
12 21 73 29 97
|
||||
42 55 54 53 25
|
||||
0 89 47 14 92
|
||||
|
||||
56 4 60 63 21
|
||||
20 50 24 77 22
|
||||
67 66 64 91 28
|
||||
36 57 68 87 98
|
||||
7 86 42 33 39
|
||||
|
||||
34 15 64 46 50
|
||||
56 7 99 69 89
|
||||
83 23 57 13 70
|
||||
86 71 85 36 98
|
||||
33 76 8 54 42
|
||||
|
||||
22 88 25 32 45
|
||||
2 21 40 11 16
|
||||
84 37 90 27 69
|
||||
51 1 89 49 15
|
||||
72 96 0 65 6
|
||||
|
||||
97 79 90 95 5
|
||||
14 96 57 40 30
|
||||
70 60 52 33 36
|
||||
10 86 28 51 7
|
||||
88 20 99 27 63
|
||||
|
||||
84 6 57 66 62
|
||||
56 80 97 55 58
|
||||
92 46 81 21 26
|
||||
99 29 27 63 87
|
||||
39 20 7 35 48
|
||||
|
||||
84 40 26 1 46
|
||||
28 42 29 5 45
|
||||
63 82 17 31 6
|
||||
30 78 2 89 67
|
||||
14 47 60 33 32
|
||||
|
||||
40 89 32 50 90
|
||||
1 5 83 41 77
|
||||
19 48 6 11 70
|
||||
78 56 93 36 73
|
||||
80 9 21 26 22
|
||||
|
||||
8 97 13 2 38
|
||||
70 61 67 55 16
|
||||
35 42 33 9 28
|
||||
26 93 86 4 65
|
||||
79 57 19 98 62
|
||||
|
||||
42 91 75 97 66
|
||||
50 12 53 52 20
|
||||
56 70 96 5 21
|
||||
89 57 83 18 17
|
||||
77 72 95 38 98
|
||||
|
||||
40 98 10 67 90
|
||||
16 7 75 23 13
|
||||
78 38 53 45 20
|
||||
0 28 87 94 25
|
||||
26 83 34 56 8
|
||||
|
||||
83 43 49 31 73
|
||||
62 54 89 12 34
|
||||
92 35 57 91 52
|
||||
58 80 20 15 90
|
||||
51 13 61 8 17
|
||||
|
||||
19 65 73 81 5
|
||||
57 71 52 51 22
|
||||
48 53 15 34 66
|
||||
63 45 96 47 49
|
||||
58 42 56 62 76
|
||||
|
||||
44 9 76 49 75
|
||||
78 51 87 39 54
|
||||
29 62 47 42 97
|
||||
48 73 50 89 84
|
||||
0 40 38 20 81
|
||||
|
||||
65 34 92 70 36
|
||||
24 54 41 31 13
|
||||
28 40 93 57 20
|
||||
19 59 89 51 77
|
||||
80 69 85 76 14
|
||||
|
||||
67 78 60 98 88
|
||||
64 46 4 84 25
|
||||
50 87 74 56 42
|
||||
59 0 7 31 61
|
||||
93 12 9 33 32
|
||||
|
||||
29 25 94 40 53
|
||||
49 77 65 27 18
|
||||
5 92 75 90 47
|
||||
46 16 82 1 21
|
||||
22 3 78 13 85
|
||||
|
||||
16 2 12 64 57
|
||||
51 28 29 46 66
|
||||
45 84 37 35 50
|
||||
90 75 34 47 39
|
||||
10 68 4 31 5
|
||||
|
||||
30 23 47 48 7
|
||||
73 16 71 12 25
|
||||
91 53 43 79 0
|
||||
81 64 35 93 37
|
||||
83 52 87 46 85
|
||||
|
||||
15 53 29 5 96
|
||||
23 61 52 36 83
|
||||
54 64 99 16 68
|
||||
60 82 90 58 13
|
||||
42 14 59 80 27
|
||||
|
||||
11 54 7 24 96
|
||||
43 32 5 95 93
|
||||
22 49 85 64 40
|
||||
51 18 39 47 34
|
||||
63 21 80 75 82
|
||||
|
||||
32 6 43 27 25
|
||||
4 20 40 59 58
|
||||
46 47 8 65 33
|
||||
12 21 29 84 2
|
||||
86 30 26 62 37
|
||||
|
||||
34 58 13 38 41
|
||||
40 53 52 54 94
|
||||
37 74 16 25 99
|
||||
22 62 11 61 51
|
||||
27 96 6 44 0
|
||||
|
||||
68 87 53 96 90
|
||||
17 49 45 13 93
|
||||
21 38 62 35 27
|
||||
56 1 65 10 33
|
||||
16 48 22 47 67
|
||||
|
||||
90 79 22 24 72
|
||||
63 65 18 12 11
|
||||
69 37 1 10 21
|
||||
73 45 64 4 8
|
||||
75 77 25 80 76
|
||||
|
||||
84 6 82 5 21
|
||||
79 62 42 78 35
|
||||
39 41 59 65 29
|
||||
25 54 7 31 93
|
||||
43 86 15 61 96
|
||||
|
||||
1 80 34 86 3
|
||||
12 49 29 7 82
|
||||
16 70 23 45 2
|
||||
17 75 52 28 13
|
||||
38 25 74 77 39
|
||||
|
||||
16 11 70 63 14
|
||||
25 61 13 84 34
|
||||
96 24 30 38 39
|
||||
75 72 59 97 91
|
||||
8 4 62 19 58
|
||||
|
||||
5 66 76 33 29
|
||||
72 92 7 87 73
|
||||
68 94 93 60 61
|
||||
21 3 10 20 89
|
||||
35 47 34 48 59
|
||||
|
||||
32 79 54 30 93
|
||||
19 45 4 26 50
|
||||
48 86 38 6 85
|
||||
25 61 66 55 51
|
||||
68 27 39 20 7
|
||||
|
||||
40 57 61 28 85
|
||||
54 96 20 99 69
|
||||
83 33 91 2 93
|
||||
92 30 53 12 16
|
||||
35 73 58 65 98
|
||||
|
||||
60 3 95 59 52
|
||||
75 89 91 96 92
|
||||
66 8 34 45 21
|
||||
6 39 2 50 55
|
||||
19 26 86 12 94
|
||||
|
||||
93 55 44 91 8
|
||||
81 89 23 77 97
|
||||
2 92 6 76 39
|
||||
21 0 56 90 51
|
||||
16 10 5 32 66
|
||||
|
||||
4 62 54 89 43
|
||||
75 22 13 10 68
|
||||
91 71 69 56 96
|
||||
55 12 53 21 39
|
||||
19 5 51 70 3
|
||||
162
december_4/src/main.rs
Normal file
162
december_4/src/main.rs
Normal file
@@ -0,0 +1,162 @@
|
||||
use std::borrow::Borrow;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
use std::vec;
|
||||
|
||||
struct Board {
|
||||
contents: Vec<Vec<u32>>,
|
||||
matched: Vec<Vec<bool>>,
|
||||
size: usize,
|
||||
won: bool
|
||||
}
|
||||
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut line_vec = Vec::new();
|
||||
|
||||
|
||||
for line in reader.lines(){
|
||||
let line_as_string = line.unwrap();
|
||||
line_vec.push(line_as_string);
|
||||
}
|
||||
|
||||
let first_line = &line_vec[0];
|
||||
let input_sequence_str = first_line.split(',').collect::<Vec<&str>>();
|
||||
let input_sequence_u32: Vec<u32> = input_sequence_str.iter().map(|x| x.parse::<u32>().unwrap()).collect();
|
||||
|
||||
let mut boards: Vec<Board> = Vec::new();
|
||||
|
||||
let mut temp_board: Vec<Vec<u32>> = Vec::new();
|
||||
|
||||
let mut final_score = 0;
|
||||
|
||||
let mut last_winning_index = 0;
|
||||
let mut last_winning_score = 0;
|
||||
|
||||
for line_nr in 2..line_vec.len() {
|
||||
let current_line = line_vec[line_nr].to_owned();
|
||||
if current_line == "" {
|
||||
let mut matched_vec = Vec::new();
|
||||
for _ in 0..temp_board.len(){
|
||||
matched_vec.push(vec![false; temp_board.len()])
|
||||
}
|
||||
boards.push(Board {contents:temp_board.to_owned(), matched:matched_vec, size : temp_board.len(), won: false});
|
||||
temp_board = Vec::new();
|
||||
} else {
|
||||
let temp_vec_str = current_line.split_whitespace().collect::<Vec<&str>>();
|
||||
let line_as_u32_vec: Vec<u32> = temp_vec_str.iter().map(|x| x.parse::<u32>().unwrap()).collect();
|
||||
temp_board.push(line_as_u32_vec);
|
||||
}
|
||||
}
|
||||
|
||||
// If there is no trailing newline the last board gets stuck in the temp_board vec
|
||||
if temp_board.len() != 0 {
|
||||
let mut matched_vec = Vec::new();
|
||||
for _ in 0..temp_board.len(){
|
||||
matched_vec.push(vec![false; temp_board.len()])
|
||||
}
|
||||
boards.push(Board {contents:temp_board.to_owned(), matched:matched_vec, size : temp_board.len(), won: false});
|
||||
|
||||
}
|
||||
|
||||
for input in input_sequence_u32{
|
||||
println!("processing {}", input);
|
||||
for i in 0..boards.len(){
|
||||
boards[i] = check_for_hit(boards[i].borrow(), input);
|
||||
print!("");
|
||||
}
|
||||
for i in 0..boards.len(){
|
||||
if check_if_won(boards[i].borrow()){
|
||||
boards[i].won = true;
|
||||
if final_score == 0 {
|
||||
final_score = calculate_score(boards[i].borrow(), input);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
let mut temp_remaining = 0;
|
||||
let mut remaining_index = 0;
|
||||
for i in 0..boards.len(){
|
||||
if !boards[i].won {
|
||||
temp_remaining += 1;
|
||||
remaining_index = i;
|
||||
}
|
||||
}
|
||||
|
||||
if temp_remaining == 0 && last_winning_score == 0{
|
||||
last_winning_score = calculate_score(boards[last_winning_index].borrow(), input);
|
||||
}
|
||||
last_winning_index = remaining_index;
|
||||
|
||||
|
||||
}
|
||||
|
||||
println!("Result score: {}", final_score);
|
||||
println!("Last winning score: {}", last_winning_score);
|
||||
}
|
||||
|
||||
|
||||
fn check_for_hit(in_board: &Board, in_number: u32) -> Board {
|
||||
let mut out_board = Board{contents:in_board.contents.to_owned(), matched:in_board.matched.to_owned(), size:in_board.size.to_owned(), won: false};
|
||||
for (index_l, line) in out_board.contents.iter().enumerate() {
|
||||
for (index_e, element) in line.iter().enumerate(){
|
||||
if *element == in_number{
|
||||
out_board.matched[index_l][index_e] = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return out_board;
|
||||
}
|
||||
|
||||
fn check_if_won(in_board: &Board) -> bool {
|
||||
let size = in_board.size;
|
||||
let matched_vec = in_board.matched.to_owned();
|
||||
|
||||
|
||||
//Check Vertical
|
||||
for column in 0..size {
|
||||
for row in 0..size{
|
||||
if matched_vec[row][column] == false {
|
||||
break;
|
||||
} else if row == size -1 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Check horizontal
|
||||
for line in matched_vec{
|
||||
for (pos, element) in line.iter().enumerate() {
|
||||
if !element {
|
||||
break;
|
||||
} else if pos == size - 1 {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
fn calculate_score(in_board: &Board, current_number: u32) -> u32 {
|
||||
let matched_vec = in_board.matched.to_owned();
|
||||
let content_vec = in_board.contents.to_owned();
|
||||
let size = in_board.size;
|
||||
let mut score = 0;
|
||||
|
||||
for line in 0..size{
|
||||
for element in 0..size{
|
||||
if !matched_vec[line][element] {
|
||||
score += content_vec[line][element];
|
||||
}
|
||||
}
|
||||
}
|
||||
return score * current_number;
|
||||
}
|
||||
8
december_5/Cargo.toml
Normal file
8
december_5/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_5"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
10
december_5/example.txt
Normal file
10
december_5/example.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
0,9 -> 5,9
|
||||
8,0 -> 0,8
|
||||
9,4 -> 3,4
|
||||
2,2 -> 2,1
|
||||
7,0 -> 7,4
|
||||
6,4 -> 2,0
|
||||
0,9 -> 2,9
|
||||
3,4 -> 1,4
|
||||
0,0 -> 8,8
|
||||
5,5 -> 8,2
|
||||
500
december_5/input.txt
Normal file
500
december_5/input.txt
Normal file
@@ -0,0 +1,500 @@
|
||||
405,945 -> 780,945
|
||||
253,100 -> 954,801
|
||||
518,300 -> 870,300
|
||||
775,848 -> 20,848
|
||||
586,671 -> 469,671
|
||||
598,20 -> 900,20
|
||||
51,975 -> 438,588
|
||||
561,456 -> 67,456
|
||||
353,135 -> 882,664
|
||||
357,873 -> 407,873
|
||||
480,247 -> 774,247
|
||||
230,895 -> 230,709
|
||||
590,738 -> 644,792
|
||||
696,821 -> 696,198
|
||||
501,461 -> 85,461
|
||||
884,88 -> 884,922
|
||||
140,780 -> 146,780
|
||||
795,208 -> 273,208
|
||||
256,185 -> 256,525
|
||||
282,196 -> 282,85
|
||||
701,133 -> 18,133
|
||||
623,548 -> 623,573
|
||||
734,895 -> 29,190
|
||||
212,944 -> 934,944
|
||||
948,504 -> 948,502
|
||||
551,613 -> 551,27
|
||||
62,54 -> 452,54
|
||||
915,851 -> 915,290
|
||||
924,843 -> 924,145
|
||||
662,412 -> 422,172
|
||||
465,87 -> 247,87
|
||||
391,91 -> 326,91
|
||||
267,572 -> 267,306
|
||||
84,505 -> 594,505
|
||||
453,383 -> 80,10
|
||||
737,891 -> 784,891
|
||||
599,339 -> 40,898
|
||||
868,962 -> 31,125
|
||||
153,661 -> 705,661
|
||||
760,74 -> 339,495
|
||||
972,72 -> 972,714
|
||||
579,636 -> 169,226
|
||||
365,218 -> 118,465
|
||||
128,906 -> 767,267
|
||||
733,165 -> 121,165
|
||||
877,99 -> 105,871
|
||||
176,917 -> 754,917
|
||||
14,14 -> 981,981
|
||||
170,958 -> 170,859
|
||||
861,25 -> 96,790
|
||||
128,143 -> 128,49
|
||||
874,367 -> 334,367
|
||||
373,434 -> 373,747
|
||||
799,946 -> 439,586
|
||||
17,923 -> 814,126
|
||||
734,192 -> 734,632
|
||||
267,280 -> 877,890
|
||||
457,500 -> 457,26
|
||||
525,679 -> 525,22
|
||||
985,64 -> 85,964
|
||||
312,411 -> 312,287
|
||||
554,860 -> 600,860
|
||||
209,163 -> 628,163
|
||||
47,30 -> 917,900
|
||||
870,948 -> 625,703
|
||||
965,980 -> 53,68
|
||||
874,631 -> 874,41
|
||||
770,29 -> 770,882
|
||||
950,988 -> 411,449
|
||||
766,900 -> 904,900
|
||||
77,23 -> 923,869
|
||||
528,151 -> 528,96
|
||||
785,468 -> 218,468
|
||||
150,932 -> 333,932
|
||||
908,846 -> 654,846
|
||||
467,220 -> 588,220
|
||||
303,437 -> 219,437
|
||||
617,71 -> 899,353
|
||||
116,311 -> 116,816
|
||||
251,165 -> 316,165
|
||||
126,897 -> 854,169
|
||||
254,473 -> 818,473
|
||||
817,265 -> 98,984
|
||||
660,492 -> 558,492
|
||||
562,117 -> 64,615
|
||||
857,808 -> 857,311
|
||||
39,641 -> 39,703
|
||||
256,981 -> 988,249
|
||||
923,175 -> 923,902
|
||||
372,800 -> 503,800
|
||||
48,339 -> 48,156
|
||||
852,476 -> 852,397
|
||||
874,190 -> 248,816
|
||||
509,629 -> 503,629
|
||||
246,17 -> 246,341
|
||||
903,961 -> 568,626
|
||||
405,740 -> 975,740
|
||||
25,10 -> 982,967
|
||||
761,287 -> 254,794
|
||||
21,514 -> 21,111
|
||||
772,350 -> 219,903
|
||||
61,56 -> 275,270
|
||||
608,197 -> 608,719
|
||||
275,30 -> 275,145
|
||||
712,601 -> 850,739
|
||||
173,205 -> 173,667
|
||||
93,644 -> 519,218
|
||||
60,48 -> 911,899
|
||||
21,975 -> 980,16
|
||||
333,602 -> 634,602
|
||||
899,374 -> 96,374
|
||||
283,209 -> 963,889
|
||||
22,20 -> 987,985
|
||||
494,66 -> 70,490
|
||||
836,876 -> 37,77
|
||||
151,530 -> 472,851
|
||||
459,531 -> 127,199
|
||||
564,489 -> 315,240
|
||||
193,341 -> 361,341
|
||||
639,680 -> 511,680
|
||||
855,217 -> 855,352
|
||||
88,909 -> 920,77
|
||||
948,318 -> 452,814
|
||||
957,967 -> 957,297
|
||||
741,172 -> 140,773
|
||||
785,528 -> 467,528
|
||||
135,658 -> 458,658
|
||||
821,653 -> 821,633
|
||||
932,137 -> 415,137
|
||||
858,638 -> 858,696
|
||||
494,495 -> 649,495
|
||||
586,261 -> 478,369
|
||||
18,680 -> 571,680
|
||||
872,233 -> 872,823
|
||||
715,935 -> 861,935
|
||||
85,251 -> 206,372
|
||||
42,972 -> 940,74
|
||||
587,955 -> 66,955
|
||||
393,466 -> 771,466
|
||||
759,744 -> 36,21
|
||||
694,90 -> 195,589
|
||||
210,456 -> 857,456
|
||||
656,476 -> 177,955
|
||||
391,224 -> 902,735
|
||||
929,802 -> 69,802
|
||||
548,395 -> 892,395
|
||||
576,838 -> 671,838
|
||||
402,412 -> 899,412
|
||||
567,601 -> 800,834
|
||||
106,386 -> 907,386
|
||||
848,349 -> 848,869
|
||||
209,392 -> 785,392
|
||||
28,105 -> 853,930
|
||||
395,432 -> 795,432
|
||||
582,570 -> 582,514
|
||||
48,410 -> 211,573
|
||||
248,617 -> 248,848
|
||||
695,174 -> 941,420
|
||||
215,651 -> 215,124
|
||||
419,555 -> 112,555
|
||||
358,975 -> 169,975
|
||||
732,247 -> 732,573
|
||||
132,983 -> 132,845
|
||||
476,110 -> 476,196
|
||||
852,437 -> 640,437
|
||||
973,42 -> 109,906
|
||||
954,797 -> 337,180
|
||||
544,233 -> 134,233
|
||||
412,150 -> 93,150
|
||||
140,296 -> 140,407
|
||||
485,875 -> 395,875
|
||||
600,942 -> 931,942
|
||||
235,677 -> 235,431
|
||||
841,745 -> 148,52
|
||||
265,803 -> 265,140
|
||||
369,597 -> 230,736
|
||||
788,745 -> 788,422
|
||||
29,677 -> 75,677
|
||||
590,669 -> 590,638
|
||||
24,23 -> 24,438
|
||||
279,476 -> 770,967
|
||||
342,186 -> 57,186
|
||||
50,49 -> 350,349
|
||||
968,40 -> 28,980
|
||||
101,101 -> 978,101
|
||||
897,48 -> 27,918
|
||||
595,232 -> 595,211
|
||||
813,982 -> 335,504
|
||||
624,41 -> 261,41
|
||||
743,102 -> 530,102
|
||||
234,814 -> 234,527
|
||||
597,242 -> 492,242
|
||||
36,84 -> 339,84
|
||||
685,729 -> 398,729
|
||||
506,733 -> 506,150
|
||||
140,788 -> 816,112
|
||||
775,816 -> 316,357
|
||||
934,394 -> 301,394
|
||||
635,983 -> 750,983
|
||||
128,29 -> 128,712
|
||||
347,348 -> 724,725
|
||||
836,367 -> 390,367
|
||||
60,718 -> 620,718
|
||||
476,786 -> 476,870
|
||||
318,490 -> 192,490
|
||||
736,608 -> 736,926
|
||||
14,79 -> 14,777
|
||||
913,245 -> 344,814
|
||||
876,775 -> 72,775
|
||||
109,273 -> 109,416
|
||||
376,64 -> 376,592
|
||||
988,11 -> 22,977
|
||||
544,602 -> 453,602
|
||||
703,585 -> 703,602
|
||||
147,976 -> 147,512
|
||||
887,681 -> 657,451
|
||||
36,913 -> 36,321
|
||||
184,723 -> 252,655
|
||||
523,905 -> 523,610
|
||||
626,106 -> 653,106
|
||||
703,211 -> 703,376
|
||||
770,175 -> 770,765
|
||||
387,628 -> 233,628
|
||||
69,890 -> 877,82
|
||||
608,751 -> 699,751
|
||||
379,958 -> 572,958
|
||||
556,555 -> 276,835
|
||||
890,681 -> 234,25
|
||||
937,792 -> 589,444
|
||||
842,296 -> 547,296
|
||||
488,638 -> 488,434
|
||||
455,823 -> 484,823
|
||||
488,610 -> 488,948
|
||||
58,829 -> 931,829
|
||||
453,481 -> 17,917
|
||||
629,473 -> 629,53
|
||||
584,512 -> 345,512
|
||||
150,92 -> 283,92
|
||||
663,692 -> 911,692
|
||||
243,835 -> 243,600
|
||||
28,26 -> 987,985
|
||||
422,388 -> 385,388
|
||||
534,798 -> 736,798
|
||||
635,394 -> 799,394
|
||||
155,895 -> 82,968
|
||||
124,926 -> 968,82
|
||||
142,431 -> 645,934
|
||||
201,977 -> 601,977
|
||||
169,322 -> 775,322
|
||||
207,251 -> 652,696
|
||||
989,975 -> 25,11
|
||||
131,89 -> 131,864
|
||||
981,989 -> 100,108
|
||||
114,84 -> 114,434
|
||||
98,713 -> 689,713
|
||||
944,262 -> 548,262
|
||||
481,568 -> 481,904
|
||||
734,883 -> 734,605
|
||||
716,687 -> 737,666
|
||||
228,155 -> 702,155
|
||||
847,675 -> 896,675
|
||||
33,121 -> 33,865
|
||||
58,211 -> 134,211
|
||||
577,154 -> 659,236
|
||||
415,958 -> 504,958
|
||||
984,359 -> 55,359
|
||||
215,22 -> 357,22
|
||||
518,232 -> 406,232
|
||||
264,950 -> 264,672
|
||||
891,549 -> 891,45
|
||||
785,328 -> 498,328
|
||||
496,815 -> 664,815
|
||||
138,55 -> 406,55
|
||||
38,823 -> 38,383
|
||||
467,184 -> 553,98
|
||||
248,794 -> 864,178
|
||||
415,561 -> 415,148
|
||||
665,726 -> 665,236
|
||||
767,777 -> 547,777
|
||||
453,860 -> 453,196
|
||||
23,645 -> 755,645
|
||||
611,985 -> 559,985
|
||||
33,978 -> 952,59
|
||||
772,36 -> 889,36
|
||||
626,521 -> 781,521
|
||||
722,502 -> 722,30
|
||||
978,946 -> 174,142
|
||||
224,901 -> 655,470
|
||||
924,142 -> 135,931
|
||||
505,171 -> 365,171
|
||||
303,888 -> 663,888
|
||||
716,838 -> 255,377
|
||||
494,390 -> 563,459
|
||||
213,595 -> 516,595
|
||||
264,436 -> 921,436
|
||||
785,749 -> 785,78
|
||||
50,50 -> 979,979
|
||||
96,72 -> 96,564
|
||||
647,278 -> 647,460
|
||||
452,656 -> 452,487
|
||||
686,145 -> 78,753
|
||||
900,973 -> 728,973
|
||||
545,137 -> 572,164
|
||||
245,211 -> 726,211
|
||||
550,606 -> 550,41
|
||||
447,25 -> 447,197
|
||||
941,581 -> 597,581
|
||||
299,486 -> 484,486
|
||||
789,67 -> 55,801
|
||||
489,842 -> 489,228
|
||||
716,452 -> 627,452
|
||||
114,735 -> 329,950
|
||||
810,157 -> 905,157
|
||||
575,397 -> 568,404
|
||||
414,221 -> 779,221
|
||||
698,363 -> 745,363
|
||||
976,498 -> 271,498
|
||||
186,324 -> 519,324
|
||||
105,777 -> 105,491
|
||||
241,58 -> 241,102
|
||||
126,883 -> 894,115
|
||||
890,853 -> 731,694
|
||||
760,713 -> 735,713
|
||||
309,409 -> 61,161
|
||||
365,263 -> 365,763
|
||||
425,591 -> 623,591
|
||||
224,233 -> 645,233
|
||||
669,872 -> 669,594
|
||||
112,773 -> 718,167
|
||||
966,168 -> 966,223
|
||||
982,527 -> 982,40
|
||||
439,688 -> 668,688
|
||||
537,685 -> 357,685
|
||||
607,164 -> 127,164
|
||||
192,894 -> 192,987
|
||||
130,196 -> 130,311
|
||||
847,987 -> 847,708
|
||||
354,66 -> 354,260
|
||||
660,441 -> 983,441
|
||||
868,282 -> 868,962
|
||||
915,272 -> 239,948
|
||||
960,970 -> 26,36
|
||||
595,837 -> 11,253
|
||||
258,533 -> 258,209
|
||||
664,802 -> 664,948
|
||||
683,117 -> 448,117
|
||||
961,104 -> 961,231
|
||||
517,427 -> 134,427
|
||||
233,451 -> 853,451
|
||||
978,412 -> 978,496
|
||||
222,71 -> 794,71
|
||||
80,343 -> 604,867
|
||||
209,104 -> 987,882
|
||||
271,232 -> 711,232
|
||||
754,329 -> 301,329
|
||||
560,937 -> 716,937
|
||||
653,194 -> 441,406
|
||||
655,506 -> 655,671
|
||||
599,336 -> 720,457
|
||||
709,895 -> 468,895
|
||||
538,432 -> 885,779
|
||||
72,231 -> 471,231
|
||||
694,131 -> 694,610
|
||||
380,37 -> 380,673
|
||||
46,921 -> 721,921
|
||||
126,823 -> 343,823
|
||||
771,617 -> 771,645
|
||||
356,734 -> 356,406
|
||||
710,504 -> 710,277
|
||||
507,65 -> 510,65
|
||||
292,913 -> 292,944
|
||||
816,640 -> 913,640
|
||||
101,132 -> 101,96
|
||||
180,21 -> 743,584
|
||||
548,231 -> 453,231
|
||||
459,248 -> 498,248
|
||||
567,637 -> 242,962
|
||||
471,418 -> 471,601
|
||||
104,822 -> 911,15
|
||||
802,583 -> 459,583
|
||||
330,681 -> 253,604
|
||||
10,431 -> 209,431
|
||||
220,776 -> 908,88
|
||||
458,508 -> 458,697
|
||||
87,803 -> 885,803
|
||||
636,372 -> 324,372
|
||||
891,528 -> 891,489
|
||||
70,274 -> 70,268
|
||||
255,587 -> 976,587
|
||||
498,69 -> 498,250
|
||||
783,838 -> 48,838
|
||||
864,344 -> 968,240
|
||||
323,734 -> 234,734
|
||||
657,347 -> 657,410
|
||||
661,682 -> 48,682
|
||||
344,815 -> 344,132
|
||||
137,878 -> 503,878
|
||||
927,975 -> 982,920
|
||||
753,964 -> 16,227
|
||||
539,957 -> 539,48
|
||||
314,651 -> 698,651
|
||||
925,653 -> 271,653
|
||||
861,518 -> 967,518
|
||||
846,126 -> 41,931
|
||||
103,409 -> 118,394
|
||||
327,185 -> 874,732
|
||||
716,930 -> 716,40
|
||||
315,702 -> 246,702
|
||||
130,377 -> 268,377
|
||||
845,978 -> 39,172
|
||||
147,977 -> 147,725
|
||||
762,660 -> 606,660
|
||||
871,186 -> 132,186
|
||||
388,320 -> 388,584
|
||||
302,410 -> 15,410
|
||||
336,234 -> 336,673
|
||||
331,208 -> 225,208
|
||||
95,565 -> 315,785
|
||||
843,563 -> 843,640
|
||||
521,378 -> 118,378
|
||||
963,17 -> 95,885
|
||||
862,487 -> 974,487
|
||||
874,402 -> 703,402
|
||||
692,689 -> 692,237
|
||||
947,635 -> 331,635
|
||||
540,417 -> 737,220
|
||||
770,161 -> 224,161
|
||||
721,831 -> 721,424
|
||||
10,411 -> 10,87
|
||||
11,985 -> 986,10
|
||||
465,972 -> 873,972
|
||||
844,753 -> 676,753
|
||||
181,27 -> 181,105
|
||||
450,675 -> 333,558
|
||||
578,286 -> 578,509
|
||||
87,363 -> 274,363
|
||||
892,119 -> 346,665
|
||||
363,331 -> 363,22
|
||||
508,424 -> 508,53
|
||||
371,145 -> 669,145
|
||||
109,761 -> 343,761
|
||||
328,804 -> 328,570
|
||||
411,741 -> 411,269
|
||||
30,139 -> 915,139
|
||||
912,736 -> 44,736
|
||||
555,884 -> 672,884
|
||||
433,427 -> 19,841
|
||||
793,796 -> 505,508
|
||||
737,554 -> 312,979
|
||||
726,231 -> 568,231
|
||||
954,479 -> 255,479
|
||||
33,365 -> 262,365
|
||||
677,608 -> 401,608
|
||||
245,620 -> 828,37
|
||||
295,274 -> 295,10
|
||||
906,106 -> 906,263
|
||||
682,719 -> 118,155
|
||||
208,859 -> 634,859
|
||||
739,103 -> 323,103
|
||||
360,142 -> 13,489
|
||||
131,553 -> 859,553
|
||||
483,308 -> 483,124
|
||||
776,720 -> 776,259
|
||||
528,327 -> 651,450
|
||||
423,223 -> 794,223
|
||||
898,698 -> 898,315
|
||||
488,824 -> 48,824
|
||||
164,971 -> 773,362
|
||||
975,850 -> 687,850
|
||||
504,810 -> 795,810
|
||||
562,281 -> 29,814
|
||||
639,574 -> 684,529
|
||||
417,800 -> 404,800
|
||||
335,844 -> 335,907
|
||||
17,41 -> 824,848
|
||||
644,220 -> 470,220
|
||||
304,944 -> 947,944
|
||||
122,807 -> 122,257
|
||||
308,553 -> 308,819
|
||||
22,672 -> 22,386
|
||||
837,675 -> 275,113
|
||||
716,650 -> 482,650
|
||||
212,350 -> 212,105
|
||||
213,594 -> 213,119
|
||||
431,375 -> 528,278
|
||||
499,741 -> 58,741
|
||||
600,291 -> 600,955
|
||||
905,205 -> 326,205
|
||||
584,152 -> 584,871
|
||||
49,153 -> 883,987
|
||||
818,822 -> 69,822
|
||||
938,286 -> 938,832
|
||||
75,380 -> 956,380
|
||||
986,424 -> 450,960
|
||||
736,470 -> 736,853
|
||||
872,988 -> 371,988
|
||||
102,203 -> 102,123
|
||||
518,338 -> 518,360
|
||||
819,263 -> 328,754
|
||||
952,242 -> 178,242
|
||||
94
december_5/src/main.rs
Normal file
94
december_5/src/main.rs
Normal file
@@ -0,0 +1,94 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
use std::vec;
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut lines: Vec<((u32, u32),(u32, u32))> = Vec::new();
|
||||
let mut max_val: u32 = 0;
|
||||
|
||||
let mut field: Vec<Vec<u32>> = Vec::new();
|
||||
|
||||
let mut danger_points = 0;
|
||||
|
||||
for line in reader.lines(){
|
||||
let line_as_string = line.unwrap();
|
||||
let split_string = line_as_string.split(" -> ").collect::<Vec<&str>>();
|
||||
let origin = split_string[0].split(",").collect::<Vec<&str>>();
|
||||
let dest = split_string[1].split(",").collect::<Vec<&str>>();
|
||||
let x1 = origin[0].parse::<u32>().unwrap();
|
||||
let y1 = origin[1].parse::<u32>().unwrap();
|
||||
let x2 = dest[0].parse::<u32>().unwrap();
|
||||
let y2 = dest[1].parse::<u32>().unwrap();
|
||||
|
||||
if origin.iter().max().unwrap().parse::<u32>().unwrap() > max_val {
|
||||
max_val = origin.iter().max().unwrap().parse::<u32>().unwrap();
|
||||
}
|
||||
if dest.iter().max().unwrap().parse::<u32>().unwrap() > max_val {
|
||||
max_val = dest.iter().max().unwrap().parse::<u32>().unwrap();
|
||||
}
|
||||
|
||||
|
||||
lines.push(((x1,y1),(x2,y2)))
|
||||
}
|
||||
|
||||
max_val += 1;
|
||||
|
||||
for _ in 0..max_val {
|
||||
field.push(vec![0; max_val as usize]);
|
||||
}
|
||||
|
||||
for line in lines {
|
||||
let x1 = (line.0).0 as usize;
|
||||
let y1 = (line.0).1 as usize;
|
||||
let x2 = (line.1).0 as usize;
|
||||
let y2 = (line.1).1 as usize;
|
||||
|
||||
if x1 == x2 {
|
||||
for y in y1.min(y2)..y2.max(y1)+1 {
|
||||
field[y][x1] += 1;
|
||||
}
|
||||
} else if y1 == y2{
|
||||
for x in x1.min(x2)..x2.max(x1)+1 {
|
||||
field[y1][x] += 1;
|
||||
}
|
||||
} else {
|
||||
let mut x_vec = Vec::new();
|
||||
let mut y_vec = Vec::new();
|
||||
|
||||
for i in 0..(x1 as i32 - x2 as i32).abs() + 1 {
|
||||
if x1 < x2 {
|
||||
x_vec.push(x1 + i as usize);
|
||||
} else {
|
||||
x_vec.push(x1 - i as usize) ;
|
||||
}
|
||||
}
|
||||
|
||||
for i in 0..(y1 as i32 - y2 as i32).abs() + 1 {
|
||||
if y1 < y2 {
|
||||
y_vec.push(y1 + i as usize);
|
||||
} else {
|
||||
y_vec.push(y1 - i as usize) ;
|
||||
}
|
||||
}
|
||||
|
||||
let iter_len = (y1 as i32 - y2 as i32).abs() as usize;
|
||||
for i in 0..iter_len + 1{
|
||||
field[y_vec[i]][x_vec[i]] += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for i in 0..max_val as usize{
|
||||
for j in 0..max_val as usize {
|
||||
if field[i][j] > 1 {
|
||||
danger_points += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
println!("Dangerpoints: {}", danger_points);
|
||||
}
|
||||
8
december_6/Cargo.toml
Normal file
8
december_6/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_6"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
1
december_6/example.txt
Normal file
1
december_6/example.txt
Normal file
@@ -0,0 +1 @@
|
||||
3,4,3,1,2
|
||||
1
december_6/input.txt
Normal file
1
december_6/input.txt
Normal file
@@ -0,0 +1 @@
|
||||
3,5,1,2,5,4,1,5,1,2,5,5,1,3,1,5,1,3,2,1,5,1,1,1,2,3,1,3,1,2,1,1,5,1,5,4,5,5,3,3,1,5,1,1,5,5,1,3,5,5,3,2,2,4,1,5,3,4,2,5,4,1,2,2,5,1,1,2,4,4,1,3,1,3,1,1,2,2,1,1,5,1,1,4,4,5,5,1,2,1,4,1,1,4,4,3,4,2,2,3,3,2,1,3,3,2,1,1,1,2,1,4,2,2,1,5,5,3,4,5,5,2,5,2,2,5,3,3,1,2,4,2,1,5,1,1,2,3,5,5,1,1,5,5,1,4,5,3,5,2,3,2,4,3,1,4,2,5,1,3,2,1,1,3,4,2,1,1,1,1,2,1,4,3,1,3,1,2,4,1,2,4,3,2,3,5,5,3,3,1,2,3,4,5,2,4,5,1,1,1,4,5,3,5,3,5,1,1,5,1,5,3,1,2,3,4,1,1,4,1,2,4,1,5,4,1,5,4,2,1,5,2,1,3,5,5,4,5,5,1,1,4,1,2,3,5,3,3,1,1,1,4,3,1,1,4,1,5,3,5,1,4,2,5,1,1,4,4,4,2,5,1,2,5,2,1,3,1,5,1,2,1,1,5,2,4,2,1,3,5,5,4,1,1,1,5,5,2,1,1
|
||||
48
december_6/src/main.rs
Normal file
48
december_6/src/main.rs
Normal file
@@ -0,0 +1,48 @@
|
||||
use std::{fs::read_to_string};
|
||||
|
||||
const ITERATIONS: u32 = 256;
|
||||
|
||||
fn main() {
|
||||
let input_char_vec = read_to_string("./input.txt").expect("ERROR reading file");
|
||||
let split_input = input_char_vec.split(",").collect::<Vec<&str>>();
|
||||
let starting_fishes: Vec<u8> = split_input.iter().map(
|
||||
|x| x.parse::<u8>().unwrap()
|
||||
).collect();
|
||||
|
||||
let mut fish: Vec<u64> = vec![0,0,0,0,0,0,0,0,0];
|
||||
|
||||
for fi in starting_fishes{
|
||||
fish[fi as usize] = fish[fi as usize] + 1;
|
||||
}
|
||||
|
||||
print_fish(&fish, -1);
|
||||
|
||||
for _i in 1..ITERATIONS + 1 {
|
||||
let zero_fish = fish[0];
|
||||
|
||||
for timer in 1..=8 {
|
||||
fish[timer-1] = fish[timer];
|
||||
}
|
||||
|
||||
fish[6] = fish[6] + zero_fish;
|
||||
fish[8] = zero_fish;
|
||||
print_fish(&fish, _i as i32);
|
||||
}
|
||||
|
||||
let mut sum: u128 = 0;
|
||||
for f in fish {
|
||||
sum += f as u128;
|
||||
}
|
||||
println!("Final Number of Fish: {}", sum);
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn print_fish(fish: &Vec<u64>, iteration: i32){
|
||||
let fish_copy = fish.to_owned();
|
||||
print!("Iteration: {}, Fish: ", iteration);
|
||||
for f in 0..fish_copy.len() {
|
||||
print!("{},{} ", f, fish_copy[f]);
|
||||
}
|
||||
print!("\n");
|
||||
}
|
||||
8
december_7/Cargo.toml
Normal file
8
december_7/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_7"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
1
december_7/example.txt
Normal file
1
december_7/example.txt
Normal file
@@ -0,0 +1 @@
|
||||
16,1,2,0,4,2,7,1,2,14
|
||||
1
december_7/input.txt
Normal file
1
december_7/input.txt
Normal file
@@ -0,0 +1 @@
|
||||
1101,1,29,67,1102,0,1,65,1008,65,35,66,1005,66,28,1,67,65,20,4,0,1001,65,1,65,1106,0,8,99,35,67,101,99,105,32,110,39,101,115,116,32,112,97,115,32,117,110,101,32,105,110,116,99,111,100,101,32,112,114,111,103,114,97,109,10,76,39,523,252,920,699,184,945,605,1243,71,604,51,245,1743,833,45,337,1928,224,547,283,413,1264,199,3,75,153,1418,1091,886,1578,1718,228,1679,775,585,98,682,108,1420,223,341,1030,58,8,505,348,7,162,492,125,271,500,495,172,639,313,1073,60,117,210,345,60,357,1061,114,11,768,19,1009,16,49,242,82,461,659,464,672,669,1010,625,148,779,79,447,159,227,419,1105,481,684,742,211,1633,72,554,1237,148,1039,840,302,291,51,693,83,62,337,27,696,65,1146,912,6,75,233,748,844,102,1300,621,1148,77,384,194,863,1305,1501,1193,811,1496,245,109,78,372,719,535,38,444,1245,85,545,1155,147,265,31,699,175,93,1165,645,4,1241,630,483,584,1749,927,1012,571,179,112,425,13,359,269,34,753,1278,414,637,55,155,96,134,232,545,90,169,7,485,25,353,78,19,52,1671,211,53,138,278,87,297,392,743,81,162,612,663,286,231,144,102,1396,574,507,1077,262,12,1047,181,1503,91,660,827,294,173,324,971,862,86,1428,684,440,163,715,1535,231,597,958,1023,1088,1646,617,1696,219,802,149,614,1412,137,35,368,78,259,280,920,52,452,741,109,553,360,151,991,1317,1064,72,252,429,581,286,450,72,50,18,720,598,422,645,349,655,533,1790,644,197,1506,401,332,733,780,276,131,131,606,948,80,1205,85,847,79,194,517,394,3,1234,643,752,121,354,499,20,99,195,194,1401,1050,40,183,1625,3,646,221,598,27,1041,693,527,82,767,495,1338,70,580,178,1473,375,960,66,279,213,836,572,1262,1118,969,275,249,657,1659,590,60,528,177,1463,347,281,481,107,278,412,47,1893,683,717,33,1652,284,317,873,727,119,143,343,88,133,521,1023,52,236,121,7,193,1,66,121,294,156,131,169,52,300,64,640,120,958,130,947,1549,43,580,498,290,492,1047,1264,46,431,1649,607,198,663,129,339,1623,157,62,363,71,898,449,437,803,798,531,80,14,180,1043,828,404,226,186,203,1087,597,1365,457,1371,320,198,66,1046,46,428,1390,78,798,457,443,659,130,212,99,194,30,1518,226,109,350,480,773,117,162,1052,740,320,1090,340,616,1125,78,1006,597,1144,76,583,41,13,674,296,100,736,943,909,948,869,1283,665,68,1107,1127,312,35,940,1250,1240,148,212,188,24,907,313,185,17,412,897,89,379,100,44,601,22,169,784,1232,1262,210,147,185,704,294,157,417,1414,496,525,322,416,438,587,1425,268,939,14,274,598,591,55,31,87,63,14,392,8,423,281,737,634,195,202,275,38,1,278,852,53,1120,585,4,754,619,288,7,10,300,214,263,936,454,185,17,73,283,316,520,407,125,990,411,455,50,725,1431,455,33,261,245,383,127,2,303,98,1574,82,24,550,424,591,263,684,1339,466,519,1098,1100,455,216,1544,665,706,1343,95,131,432,899,993,346,11,185,183,499,704,1579,110,233,41,21,220,693,938,963,4,590,126,199,15,36,1056,1250,1095,49,306,1350,1215,599,162,11,746,5,638,907,166,1486,339,397,1374,903,321,506,196,732,3,76,1269,1238,629,1496,974,1424,30,685,375,260,272,1230,82,30,854,428,24,11,961,245,873,6,1430,119,228,188,131,1395,278,34,88,268,1072,94,380,1203,4,89,55,849,630,269,1079,608,568,1265,328,1008,130,28,670,737,128,806,119,51,47,59,108,1158,102,375,26,122,387,517,231,320,25,591,140,143,474,21,1051,412,84,1501,5,211,24,366,454,2,196,127,1098,592,103,1331,1004,924,605,308,103,1408,223,205,270,53,90,1309,119,979,929,1277,575,394,146,194,3,1855,46,1327,492,1224,884,367,218,1068,89,493,210,1128,220,385,804,668,496,1202,308,262,671,166,13,512,111,840,508,1357,149,792,748,439,1001,1705,58,232,104,68,115,585,678,69,795,104,505,577,564,213,256,64,608,1134,359,17,68,123,776,680,553,198,652,1058,1575,500,797,550,325,32,529,299,207,159,490,600,798,25,473,127,683,813,1347,162,90,231,220,933,2,1023,250,419,39,1049,1315,1179,1264,339,285,84,234,209,781,1293,49,177,118,618,662,126,922,219,222,909,460,811,25,75,223,7,227,613,918,121,238,1016,110,220,1101,360,321,1670,638,170,687,1567,289,433,842,685,1252,470,113,83,163,63,3,710,13,1164,917,16,191,1169,392,213,426,151,1182,107,167,1071,538,1242,1247,116,117,1638,675,498,570
|
||||
33
december_7/src/main.rs
Normal file
33
december_7/src/main.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use std::{fs::read_to_string};
|
||||
|
||||
fn main() {
|
||||
let input_char_vec = read_to_string("./input.txt").expect("ERROR reading file");
|
||||
let split_input = input_char_vec.split(",").collect::<Vec<&str>>();
|
||||
|
||||
let mut min_fuel = u32::MAX;
|
||||
let mut cheapest_position: u32 = 0;
|
||||
|
||||
let crab_positions: Vec<u32> = split_input.iter().map(
|
||||
|x| x.parse::<u32>().unwrap()
|
||||
).collect();
|
||||
let max_depth = crab_positions.iter().max().unwrap().to_owned();
|
||||
|
||||
|
||||
for test_target_depth in 0..=max_depth {
|
||||
let mut needed_fuel_for_depth = 0;
|
||||
for crab in crab_positions.iter() {
|
||||
let distance = (test_target_depth as i32 - crab.to_owned() as i32).abs() as u32;
|
||||
let mut needed_fuel = 0;
|
||||
for d in 0..=distance {
|
||||
needed_fuel += d;
|
||||
}
|
||||
needed_fuel_for_depth += needed_fuel;
|
||||
}
|
||||
if needed_fuel_for_depth < min_fuel {
|
||||
min_fuel = needed_fuel_for_depth;
|
||||
cheapest_position = test_target_depth;
|
||||
}
|
||||
}
|
||||
|
||||
println!("Cheapest Postion is {} with a fuel usage of {}", cheapest_position, min_fuel);
|
||||
}
|
||||
8
december_8/Cargo.toml
Normal file
8
december_8/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_8"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
10
december_8/example.txt
Normal file
10
december_8/example.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
be cfbegad cbdgef fgaecd cgeb fdcge agebfd fecdb fabcd edb | fdgacbe cefdb cefbgd gcbe
|
||||
edbfga begcd cbg gc gcadebf fbgde acbgfd abcde gfcbed gfec | fcgedb cgb dgebacf gc
|
||||
fgaebd cg bdaec gdafb agbcfd gdcbef bgcad gfac gcb cdgabef | cg cg fdcagb cbg
|
||||
fbegcd cbd adcefb dageb afcb bc aefdc ecdab fgdeca fcdbega | efabcd cedba gadfec cb
|
||||
aecbfdg fbg gf bafeg dbefa fcge gcbea fcaegb dgceab fcbdga | gecf egdcabf bgf bfgea
|
||||
fgeab ca afcebg bdacfeg cfaedg gcfdb baec bfadeg bafgc acf | gebdcfa ecba ca fadegcb
|
||||
dbcfg fgd bdegcaf fgec aegbdf ecdfab fbedc dacgb gdcebf gf | cefg dcbef fcge gbcadfe
|
||||
bdfegc cbegaf gecbf dfcage bdacg ed bedf ced adcbefg gebcd | ed bcgafe cdgba cbgef
|
||||
egadfb cdbfeg cegd fecab cgb gbdefca cg fgcdab egfdb bfceg | gbdfcae bgc cg cgb
|
||||
gcafb gcf dcaebfg ecagb gf abcdeg gaef cafbge fdbac fegbdc | fgae cfgab fg bagce
|
||||
200
december_8/input.txt
Normal file
200
december_8/input.txt
Normal file
@@ -0,0 +1,200 @@
|
||||
ecdbfag deacfb acdgb cdg acdbf gdfb efacdg gd cagdbf beacg | cdg dcebgaf gbdf bdacg
|
||||
fadecg gdbecaf agbfd fgdcb gab ebagdf feabcg deab gdefa ab | adfbg ab fcgdbae bfgecda
|
||||
cgebad edfagcb fg fedg ebfca gcefb fcedgb dbagcf cgf cdbeg | cfg acfbe bcgdafe dgeafcb
|
||||
bgcde cbefg gd dbeafc afbcgde bedgca gacd dbg cedba fbegda | agfcebd adgfbce dgb fgceb
|
||||
gadcbe gcade debfac fdagce egdbf cfedg fbgcade gafc dcf fc | fcga eacfdg gfca fdcbea
|
||||
dbgcae gdeaf cefga cfa dcbgfa cgfabe cefb cf ebfgcda acgbe | gebacdf fcgdeab bacdge cfeb
|
||||
fgde efc dacgf cbdgfa fe abdcfe afdbecg gaefdc gcfae abceg | ef agdcbf bfdagec efdg
|
||||
egfacd bfcdeg ac facbg acbe cfa fbgace fgecb gfdba fbdcgae | ac ca ca fgeacb
|
||||
acefg dae dfbec abfcedg cfdea dgeafc ad dfag eacgbd bcagfe | dfag gfad dgfa beagfcd
|
||||
gae cabfgd fbcag ecbgad gfec ge agbfe gdefbca bfeda cfbgea | geabf gecf efgc gafbc
|
||||
efdgabc bda gceadb gafbec aedbf da cadf cbaef badfec gdfbe | efbda dba adcf da
|
||||
dgbaec gcade feacd bcfgae fabcd edfg ef agdfcbe gdefca fea | gedf aegfcdb edagc cefdgba
|
||||
cf adbfc bfagd gdaefc cgdefab gfbc gdacbf caf eacdb fdeagb | fgcb faedcg cbfg gcafbde
|
||||
bg cabg cdfge efbacg cebadf dgeafb fcebg gbe cabef egdbfac | gb bge cgba ecbfa
|
||||
dgfcabe geadfc gbadf cgd gbedcf acdgf dfbcea agce cg dfeac | cg agcfd aegc cdg
|
||||
gcfdae bcgde bdf gfcaedb bafc abfdcg agdfc cbgdf bf beafdg | fbd bafc cafb dbfcga
|
||||
fgab fbedca fgead fg bfgead efadb gefcdb defgcab fdg gadec | cbedfg abgf agfebd gabfcde
|
||||
begda fgbdeac gecf cgd dgeac efadc fbecda cegadf cg fabgcd | adgfbec cgd gdc dgfcaeb
|
||||
gcbfe gacdef eadbgc eabcf cbg dgfcbe bg dfeagcb dfgce bfdg | gbc bfgd bcg bafce
|
||||
efcbd ecabgd cbdga cfaedbg fcabdg deg ebga eg gdceb aegfcd | acgdbe ge aecdfgb fagdec
|
||||
gdeba afb cgdfab gfacebd gafe fa fbedc dfbega dbecag ebdaf | cagfdb eacdbgf bdefagc ecdfb
|
||||
fcbgdae egfbc fdbac dgcaef fbcdag fgcbd aecfdb dcg bgda gd | dbag dg afcegd cgd
|
||||
dgcea agbedcf ed agcef acgbd dagfbc gbed ecbgad dae bdaefc | begd ed dea ead
|
||||
efdbac bedcgfa agcde cdgfea cg bgaed dcg efgc faced gdcfab | dafbec fdacgbe fgdace gadeb
|
||||
bdgae acdegb adgfbe agc gbcaedf gc agdfec abecg ecfab cbgd | aebgd cg cg gdbc
|
||||
abgcef ebgcf badgef cfgdbae cfagb eb gbe cfedg dbafgc baec | beac agbcf be ebg
|
||||
dca cabedg acbf aedcf agcdebf daegf gefbcd efdcba ca debfc | cfba agcbefd ac cbeagd
|
||||
bf gfbeca cbaef adfgbc bfc gbef aegbc gcafebd bagced acdef | fcb gefb bfeac ebgfac
|
||||
gcbaefd fg cfagbd bafdc bceafg gfbcd fgb dafg dbafce ebgcd | fg gf adgf gafd
|
||||
gadbf aefbg egfd efb dgfbea cbfeda cbega ef agbefcd gdcabf | gfde ef gdfe gbfae
|
||||
egbdfc gecbfa dfgea egcfb bea ba bcag fabcde gacfdeb gafbe | agbc bdcagef ba dfgea
|
||||
gfdce afged dcgbef adcgbef dbage agf gcfdae gbadfc cefa fa | dfcgab bdgae gaf gaf
|
||||
fadgec bdaegc fedag cd bfdaeg dac agbfdce efcd cgbaf dfacg | bdgcaef gfedca cda abcgf
|
||||
afebgc eac agfcb fdbce fbcdag faegbdc cafegd gabe cbeaf ea | ae eca gadefc cfdbega
|
||||
gcdb db ebgacfd deb gedca efacgd cabed ebcfa decabg eabdgf | dgecfba fabdecg aecdgfb fegcbad
|
||||
cgefd gd edcfbg dfbgca fdg cdabef fadcgeb dbge bdcfe caegf | dgbfce gbde degacfb edbcf
|
||||
eadgb fegbd faebcg bdecga agb cbad cbdaefg aefgdc ba dgcea | egabcdf ba agb deagbcf
|
||||
cedga ab fdgeba gfdeb fbga eafdgbc dbgae dcgfeb dab ebcfad | agfb dbcfage ab gfba
|
||||
efdacb fabegc dbgfcae gce ceagf gcba gc gebfdc efadg afcbe | agbc dabfce fgcbde dfega
|
||||
bfdcga debgf fde gfeadb de dabfce fbadg ebcgf dega bfaegdc | cefbdga dega dgbfa cgfeb
|
||||
efagbcd gafbed ab gcdfab cgbde cabf cabdg gafdc bda gaefcd | cfba adb egdcb bad
|
||||
fcbe fcagde bc fcbgd fdgbec fdgab degcf bcadfeg gdeacb cbg | fbagcde efdbcag gdfba abgfdce
|
||||
bdfac cedfa cabdgf bdgafe cdfbega dcabge fba fgbc bf adcbg | gabcfd afcdb beadcgf eadcgb
|
||||
cb edcfa aedbc dgbfea bdc cgeb adgfbec edagb cfbagd cgadbe | bdc cedba bfgceda bc
|
||||
fdbca badgec gbf cgaeb gf fcebgda bfgac dafbge cafbge gcef | baegc gfb fbg gbf
|
||||
dbafce daecb bgdca edbgfa abg egcdab ecga cgdbeaf dcbgf ga | bag ga cage cfbgd
|
||||
eacfbgd cbagdf dbegcf edac fgceda gaefc cgfed gbefa ca fca | faebg bagfe gfabced acf
|
||||
fde edbca cdgfba ef gadfebc bfagd efdba bfge efabgd edgcfa | fegb bacgefd gbef bgdafc
|
||||
bcgdf gbdeca ebcgfa fcgaedb agdfb dfce cfg fc ebdfgc cedgb | cfg cf cgf cedgfb
|
||||
bfega cafdbe adfcg dfabgec fdb db dagbf gaefbc afebdg bged | bfd gdeb gbed bfdagec
|
||||
facgbe gbdefc egfcd ceadg efdb cef dbfcga bdgcf ef fgdaecb | bdfegc fe edfb cef
|
||||
bfad dagbc cbd fgedbc dgcea degbafc dgbacf agbfc bd cgfaeb | db dcgafbe dacgbf dfba
|
||||
cdbae acfe gcfadeb ead ae degafb bfcdga beadfc bcdge acbfd | fdebcag dfbac ae ea
|
||||
bdgfac ga gfae cga bceadfg agdec fcead bgdce afdebc eadgfc | cga ga faeg facdbeg
|
||||
af afb bcdae ecbfg feabc cdfa bgedac egdafb fcadbe eacbdfg | cabef afb gecfb cagedb
|
||||
abgcde fbd bdeaf df cdeagbf dbgfae facbe dbage cefbdg gafd | dgbacef df febdcg df
|
||||
egdbaf bcafg gedab fe efg ecafgdb bcgdae gacfde bgaef ebdf | bfedga ef cfgaedb bdaeg
|
||||
bfe ef fgebadc deagb feadb caef cegdfb cfbad ebacdf cdfabg | cdabf fcedba dcgbaf afgbecd
|
||||
dec gacfd geac ebgfd ce fdegcab edacfg dfceab bdgafc edfgc | cega geac dce ceag
|
||||
cbfdge cebag efa febgda gbdef fa dfag agfbe fdaecb befdacg | febga baegcfd aefbcd agdf
|
||||
fgdcba bdcaef gaf bcga dgfac ga gdcef cfdab gfdeba gfbceda | cabfd ga gfa cgfad
|
||||
gdaef fabdceg fgdcba gcd acbfd cbfg cgdeab dfgca cdefab cg | begcad fgcb fegda dacbfg
|
||||
efbdg gfad bfadgce deafb da fbaec ead debcfg bdafge ecdbag | acgdfbe dea eda bafgdce
|
||||
gcb efcadb cgfdb bg dbag gbfdeac cagbdf bcadf egfdc abecgf | cagfbd dfacgbe bg bgda
|
||||
ab fedba ceagdbf dgbef afcde bdca cgeabf afbecd aeb aegcdf | cbda egafcb abe dfcea
|
||||
acgbde bcag fcbged bec dfeab ebadc bc ceagbdf gdaecf aegdc | abcde gcba ebc ecb
|
||||
bacgfed ecafgb gefbc agfedc fbeag fegdba fcg dcgbe fc bcaf | gebaf facb gbefca cegbfda
|
||||
dfebgca daceg beadgc bcgda gebd bag fgcade gcfeab gb cadfb | dbge gdeac bag acdgb
|
||||
cefg bfcda eacgbd bdfcg cgedfb geafdb cg cdg fegbd fceagbd | fcdgb gcdbf cdbfg cg
|
||||
febc cgdaebf gedbf bf fgade fdcbeg bdagcf bgcade cgbed gfb | gfdbe fb cbegd ebdfg
|
||||
ed bacdge dafgbce gaedb cbgafe fabgd deb cbgae gdec efbdca | deb ed degba acbgdef
|
||||
gcfdba gbadf cb dbgcae cefda bgadecf efbagd abc fcgb afcbd | cb bfcg cdeabg cbfg
|
||||
bfcedg bcedaf bfecgad efbad aefc ce degbaf bce aecbd cgbda | bafdce acefdbg dbfecg cbe
|
||||
bf cdbef bef gcfb ecgadbf debfcg bgadef cbdea afecgd efcgd | gfedcba gedfbc edbca efgbda
|
||||
becgaf fbedcg dgbef defcb gbf begda cfdgeba dfbace dgcf fg | degab fgcd gbade gdfeb
|
||||
fbecdag edafc ebdfc aecb fabcgd bfc bc ebdacf cgeafd bgfde | bc fcb cb eabc
|
||||
bdegfa daefb dgbacf dcfagbe cdeab fgeab efdg gfcbae fd adf | afd eabcfdg adf df
|
||||
efcabd gdfec bgdcae acegb db cegdb dbag deb bfgace fadbceg | deb bed gacebd gcedb
|
||||
adb bdeagfc adgce cfdbe fbae ebacd cagfdb bdcgef ba adbcef | dab edfcagb ab aebf
|
||||
caed cga dgceb edfbcag gcaeb bgaef ca gbecad gdcbaf cedfgb | cdebfg eacgb gac dcegb
|
||||
cdbeag bagfc aef dbeagfc fabdec bedf gcfeda febac fe baced | efbd afe acdegb cadebf
|
||||
aecfd cbedf bd cbafgd ecgfdab dbcgef gebd aebgfc bcfge dbc | dbc dbc fbgaec dbc
|
||||
cfdgae fgacd ga dbcfa bgfced dag gfedc daecbg gafe ecgafbd | dgfca cfadg acefdbg ag
|
||||
degba gecbad gbcfead deafgb gafedc gec gbdc ebcag cg cfeba | gce afecb gce gce
|
||||
debf gcfdb ecd dgbcaf eabcg ed dgfcbe agcdfe bgedc gbcafed | cgdfaeb gcbfd dacbfg fbed
|
||||
bg gbed abceg cegfa fgaebcd cbgadf bga decbaf gedcab acdeb | cadebf gba abg abcegd
|
||||
cafbdg bfaeg fgedab bgafecd gab befcg adbe ecagdf edfag ba | beda afebcdg eadb dfecagb
|
||||
fdebc ge edbcaf fbdagec dfebg cegd gcfdeb gbfaec dbgaf beg | ebg bge ge dceg
|
||||
becad gbcdafe egcdfb eafcb degcb fbcgda agde adb badgec ad | facbgd afceb fbeca badgfc
|
||||
gdfac fadgbec cef ec bdgfe agfceb fcdeg gefcbd defgab edcb | abgedf eadcbfg dbgecfa fgebdc
|
||||
ebfcdg cgdbaf gdbfc bdec debfg febga edfgacb def facgde de | gfcbad cebd ebcd fdgcb
|
||||
feg faedc afdebg ge bgcafe gdcabf edgb gdfea dfbag efdbacg | gedb eagdf egbd gfbad
|
||||
eagdc gabedc cebdf gfc gadbfc edfcbga fcegd gdefca efag gf | fg fcg adegc edgfc
|
||||
fde fgedc cbdafe agefcb fagdce gfda efacg gbcde fgdecab fd | eafgcb cgfdeab cgfae efd
|
||||
afdegc dec dc ebcfad bceagf ecfag becdgfa gbdea gaedc gdfc | ced acbgedf gabde faebcd
|
||||
efdacgb cdagf cdegb egcdfb bf dcfbg cbfe gebcda bfadeg fbg | cbgdae gbf bf ebcf
|
||||
bdcfe cfdbga dec eabgdc caebfd ce fagcbde efac bdacf ebgdf | fadbgec cde aecf cde
|
||||
acgfdbe bceda bdgac fgcabe cebfa dbe eafd fbdceg dbfeac de | acfeb cagbfe feda aedf
|
||||
cd adgcfb adgc dfabce fdbgace gbdfea dfabg dfgbc dcb gcbfe | bcd badfecg cd gfeabdc
|
||||
bedc cgbdfa ec cge efdagc dgacb acgdeb agfbe bcage baecgdf | gce cedb ce cge
|
||||
fagecd gdfb ecgab fcbgade fcdge bdgce eadbfc gbecdf bd bde | gdecfab cedgf gbace abcfde
|
||||
debf fbc fcgeab dfgec dgacfe debgcf dgcfb bf cbdga aebdfcg | cdgefa adcefg dfbe agdefbc
|
||||
bcafe bdga debgacf ecafgd ad ecbgdf bfcgd bgfdca cad bcdfa | aefgcbd acdegf eagfdc ad
|
||||
fbdce de fcbdg bfecad cfaeb adegcb facedgb bde faed bfaegc | cfdbg afde fadbec bde
|
||||
fcdgbea cfe cebgf fe fbcdg abcge dbfe gfdbce dgcafb fdgace | eafdgc fec fce cef
|
||||
fagdebc fcbdg ba adecbf dgebcf cbga edagf bad agfdb gfcdba | fgbcd ab dcfbeag ba
|
||||
efgadc gbeac fadebg gbaef gec dabce cgfaeb bgfc gc fdacegb | begdfa gc gc fcbg
|
||||
ec fgbde befgda caegfbd agbcd bdcgef egc bcfe dcgeb edcfga | gecadf gadbcef ebgcd dgefb
|
||||
cfadgbe cdef ebagdc cadfb cfbade afbde deb gdcbfa aebgf ed | dbe decf ed ed
|
||||
ef fcae gdbeac bcedgf def ebfacd edbac eacbfgd bfdae dbagf | eabfcdg dfe edf bcdefa
|
||||
bafgd dc gdebacf decg fagedc cad gcdaf egacfb aecgf aedfcb | ecgd bgafec acd bcedaf
|
||||
fcegb dafcgb bgd bagcdfe gfebd fdbae eagfbd gd edga aedcfb | dfgbea gdb bgd fbgacd
|
||||
dec cgebaf fdgc afedbc dgbce cd fgbdce bcgfe egdba ebafdgc | bacedfg gbacef dgcf acbfed
|
||||
edfgab bgeaf eacbfd ebcagd dafbegc afe gfde bgfca fe eabdg | ef afe cfdeab abegd
|
||||
ae egbaf eacg gdfecb bacdef efbcg adcfbge fae dfabg ecfagb | agbef cbefag eaf adfcbe
|
||||
gce edfgbac dgefac fcega adcebg fagcd fgdbca aecfb ge fgde | degf egfac begafdc eg
|
||||
ebacd gdace bc bdefa gdefac eafgdbc ecgb dcb ecbadg dcbafg | dbc ceagdb gbdacf cdb
|
||||
aecdb bfae gcefd af cdafe fda eadfbc gabcdf begadc cabdgef | edcgfba acgbdfe cadbefg afd
|
||||
cad cefadg geacbfd debag cbag egbdca ca cdabe eagbdf ecbdf | ca cda acd cgab
|
||||
cbf adcgb dbfa bf fdeabgc eacdbg fabcg fgaec ebcfgd fdagbc | gcdfbe cgafe bfc agdcb
|
||||
dfeagc dacgf fdcea bdgacf defbga aefcb dgce ed dae adfbcge | cedg afegbd gfbceda eabdgcf
|
||||
egacd ebdgfc fc cfg dcfgea cdfa dgaecb efbag aegcf bgecdaf | cgf fc cbdega badefcg
|
||||
gedb fgabc adfbec bfedag dbafg dfcgabe gfd adgefc gd dfabe | adgfbe bfcgade gdf fdg
|
||||
deg fcgbdea gdbacf cgbade bfgcd fcaed fdgbce fgeb edcfg ge | ge gfeb gbcdfa gebf
|
||||
cdfag ebfdgac ecga gfade bfdeg gfacbd gdefca ea afe adfecb | ecga abcgedf dcfabge efa
|
||||
gadebcf aebg bdgac fdbac dcage bg acedbg dbg efgdcb egfdca | dgb bage ecfgadb gbd
|
||||
ecfd efgcb dcgbf fcbdga afdgcbe gfe bgedfa dcbgfe cgbae fe | fge ebfcdag bgeca cdef
|
||||
dfbgca dfbac ebgfdca abefd ebdgac fcgbd ca cab cfag fedgbc | cgaf bedcgaf gbcfd bac
|
||||
begfac faedc fedcb fecdga dcbgefa fegca adc dega cbafdg ad | da adc ad cda
|
||||
cebgdf fegdb ea efgabdc gcbda bdgea ebgdaf dcagfe bfae ead | ea ade cegdfab bfgaecd
|
||||
aefcbdg dbafg agdeb agfcbd fa adf efcabd gbefcd gfac cgdbf | fa adf af gdbcf
|
||||
cdgabef bfcaed cdf gcdbf bdgac fc dcebag gcaf bfged afdgbc | cf cgadeb fcd abdfgc
|
||||
fbcea egfcad dcbf adbef befgca dfa cagfdbe feacbd ebadg df | cfbd dgecbaf df decfba
|
||||
ebdcg ecbag egbcfd dgc cdefb dbfg dg bacefgd dcefba fgdcae | fbedc fedgac fecadb dg
|
||||
gcebd gf dafg acegbf fcadb eacbdfg cgf dbagfc dcbfg defabc | dagf agdf egacdfb dfbcga
|
||||
ebafgd cafdg gbfad bf eacbfd bfa edfbcag abgde cagdbe bfge | cgabed fadbg bcdfea bf
|
||||
ebdca dgbef facebg fba acdf bdafce daebf cgdebfa gadbce af | eafcgb egcdba gebacfd dcgbefa
|
||||
gafcdb dfcbe ae bacdg ecfagdb fcageb agde baced deabgc bea | cdgab cdfagbe ae acbde
|
||||
ecgdf acdg adfegb edc cgdeaf bedgafc dfgae cd bfceg afbedc | cebdaf dce acgd aegfd
|
||||
ab gdcebf bga ecgbf bdgafce gfbac afdgc cegadb gbefac eafb | fcgad eabf afbe ab
|
||||
bgefca fd bdegaf fdb debfg agefb gdbcaf afde dgbce dfbeagc | cafgbe fdb dfb dbafgce
|
||||
febcadg ecabg agdbec dafegb cegbfa baf bfgc bf febac dafce | gfcb fcbg efcad cefabdg
|
||||
bcgaf bgfcda acbdfge ad bagd dca gfacde bdcef ebfgac abcfd | ad ad agfdec cad
|
||||
gaefdc dbgfae bd fbd gdefbc cbdef cebfa cdfeg ebcfdag bdgc | bedfc bd gdcfe db
|
||||
dbgeac fdcgbe eg gace cbaed adgbe gecdbfa gbe fgbda dfaecb | ebg gadeb aegc eabfgdc
|
||||
bcgde cfgdbe gefc bfg fcdbg fdegab dfcba gf adbgecf bdgeca | bdcge efbdga cegabfd gfb
|
||||
fcgeb ced cd begcd dbgcae dabeg gdefac gabedf bgefdca bcda | gfbaced aebgd dcab acbfged
|
||||
ebadg fdbecg cgbfe fabc agf efabgc fa dfaecgb bfgea dagcfe | bcfa fag af cfadeg
|
||||
ga cbegd fgae fdgaec bfacgd cgade gfecdba adcfe fdbeca gac | acg gacfdeb gefa fedbac
|
||||
gbe debcf cgdfeab bdegfa agec ecdagb acfbgd ge gcdeb gcdba | egb gbadfec cgae cage
|
||||
cdfg fgdebca gadbfe cg egfac adgfe egc fbace dcbaeg dfcaeg | ecg gdeaf cgfd gdcf
|
||||
fagecdb fed gedac cfgd aefcb df gbaedf fcade dgafce geabdc | bfdcega df fd agbedf
|
||||
eaf af gdeac gfeadb egdbf bafd bdgceaf afegd gefbdc eacgbf | dfab fea fae edgca
|
||||
ea bgaec fbcge bdagc bcfdeg afdbeg abfegc eba cgbefda ecfa | ae ea bagcd ea
|
||||
de abegdf dea fdbaceg gdcab dgaeb gfbae cbedaf egdf cbgaef | cebdgaf bfgcead ebcafg dea
|
||||
cgaefb ca bagdcf caf badc fdgceab dgfea cgfbd cgfad cefdgb | ac bfdagec fca bcedgf
|
||||
dbefcg bdgacf fegbd ebgc bgdfcea dgb gb aegfd bfdcea dcfbe | bgfdca fgbdca fcdeb bcge
|
||||
gcadb dbage adbgfc deafbgc cbdf gcd dc eacfgb gdface gcfab | cdg cgbad gfdace gdc
|
||||
dfc cadg bacfgde cd fagbc gbedf acedbf gfbdc cbefga cbafdg | cd gcdbf cd gbfde
|
||||
adebf dbgae dfe adfcb gcbfeda ef bgfdae gadecf gfbe dbgcea | bgfe ebdfcga beadcg badcf
|
||||
eafbgcd bfdcae egfac dbaeg cafegd bfcgae gcfb ebacg cab cb | aedfgbc bc ebdag bgcea
|
||||
bdace abgdef dfc bdecf fc gbefcd cfegad fcgb degfb dgbafec | dfc dfc gcbf fgabecd
|
||||
gbfdeca gca gcdb fgebac bcdfag bdface dcbfa agdcf gc afgde | cbadf fcgeab afgdc gbdc
|
||||
daceg ceg eabg abefgcd ge gbcda gbcedf geabdc adecf fdagcb | fdbceag eg adceg gce
|
||||
bd acdgb fdegca egadc edgfacb ceabgd gdafeb dgb cbde fcabg | cebd gbd ecbd ecdb
|
||||
gdeca gcafbe gfecabd ecfd adbgc fdgea dfagbe ec cea gecfad | efgabdc dgabcef cea ce
|
||||
adefcgb gbfd cbedf gf gefbdc cgfeb acbeg cfbeda fge fcgaed | dbcegf fge egdacf abgfdce
|
||||
bfegca fdgb fdcga dga fbcga cfbgade dagbec gd caefd cdgbaf | dbceag dgfbeca dbfg cagdbfe
|
||||
cbad cageb egbdaf cgdbaef da dea efgcd bgcade gaefbc dcage | dea ad ade gcdae
|
||||
fgeab adecfgb beagcf debafc acbged fb cagbe gefad feb cbfg | badcge bfe fbe bgcf
|
||||
cbfag bd fdaeg afdbg dba bagdec gbeafd abfegcd dfeb fadegc | abgdec gfbcdae bdgfaec fcgba
|
||||
eabdgf fadbcg aedcfgb eg bge bagfce bgecf bfced fbgca cgae | ecfgb eagc eg ge
|
||||
cgab bc abfdec cgefd adbeg ceb fabgde cadegb cbedg bgdeacf | gabc gacb cbag gefabd
|
||||
bfecgd facdeg bcgfd fd fgcab bcegadf bdegc debagc dfg dbef | cgbdea dfg efbd gdf
|
||||
bedf debcag abfcg afd acdbe fd dabfc deabcfg abedcf egfdac | efcgda bfde ebdf dabfec
|
||||
gacbf gdebfc aedfb eg eacfdb egad febag aefgbdc egb gfabed | defba gbe eg eagd
|
||||
fcdb cgadef bgfcad gabef eabdgc cgb gefbacd bc dagfc gbcaf | bgc bgacf cb dbfc
|
||||
ebgfcad ebdga efdbac gefacb ge eafbd dgfe bagdfe gbe bgacd | bgedfa eadcgbf beg degf
|
||||
gfabcd ba abedcfg bfae bca edafc bcade gcfeda efdacb egcdb | ba ba afbe dbgacf
|
||||
ecdga deagcb gdbe ecgafd gabfced gfdcab gb cbg efcab ecgab | fagcbd dbagecf gbecad deacgf
|
||||
fegbcd dg gfaedc egafc befgca eacdb edacg ged decbgaf agdf | fedacgb dge dg gecfad
|
||||
cba abfeg gecabf cfdbae eacgbdf gfca ebdafg bcdeg ceagb ca | eabfg gcaf gafc acegb
|
||||
dgefc fbgecd bafec da cdafeg fecad dca bfecadg dfga gcedba | egdcf aecdbfg aecfd acd
|
||||
gdcf afcgbd cad gebda dfeacb fcabedg abgcd bfcag dc abefcg | cdgf cabfg gcfd adgbe
|
||||
ef cafeb gbcfea agcbdf agbfc gfae bfe cgfbeda bdefcg dceab | eafg dgcbef cfgba bcagedf
|
||||
eadgcf cadb ac cdbge bcaeg bcdfeg egabf ace fbgcead dbeacg | afgdecb egafcdb cdgefa ca
|
||||
da bfacg bdfgace adfgbc badc fcdga gdaebf caebfg dga gecfd | fdbaecg ad cdgfaeb fbcdgea
|
||||
cfd fc gfebacd bdcge cefgd afcged abdfcg acef adfge gdefab | bagfde gaebfd cf cf
|
||||
dag bdfgac agbc fgbdc fdcgabe ga gbdfce gdafc ecfda bfdaeg | cbfdg bcag dag ga
|
||||
gacfe aegfcdb fdgca dafcb cedgbf fgd ebacfg dega afdcge dg | gacfe gcebfd aedgbcf dg
|
||||
cdafb cbfag ecfdba acgdefb daegbc fcgd dcafbg gbc gc aefbg | gbfea gbc cgfd cabefdg
|
||||
bcdeg cfeabd fc afgc gecdf gdefab dgecaf efc bdaefcg egdaf | gbfaed efdcg bgecd dbagecf
|
||||
cdeb cadgfb dagcb deacgf bgfae aebdfgc badeg eda aebgdc ed | ecbd fageb ebcd ed
|
||||
cfde eacgfd gaefc agbdc gcdaf edgfba cebgaf gbcdefa gfd df | cfde fgd ecfd df
|
||||
egfdb fgadc bgc cb cafdebg ecfgab cdab ceafgd bfgcda cfgdb | cabd ecdabgf adfgc egdcbaf
|
||||
edcbagf fa gdcbea egcfd aecbd fadce adf ebafdc gbafed fabc | ebgdcfa daf acebd dcfge
|
||||
bdfec cg dabegc cgbde fcegbad dcagef abcg cge dgfabe badeg | bcfed bacged gc cgadfbe
|
||||
dagbf fbgdc fcbaed geaf ga ebadcg agd begafd cgedafb afbed | fgcdbea fdeab fdabe dga
|
||||
fae dacfeg cade acdfbg ea dacefbg gcfabe cadfg degaf fbdge | bdafecg afdge fceadg fgbceda
|
||||
becagdf gabfce gb bfdca agb dbgafe agfec egbc cegfda gcbfa | cgbe bga bdgeaf faegc
|
||||
96
december_8/src/main.rs
Normal file
96
december_8/src/main.rs
Normal file
@@ -0,0 +1,96 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
use std::collections::HashSet;
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut line_vec = Vec::new();
|
||||
|
||||
|
||||
|
||||
for line in reader.lines(){
|
||||
let line_as_string = line.unwrap();
|
||||
let split_line = line_as_string.split('|').collect::<Vec<&str>>();
|
||||
let input = split_line[0].to_owned();
|
||||
let result = split_line[1].to_owned();
|
||||
let input_list: Vec<String> = input.split_whitespace().map(|x| x.to_owned()).collect();
|
||||
let result_list: Vec<String> = result.split_whitespace().map(|x| x.to_owned()).collect();
|
||||
|
||||
line_vec.push((input_list, result_list));
|
||||
}
|
||||
|
||||
let mut easy_values = 0;
|
||||
|
||||
for line in line_vec.iter(){
|
||||
let result = line.to_owned().1;
|
||||
|
||||
for res in result {
|
||||
let len_res = res.len();
|
||||
if len_res == 2 || len_res == 3 || len_res == 4 || len_res == 7 {
|
||||
easy_values += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("Easy values: {}", easy_values);
|
||||
|
||||
let mut output_sum = 0;
|
||||
|
||||
for line in line_vec{
|
||||
let input = line.0;
|
||||
let result = line.1;
|
||||
|
||||
let mut segments = ['x'; 7]; // segment mapping
|
||||
let mut digits = [""; 10]; //Pos of digits
|
||||
|
||||
digits[1] = input.iter().find(|x| x.len() == 2).unwrap();
|
||||
digits[4] = input.iter().find(|x| x.len() == 4).unwrap();
|
||||
digits[7] = input.iter().find(|x| x.len() == 3).unwrap();
|
||||
digits[8] = input.iter().find(|x| x.len() == 7).unwrap();
|
||||
|
||||
segments[0] = digits[7].chars().find(|x| !digits[1].contains(x.clone() )).unwrap();
|
||||
segments[1] = digits[4].chars().find(|&x|
|
||||
!digits[1].contains(x ) &&
|
||||
input.iter().all(|digit| digit.len() != 6 || digit.contains(x))
|
||||
).unwrap();
|
||||
digits[5] = input.iter().find(|x| x.len() == 5 && x.contains(segments[0]) && x.contains(segments[1])).unwrap();
|
||||
segments[2] = digits[1].chars().find(|&x| !digits[5].contains(x)).unwrap();
|
||||
segments[5] = digits[1].chars().find(|&x| digits[5].contains(x)).unwrap();
|
||||
|
||||
digits[2] = input.iter().find(|x| x.len() == 5 && x.contains(segments[0]) && x.contains(segments[2]) && !x.contains(segments[5])).unwrap();
|
||||
digits[3] = input.iter().find(|x| x.len() == 5 && x.contains(segments[0]) && x.contains(segments[2]) && x.contains(segments[5])).unwrap();
|
||||
digits[6] = input.iter().find(|x| x.len() == 6 && !x.contains(segments[2])).unwrap();
|
||||
segments[4] = digits[6].chars().find(|&x| !digits[5].contains(x)).unwrap();
|
||||
digits[0] = input.iter().find(|x| x.len() == 6 && x.contains(segments[2])&& x.contains(segments[4])).unwrap();
|
||||
segments[3] = digits[8].chars().find(|&x| !digits[0].contains(x)).unwrap();
|
||||
segments[6] = digits[0].chars().find(|&x| x != segments[0] && x != segments[1] && x != segments[2] && x != segments[4] && x != segments[5]).unwrap();
|
||||
digits[9] = input.iter().find(|x| x.len() == 6 && !x.contains(segments[4])).unwrap();
|
||||
|
||||
|
||||
let mut output_value: String = "".to_string();
|
||||
|
||||
for val in &result {
|
||||
let mut val_hash = HashSet::new();
|
||||
for ch in val.chars() {
|
||||
val_hash.insert(ch);
|
||||
}
|
||||
|
||||
|
||||
let index = digits.iter().position(|&r| HashSet::from_iter(r.chars()) == val_hash ).unwrap();
|
||||
println!("Element is {}", index);
|
||||
output_value.push_str(&index.to_string());
|
||||
}
|
||||
|
||||
let output_value_int = output_value.parse::<i32>().unwrap();
|
||||
println!("Final Result is {}", output_value_int);
|
||||
output_sum += output_value_int;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
println!("Final Final Result is {}", output_sum);
|
||||
|
||||
}
|
||||
8
december_9/Cargo.toml
Normal file
8
december_9/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "december_9"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
5
december_9/example.txt
Normal file
5
december_9/example.txt
Normal file
@@ -0,0 +1,5 @@
|
||||
2199943210
|
||||
3987894921
|
||||
9856789892
|
||||
8767896789
|
||||
9899965678
|
||||
100
december_9/input.txt
Normal file
100
december_9/input.txt
Normal file
@@ -0,0 +1,100 @@
|
||||
9876567896542101249889965434567898765698785435678989898897654789424901245699887678932398943999888667
|
||||
5995456976543294398767896223456789654988654523599976677789765678919893456989776587891987899898765456
|
||||
6976577897664989985458989012345678969876543212388965435678996789909789579876543456789996789789894347
|
||||
7988678989979876564344678923576789989997432101267896323499989898898678999998432345899985345678932123
|
||||
8998789867891998432123799939678999899976543243458986545689869987674567989987543467899874257899653999
|
||||
9999898756890986573334987898989989789987654367867897656799878998543459876797665678901965346789869878
|
||||
9899999646789987654579876567898775679998965489989998767899989019651279765798786989219875457896998767
|
||||
8789798756789298777689987679987654598999996797597899878999999198762998754569987895423996567934987656
|
||||
6679659987894399888798998989876543497899987965456953989998998999879896543456998976534597789759876547
|
||||
5589943198965989999897899492998612986789998954349892199987687889998794332346799989645679898967965431
|
||||
3469894239899876543956789321299101975679989421298789098996545678987653201236789899898789987899876672
|
||||
2345789345798765432346695490985423986789879910197678987987657899998543212345897679929899896989987983
|
||||
1234689956789854301234579989976639897897567891997569896599868998987654324596896578910998745878998754
|
||||
2345789897892969219345989879897798789995456879875456789476979997699865537788912345921987634569898765
|
||||
6456898798901298998996898768789987656789345967965345799324989896549876745689302399899876547679769876
|
||||
7587897689432987887989997657567894345693233459874234678912398765434998656793212989678987756789643987
|
||||
8798976568999876776577896543479965456789102398762123489323489886755789767894349876598998767896542398
|
||||
9899435456987985325456789632568997697898912987542012395434678987867899878995998765456789878984321459
|
||||
0987321249876543101267896521456789789967894599653423569545989999878999989789854321239899989876532967
|
||||
1965433968987653274378976410367899996456789698769545678956799896989998795698765430198999898998649798
|
||||
9876549899899985365467995321278998975345698999978996789967998785599987654569896542987898767989798689
|
||||
6998659789789876476567896793345897683234567899999987897898998654359876543756987669896797659878987543
|
||||
5109898654677986587678987854456789432126788999876798956799987543298765432345798798765896738769996432
|
||||
4315986543456997678989998999967896569335999998765329545689499856988664321234569899896954323657987571
|
||||
5423498642347899789496889987898987698946789999854101234599398767976543210145778954987893212345898430
|
||||
5439987656456789892345678966989998987956797898943212345678939878987854321236899892198962101236789321
|
||||
7998798798987899921234568945679899876897976987657723876789548989298975432445689789299753213445678932
|
||||
9886649899198988430345678936799786765689765698876545687899956994349996547556895678987654567576789545
|
||||
8765434989019876521234569647987654554599654769987656998989899865456987698667894689598765678689997696
|
||||
9976765678929998432349678956987833223498943459899789899876799976967898789788923499439878999793239987
|
||||
9897878789997987653658989769876521014587894598769898776655689989898989899899312678921999999890145698
|
||||
8798989899876598967967899889987432123456789998655949654234678998789879902954201259890987898921236799
|
||||
7689994939875439879878925995698544536568999897543239862124559897674567893965354345679896567892357892
|
||||
4567943129876623989989213989987656697879998795432124983012346789543456999878465456798765456789469921
|
||||
3459321098765012399992101978798777788989989689321013964323456797652345999986577567987654343459567890
|
||||
2398939987654123689764219865669998999599876579544329865434567968531237889499787679898763212378978921
|
||||
9497898999953234569765439754358999886498768478995449876545678954320145679329898799769894324567899652
|
||||
8976867898764345678996598767467898765349954265689656987787889765621234569210989987657975434678996543
|
||||
7654656789876656899789679898978987643299863134598767898898999875432349878929876976549876545789989656
|
||||
6543445678989778956678989939989498656987654249699878989929986976543456789998665989434987656899879767
|
||||
7651534567899899434579998545695349897898975398988989878212965987757567899987554599321399767948768998
|
||||
8710123458989910125678997656789232998969876987767899966109854398869678988995463498442459878932356799
|
||||
9321234667965431249989798767992101239654989876456789954398743239989899767896332987643467989201345689
|
||||
5432345678976542458995679898943356896543298765334567895987652159899998456889101298776578993212456789
|
||||
6597656789987843567894623999764877987654697654123456789298789018789997349778922999887789989999597890
|
||||
7679787894599756778943219989885989598969798743034568994398732124679876234567939899998999678878998921
|
||||
8789898923987967889994398879996795459998999842126678985459543435678965445678998798999987567567899932
|
||||
9893969219876598997889986768998954356987899763234589876768954747899876789789998697989876423479927893
|
||||
7932356929854329545678965657889653235696598654345678989879865656789987899899986545877988765589436789
|
||||
6541467899773210124567894545678932123798429785456799393989876769893198999999876623456899887896545895
|
||||
5432379987654432396779943234799543234987439896567893212394987899979999098789985212346799998997657994
|
||||
7654567898878643989998954545988954345976545987678954493913598998769892197679654303457897659398778989
|
||||
8769879999997654976867995659877899457898656798789895989897679989654793986598765412598986543239889678
|
||||
9878998998898769865456789798765678967899769899896799879789789979543679995439874323459995432123996567
|
||||
7989997896799898765347899899854569998989878998965988964569899865432568954321986445578989932019765456
|
||||
6497986725788987653234567945965789889965989987654567953478921984321467899439797569789677892198654345
|
||||
5345975414667898784123489939876998767894395698753457892345890997632345678997698978993566789249985656
|
||||
4239864303458999894234567892999899656910234989884878921456789896543456799986569989432345698956976798
|
||||
3199878212367898765645678901988789945991299878976789530345698789654867899875456599531234987899897899
|
||||
4289989343478999976789789899876567899889989656987897321234799678965798999654323478920134986798799954
|
||||
5678999656789799987899995767998345789767678967998976532367987579877899998975634567921299875532678995
|
||||
6989998767895678998999864545695456897654589898959897745459995459989999897996796778932989984321556889
|
||||
9899899878984569019998753434976568933743456789345679856599989398999989796789989899749878975410345678
|
||||
8798789989573498929987642123988989421012345891234567967987673267899875685889878998659867896541236789
|
||||
4685678997431567898998543234599895434999496910126779878998432156999764534678967989898656789532345892
|
||||
3434567986542459987987654456988789659878989321234569989109843245699843123599345678987745699546456943
|
||||
2123456797656567896499766569877679998765678932457998997998764556789965654789234678976534678998567894
|
||||
3234597899997698945349879698767567899654367893459897566899976778999877765692123567894323559898778965
|
||||
4345798999889999431299989987656458999865458954598798445645987899989989876789012989963212346789889986
|
||||
5477899998678898740989999898742347899876767895987654320136798989578997987894329898954433577894999897
|
||||
6567999876545689659878998765431236789987899999898765631247899975459876598965498787895954589912398789
|
||||
9878989987434567998767849897310135689298946789769987545698999767210986439878987676799867678923497679
|
||||
9989678998523456987656234998421234793139435697654398656989987654329798323999776545789878789539987567
|
||||
9694569876313456986543123499562376891098546789452239769878898976498643202987632124699989897698776466
|
||||
8543456965424569997931012987654567942987657895321019898967679987679784419876543245678993919987654345
|
||||
7432459876436678998765178998765678993498767987432123987843567898789876323987987656789892101298764257
|
||||
6556795998545689209874357899876899789569978998693239876732598999898765435899398767897789912999865369
|
||||
7867954297656789398765456976989965678979999109989346985321487899989876546789219978945679899899876459
|
||||
8998969199887895459876587895697654567898989235979997976210356789767998769894349989234598788789989678
|
||||
9549998989998979567989698914598543456987678949868789997921234899854319898965998799015987675679898989
|
||||
5434987879999767989999789323987632369876567998659699989892347999995423997999897678929876564798797890
|
||||
6565976765789658999989899939876521379765476896543569876789456789989599886789764567899975433459656891
|
||||
8679765554567967898968979899985435498654345789432498765689567994678987765989953456989876321298967892
|
||||
9998654443456898987956758789876657987421235679321989654699778976989876564567892349876543210987898943
|
||||
9877843312345789876541245696987789876530123789432979795699899987898765433548953478988664329876789654
|
||||
8765432103556898765720476795498898987545434599999868989789954698999654321238954567899965498765678967
|
||||
9876556314587899654321297954349967898687567899889747678999643999999876534567896898999876999874789878
|
||||
6987787323458998965432379965212456789798678998777634567898759789989987845678997899789999894323699989
|
||||
5598898954569987897763567899101345679899789997664523467969898698678998756989998955567987643214569999
|
||||
4459999767698876999654578998932956789929899876543212348954989543559899967899989643456798752101478989
|
||||
3358999878987855798965689987999897993210998987654101247899878942345789878998765432017986543212399976
|
||||
2256789989876544687899899876789789894321987598785613345678967921456789989999976543128987664343457895
|
||||
1034598795987432356789998965645698795452399439896723456789456892967895698789897669239898765674688934
|
||||
2129889643498321768899987854134987689943998921987854578891256799898934987676789778349769876989799423
|
||||
5345679791987542379998996543029876567899877892398987689932345689789329876565679889498959987899898912
|
||||
7956789989998673498987987632198765456789766799459998996543867795679499965434798999987898898942967923
|
||||
8987999878998794567896496544349896777895445678967899329654989894898987654323456789876987769321259894
|
||||
9499998767899895678954349876456997889954334589979997598767894943767899865410387899985396543210345789
|
||||
5323987756789987989765212989567898996563125678989987679878943432356789876521239999876987654421256895
|
||||
6212976545678998999986433497678999765431016789990198789989432101245678989432445689989998765632867934
|
||||
104
december_9/src/main.rs
Normal file
104
december_9/src/main.rs
Normal file
@@ -0,0 +1,104 @@
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader};
|
||||
use std::io::prelude::*;
|
||||
|
||||
const RADIX: u32 = 10;
|
||||
|
||||
static mut visited: Vec<Vec<bool>> = Vec::new();
|
||||
|
||||
fn main(){
|
||||
let file = File::open("./input.txt").expect("Read failed");
|
||||
let reader = BufReader::new(file);
|
||||
|
||||
let mut line_vec: Vec<Vec<u32>> = Vec::new();
|
||||
|
||||
for line in reader.lines(){
|
||||
let line_as_string = line.unwrap();
|
||||
let line_as_int_vec = line_as_string.chars().map(|x| x.to_digit(RADIX).unwrap()).collect::<Vec<u32>>();
|
||||
line_vec.push(line_as_int_vec);
|
||||
|
||||
}
|
||||
|
||||
let height = line_vec.len();
|
||||
let width = line_vec[0].len();
|
||||
|
||||
let mut danger_value = 0;
|
||||
|
||||
let mut low_points: Vec<(usize, usize)> = Vec::new();
|
||||
|
||||
for line_nr in 0..height {
|
||||
for col_nr in 0..width {
|
||||
let upper = if line_nr > 0 {line_vec[line_nr - 1][col_nr]} else { 99 };
|
||||
let lower = if line_nr < height - 1 {line_vec[line_nr + 1][col_nr]} else { 99 };
|
||||
let left = if col_nr > 0 {line_vec[line_nr][col_nr - 1]} else { 99 };
|
||||
let right = if col_nr < width - 1 {line_vec[line_nr][col_nr + 1]} else { 99 };
|
||||
let val = line_vec[line_nr][col_nr];
|
||||
if val < upper && val < lower && val < left && val < right {
|
||||
danger_value += 1 + val;
|
||||
low_points.push((line_nr, col_nr));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _ in 0..height {
|
||||
unsafe { visited.push(vec![false; width]); }
|
||||
}
|
||||
|
||||
|
||||
|
||||
let mut basins: Vec<Vec<(i32, i32)>> = Vec::new();
|
||||
let mut sizes: Vec<i32> = Vec::new();
|
||||
|
||||
for point in low_points {
|
||||
let test = get_neighbours(point.0 as i32, point.1 as i32, height, width, &line_vec);
|
||||
if test != None {basins.push(test.expect("msg"));}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
for bas in basins {
|
||||
println!("Size of basin: {}", bas.len());
|
||||
sizes.push(bas.len() as i32);
|
||||
}
|
||||
}
|
||||
|
||||
sizes.sort();
|
||||
|
||||
let mul_result = sizes[sizes.len()-1] * sizes[sizes.len()-2] * sizes[sizes.len()-3];
|
||||
|
||||
println!("Danger value: {}", danger_value);
|
||||
println!("Multiplication result: {}", mul_result);
|
||||
|
||||
}
|
||||
|
||||
fn get_neighbours(line_nr: i32, col_nr: i32, height: usize, width: usize, line_vec: &Vec<Vec<u32>>) -> Option<Vec<(i32, i32)>>{
|
||||
unsafe {
|
||||
if ( line_nr < 0 || line_nr > (height-1) as i32) || ( col_nr < 0 || col_nr > (width-1) as i32) {
|
||||
return None;
|
||||
}
|
||||
if visited[line_nr as usize][col_nr as usize] {
|
||||
return None;
|
||||
}
|
||||
if line_vec[line_nr as usize][col_nr as usize] == 9 {
|
||||
return None;
|
||||
}
|
||||
visited[line_nr as usize][col_nr as usize] = true;
|
||||
let mut result_vec: Vec<(i32, i32)> = Vec::new();
|
||||
let l_res = get_neighbours(line_nr, col_nr-1, height, width, &line_vec);
|
||||
let r_res = get_neighbours(line_nr, col_nr+1, height, width, &line_vec);
|
||||
let u_res = get_neighbours(line_nr-1, col_nr, height, width, &line_vec);
|
||||
let d_res = get_neighbours(line_nr+1, col_nr, height, width, &line_vec);
|
||||
if l_res != None { result_vec.append(&mut l_res?); }
|
||||
if r_res != None { result_vec.append(&mut r_res?); }
|
||||
if u_res != None { result_vec.append(&mut u_res?); }
|
||||
if d_res != None { result_vec.append(&mut d_res?); }
|
||||
|
||||
|
||||
result_vec.push((line_nr, col_nr));
|
||||
|
||||
|
||||
|
||||
return Some(result_vec);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user