summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@gmail.com>2021-12-09 22:06:45 -0800
committerIrene Knapp <ireneista@gmail.com>2021-12-09 22:06:45 -0800
commit964c72cc4fe03c06bd067fc7605cca96f8b94943 (patch)
treee7b7e44cfc57f4e8ececcb9367057f72b8e9eabb
parentfb70e46dc0009c69f617135b0249cdda31b978bf (diff)
10
-rw-r--r--10/Cargo.toml11
-rw-r--r--10/input102
-rw-r--r--10/src/main.rs148
-rw-r--r--10/tests/main.rs17
-rw-r--r--Cargo.lock8
-rw-r--r--Cargo.toml1
6 files changed, 287 insertions, 0 deletions
diff --git a/10/Cargo.toml b/10/Cargo.toml
new file mode 100644
index 0000000..6b36e1c
--- /dev/null
+++ b/10/Cargo.toml
@@ -0,0 +1,11 @@
+[package]
+name = "advent_10"
+version = "0.1.0"
+authors = ["Irene Knapp <ireneista@gmail.com>"]
+edition = "2018"
+
+[dependencies]
+advent_lib = { path = "../lib" }
+
+[dev-dependencies]
+assert_cmd = "0.10"
diff --git a/10/input b/10/input
new file mode 100644
index 0000000..ca048fc
--- /dev/null
+++ b/10/input
@@ -0,0 +1,102 @@
+[<<{[{([([({<{<>{}}>[[[]{}][[]<>])}{[(())][[<>{}]{[]{}}]})](([{<<>{}>[()<>]}<<<>()>{{}<>}>]{[{{}()}[(){}]]})
+[({[[(<{[<[<{({}[])(<>{})}(([]<>)[[]()])>{[<{}()><{}{}>][<[]()>({}())]}]<(<(()<>){{}{}}>({()()}(()[])))>>[([
+(<([[<(<<{((<<<>{}>{{}{}}>({()<>}{()<>}))<[(<><>)<<>()>]{((){}){[]<>}}>)}({<[(()[]){()[]}]{((
+<[(<{[{{([([{{{}<>}}{{<>()}<<>>}]){[[<[]<>>(())]<<<>{}>(())>][<<{}{}>(<>())>{<{}{}><{}<>>}]}]<<({{()
+{(((<{{{<<{({{()[]){()[]}}({{}}[<>[]])){[{()<>}<()()>]}}>{[[{<[]{}>{{}()}}<<()[]>[{}[]]>]{[{(){}}(()[])]<({
+<(<{<<{{([[({{<>()}[(){}>}[(<>)(()[])])([[<>()]<[]()>])]{(<(<>()){[][]}>[((){}){[]{}}])[[{[]<>}({}
+((<[<(([[{[{{[{}()]{<>[]}}}]{[{<()()>[{}[]]}[<[]{}>]]{{{<><>}[()[]]}<{{}{}}[<>()]>}}}[{{<{[][]}({}())><{
+[([{({[({<[[<([][])<(){}>><<<><>>[[]()]>]<<({}{}))[<<>[]>]>]{[(([]<>){[]<>}){[{}{}](()())}]}>[<<{<[][
+({{{(<{({((<({<>()})[(<>[])<{}()>]>{{<[]()><{}[])}[{[]{}}({}{})]})){{{[<(){}><[]<>>][<{}()>{(){}
+(<[<[<{[<{{[[([]{})]](([{}{}]({}[])){<()()>({}())})}[((<{}()>{[][]}))[[<()[]><()[]>>([[]<>]([]{}))]]}({[
+<{{[<[<<(<[[([[]<>]({}<>))][[({}<>){{}()}]{<(){}>(()[])}]]>{[([[[]{}][{}()]][({}{})((){})])({({}
+([{{[{{[<<[([([]())<[][]>]({<>()}{[]()}))<(<<>{}>{()})>][[[{<>[]}[(){}]][[()[]]({}())]][(<[]{}
+<[{<[<[<{[<([[{}()]]){<{{}<>}[{}<>]>([{}{}]<[][]>)}>][<([{(){}}<<><>>]<<[]{}>[()<>]>)><{[([](
+<([[([((<[{<<<()<>><[][]>>{({}[])({}{})}>({({}<>){[]}})}<(<{[]{}}{()<>}>([(){}][()<>]))[{[{}]<{}()>}<{{}
+[{{[([{{{{(({({}<>)<[][]>})([{<>()]<<>{}>]{[()()]}))({{<(){}>{<>{}}}}([<()<>>[{}{}]]{{[]{}}(()[])}))}{(((<[]
+<{{{([<[{((<<<[]{}>{()[]}>{(()[])[{}()]}>[[(<><>)][[(){}]{[]<>}]])({{((){})<[][]>}[<[]()>(<>{})]}<([{}<
+<[(((<{(({[{[[[]()][[]<>]]<{<><>}[()()]>}][{[[{}{}]<{}()>]<([]()){<>[])>}[(<{}<>>({}()))(<<><>>((){}
+([{{[[((<{([<<()[]>{[][]}>{[[]{}]<{}()>]]{<<()<>>>{({}<>)((){})}})<[{[<>()](<>[])}]{({()}({}
+(({[{(({{{<{(({}{}){[]<>})<{[][]}>}<<{{}[]}<{}}>{{()[]}{<>[]}}>>}(<<[([]{})<<>()>]<(()<>)<{}<>>>>>[{{(()[]){{
+<[{<<<(([{{(<[[]()][{}[]]>[[{}()]<{}()>])<[[[]]{[][]}][(()[]}]>}}][{({<<<><>>>[<{}[]>({}{})]}<(([])<{}{}>)>)
+{<(<[(({<[<{(({}){()<>}}}([[<>()](()[])])>((<[[]{}]{[]<>}>({[]<>}[[]<>])))]>}({{{[{{<>()}[(){
+[{<{{{[<[[<<<[<>]>[[[][]][()<>]]>{<{(){}}<()[]>>([()[]](<>))}>[{[{<>{}}[[][]]][[[][]][<>[]])}<({{}()}{(){}}){
+<<<<(([((<(([{<>()}<[]{}>]))({({{}[]}<(){}>)[(()())<{}<>>]}<{<[]()>{()[]}}([<><>]([]{}))>)>[<{<<()[]>[()<>
+<{<{<((({[<{(<{}()><()[]>)<[{}()]<<>()]>}<{(<>())[[]<>]}[(<>[])[<>[]]]>>]<<<<([]{})(()())>{({}(
+(<[(({[(<{(([({}{})(<><>)]<{[]}(())>)<([(){}])>)(<(((){})<<>])([{}{}][{}{}])><[<()()>[{}()]]{((
+<{<(<([<{[<{[{<>()}{<>[]}]}<<[[]()]({}<>)><[[][]]([]{})>>>[[[{<>{}}(()())]({()<>}<{}{}>)]]
+{[<[(<((<{<[[<[]()>[[]()]]([{}()]<<>>)]([([][])[(){}]])><{({<>[]}[[]<>])<{<>()}<()()>>}((<{}()>)<(<>[]){[]()
+<{<[{((<[{([[<<><>>(()<>)](([]()){[]()})]<{(<><>){(){}}}>)}<(([{()()}<<>[]>])(<<<>{}>(()())><<{}{}><{}[]>>
+(<([{<<[<({({[<>{}](<>{})}((<>{})<{}{}>))[<[()](<>())>{[[]()]<()<>>}]})[{({(()[]){[]{}}}[[[]()]
+{({<(<{{[<(<([<>[]][{}{}])[[{}<>]{[][]}]>[[((){})[<>()]]({[]<>}<{}()>)]){[([[][]]<[]{}>)[[{}()]]][[([][]){[
+({[<{({{(<{[{<{}[]>{<><>}}<<<>[]>([]())>](<(<><>)<[]{}>><{<>()}<()<>>>]}<{[([])<{}<>>][<[]<>>
+[{<[<{<({{(((<{}[]>{[]{}}){<<>[]>[<>[]]}))<[(<<>[]>{[]{}})[<{}[]>{<>{}}]]>}{([{[<>{}]([][])}<{()()}{<><>
+{[([{<([{{<[<{(){}}[()<>]><[[]][[]<>]>]([<()<>>({}<>)][<{}()>[<><>]])><<{<()()><<>()>}[[<>[]
+<{({[{{([({(({[]{}}<{}{}>)({[][]}<[][]>)){{[()<>]<<><>>}{<{}{}>}}}{({[[]()](<>())}{[()[]]}>[<{()}{[]
+<{<({([{{{((<{<>}<[]()>><[()()][[]<>]>)([{()<>}{<>[]}](<<>()>([]{})]))(<{<(){}>}([<>[]](()[]))>[
+[{[({({<(([({{{}<>}}[<[]<>]({}{})]){({()()}{{}[]})}]{[[[()<>]<<>[]>][([][])]]})<[<<([]<>)([]{})><{<
+<[[[({{{([{({<()[]>(<><>)}<{<>}([]())>)([[{}[]]<<>()>]([<>()][[]<>]))}<{<(()[])>>>]<<<{{()()}[()<>]}{([]
+[<[({<<<<<<[{{{}{}}{[]<>}}[<{}{}>(<>[])]]({<<>[]><{}()>})><<<{<>()}[()<>]>[<<>[]><<>{}>]>{<{[]<>}[()
+([[<<(((<[(({({}{})<[]{}>})<<<{}[]>{()<>}><{[]()}>>)((<{<>()}[<>[]]>[<{}()><{}[]}]))]{<[({(){}}
+[({<(<<[{<[[<(<><>)[{}]><([][])[{}<>]>]{([<>[]]({}()))[{[]<>}([]<>)]}]>{<(<[[][]]<[]()>>{(()
+{({(([({{{(<({()()}<<>()>)[(<>[])[{}{}]]>[{[()[]]([][]>}[{(){}}<{}<>>]])[(<{[][]}(<>{})>{[[]<>
+(<{([(((<{[<{[<><>]{()[]}}<<[]>>><{({}<>)(<>[])}{<{}[]>[[]{})}>]({<{{}<>}(()[])>{([][])[{}
+<<(<[({{[<<({{[]()}})<(([][])([]()))>){([(<>{})][<{}<>>{{}[]}])[(({}())(<><>))<<[]><<>[]>>]}>({[{{<>}(<>[])}{
+[{[[<<<{(([([({}<>)[<>()]]<(<>())>){([<>][<>()]){{(){}}[<>{}]}}]([<{{}{}}<{}<>>><{<><>}>]<(<<>[]><{}[]>){[
+<<{<[([{{[[[{<<>()>({}())}<<(){}>[{}()]>]](([{[]{}}[<>()]][[[]()](()[])]){[[{}()]<[]>][(<><>}]})]}[<
+<[(<<(({<{((([<><>]<(){}>)<{{}}({}())>)<[<()<>>[()[]]]({[]}{[]()})>)}><<[(((()<>))<(<><>)>)]([((()<>){{}{}}
+{({({<<[(<{{<{(){}}<[][]>>[[<>()]({}<>)]}}><<(<{[]<>}([][])>[<{}<>>([]())]){(<()[]>([]()))}>[({[()<>
+<([({{<{([<<[[{}()]][<()[]><<>{}>]>([<{}[]><()[]>]<{{}()}[[]{}]>)>{<(<(){}>)({{}{}}{{}<>})>{([(){}][[][]])[{
+<<<<(([<([[{{[{}{}]{<>[]}}[[{}{}]<[]{}>]}[({[]()}[[]<>])[[[]{}]<<>()>]]](<{<[][]}{<>()}}{{[][]}}>{
+{[[<[{<{<((<<([]())({}())><(<><>)<{}<>>>)<[{{}[]}][<{}<>>([]{})]>)<{[<{}[]>(<><>)]<<(){}><[]{}>>}{<<<>{}>>
+<(<<((({{[({<<{}[]>{<>[]}>{({}{}){{}[]}}}{[[()()](<>{})]{{<><>}<<>[]>}}){<[{()()}<()[]>][[{}{
+[<([<<{<<[<<([()[]]({}[]))<{<>()}>>{[<()<>>[{}()]]<{()[]}{(){}>>}>]>><[([([<[]<>>{<>{}}]<([][]){<>{}}>)
+[{{([{([(({<{({}[])(()())}{{{}<>}[()()]}>[[[<>[]]([][])]({<><>}<{}{}>)]}[[<{()<>}[<>()]>[<{}{}>[()()]]]{([(
+<({[(([[({((<({}[])([]<>)>{<()[]>([]{})}){{([][]){[]{}}}[({}{})[{}]]})<{<{[][]}([]())><[[][]]{<><>}>}<<
+[<<((<<[<{{{{<{}[]>[{}[]]}{{<>{}}{<>[]}}}[{(<>[])({}())}{<<>()>(())}]}{<{(()()){()<>}}><[([]())]<<()[]>[(
+([[(<<[{[({(<<[]<>><{}>>({<>[]}([]())))[((<>[]){()()}){{[]<>}[[]()]}]}([({[]()}[[]{}])[<{}()>{[]<>}
+{(<((<{([<<{{{()[]}<(){}>>[[[]()]<{}<>>]}<([[]<>]){(<>{})<()[]>}>>>{(({[<>()]([]())}))}]([<{({{
+[[[[<([{[[{<[{()}(<>[])]>(<[[]{}]<{}{}>>)}]<<((<(){}>{{}[]})[([]{})[[][]]]){{<(){}><[]()>}{(()<>)[[]<>]}
+<([{<<[<{{([(<<>()>(<>[]))<[<>[]]>](<({}())<()()>>)>{{{[<>[]]{<>{}}}({(){}}{{}()})}}}({{([()[]][[][]])[
+<<({({{<(<(([<[]()>[{}<>]]<({}){()[]}>){[<[]{}>(()<>)]}){[{{<>{}}{()[]}}((<>[]))]{(<{}()>{(){}])[(<>{})<
+(<<({(<<([(([<<><>>([][])]<[<>[]][()]>)<(<[]<>>[<>{}])>)(([({}()){[]()}]((()[])(<>()))){<<{}<>>{[]{}}>{[(
+([[[{{[<{(({{(()<>){<>{}}}{[{}<>](<>[])}}{{<<><>>{{}[]}}([<><>]{<>()})}))([<([[]<>])>]({[<()[]>][
+<<(([([[{({([<<><>><[]{}>][(()())(()[])])<([{}()][{}[]])<((){}){[]()}>>}<{[{[]()}[[]()]]}>)[<((<[]{}>)((<>[])
+{<<{[[((<({<{<<>{}>}[(()<>)[{}[]]]>[([<>()]({}()))]}<<<<<>[]><<>>>>{(([]{})[()()])}>)((<((()[])(()<>
+<{<{<{<[({(<[(<>[]){<>{}}]{(()[])([]{})}>)}<[({<<>()><{}()>})(([()<>}[[]{}])<{{}<>}>)]>)<(<{{{[]{}}<<>{}>
+<[[{(<{(<([<<{{}{}}[[]<>]>><{{(){}}<()<>>}{<{}{}>{[]{}}}>])>{{<{([{}()][[][]])<([][])({}<>)>}>{
+({({<<[{[[{{[{{}()}{()[]}]{[{}[]](()())}}<[([][]){()[]}]<[[]()]((){})>>}]<[(<{[]{}>{{}<>}>{
+{{[<[((([<[([[()[]]{()())]<({}{}){[]{}}>)]>][<<({<(){}>({}{})}{<<>[]>[()]})<(<(){}>{[]()}){
+(({[((<(<({([(()()){<>[]}]){({{}<>}{{}[]})}})[({({{}<>}[{}()]){{[]()}<<>{}>}}<<<()()>[<>{}]>{<{}{}>}>)]>[[
+((<[[((<[(({[{<>()}(<>[])]}{[(()())[[][]>][<{}<>>{<><>}]})([{{<><>}({}<>)}]{(<[]<>>(()[])){<{}<
+<[[{[<[<{<<<<([]{})[<><>]>(({}())(()<>))><([[]{}][[]()])<{[][]}[<>{}]>>>(({(()[]][[][]]}){{<<><>>{[][]}}}
+[<[{{[{[<<{(<([][]){[]<>}><<[][]>([]<>)])<<<[]{}><<>[]>>([{}<>]<[][]>)>}>><{([({<><>}<()()>)<({
+{<{([<{(((<{<{[][]}{()()}>(((){}){()()})}>)[({<<<><>){<>()}>((()[]){()[]})}{({<>()}{{}()})({<>{}
+[[[(<<{({[{[[<[]<>>[{}()]][[{}[]][{}()]]][[[()<>]([][])]<<()>([]<>)>]}[({[<>]{()<>}}(<<>()><(){}>))[<({}[
+<[{({<{[<[(<({{}[]}<<>()>)([{}<>]{[]{}})>)[(<{()}<()>>{[()<>][()[]]})<[[()()][{}<>]])]]<[[{(<>[]){<>()}}
+<((<{[{{<{([{<()()>(()[])}{{[]<>}[[]{}]}](((<>())){{[][]}<{}[]>}))(<{((){})[<>{}]}[[<>()]<<>[]>]><{({}<>)({
+{<[[<(([<[[[{{[]()}{<>{}}}<<<>[]>>][(({}{}){<>[]})[(<>{}){()<>}]]]<{<((){})([][])>}<[((){})[[]{}
+([[{[[<{<((<(<<>>)>){((<{}<>>{<>()})){([{}[]}{<>()})<<{}()><<><>>>}})<{{([(){}])<<{}[]>{[]<>}>}<<<()<>>[[
+<[([[[[[{((<{<(){}><<><>>}[{[]<>}[<><>]]>[({()[]}{<>[])){{{}<>}[[]{}]}])<[([[]<>][{}])([[]()][{}()])]<<{[
+[{[<[<(<[([[([<>[]]<(){}>){(<><>)<{}<>>}]<[[[]()][<><>]]{{[]<>}(()[])}>]){{<{{[]{}}}((<>()){[][]})
+{{([[({{(<<(<[{}[]]<<>[]>><{{}<>}{(){}}>)>>)}})((<{<{<[([][])][[<>{}]<()[]>])}<([[{}[]]{[]()}]{
+<({{{{{{<(<<[<()()>([]<>)](<[]()>[<>{}])>(<{<><>}(<>[])>)>[({(<>())<<>{}>})])><<<[{[[]()]<{
+{[([(<([[({<({{}[]}{{}()})<<{}<>>{<>{}}>>})([([{[][]){{}<>}]{{<>}[()[]]})((<(){}>[[]()])[[[][]]([]<>)])])]{
+{(<[<{[[{({<[{<>[]}<()<>>](<{}()><{}{}>)><<({}<>)<{}()>>([<><>][{}()])>})}<[{<([()[]])>}]>](<({(<(<>())(<><
+({<(({{{[[{<([[]<>])>(<{<>}>[[()()][()()]])}]]}<<[<[<<{}[]>((){})>{([]{})}]><<{<{}()>{[]()}}{{()()}<
+<{<<(<[<{[<[{<{}{}>[<>{}]}[{[]<>}{<><>}]]{{<()<>>}[<{}()><{}()>]]>]}>]>)>>}<<[<(([[[<((<(){}>){([]{}
+<<(<[[<[[[<<({<>{}}{()})><[([][]){[]<>}][[()[]]]>>]]{[{(<(<>{})({}{})>)}]({[({{}<>}([]<>))([()[]
+<[[(({[<(<{([(()()){()[]}]<(()[]){<>()}>)<[<(){}><[]{}>]({[][]}<[]{}>)>}[<[(<>)<<>{}>)>({{<>{}}(()
+([[({[<<{(<[<{{}{}}<{}{}>>{({}())(()<>)}]>[([{[]}(<>{})])])}>>]{[{[<{<(<<>{}><{}[]>)><({[]<>}<{}<>
+{(<(<[<{[<{<({()[]}){({})}>}{[<[{}[]](<>())>{[{}<>](()[])}]}>]{{<[[[<><>]]](<(<>{})><{[]()}>)>}{[<{[{}{}]((
+{{{(({({<[[[[[<>{}]<[]{}>][((){}){{}{}}]][[([]<>)<[]{}>]{({}())(<>[])}]][<((()<>)[()])><{[{}[]]{[][]}}{{
+{<[({{([({(([<{}[]>{()[]}]){<[[][]][<>{}]>[{<>[]}({})]})}{[{[{()()}{<>()}]}{[([]{})<<><>>]}]})<<
+{<<<{{({{<([<({}{})<<>{}>><[[][]]({}<>)>])>([{([{}()])}([<(){}>{{}()}](<<>{}>(<>[])))](<([<
+<{{{<({[[{{<<[(){}]<[]<>>>{{{}()}([]{})}>}<<[<<>{}><{}[]>]([(){}][[]{}])><[{{}{}}<{}<>>][<[][]>
+((<(<<{<(<{[[{[][]}]{{()<>}<<>{}>}](<[[]<>]<{}()>>((()())[<>{}]))}[([(<>{})<()[]>]<[[][]]<[]{}
+{[<{[[{<[((<<<<>[]>[[]{}]>({{}[]>)>)<{[[[]{}]<{}{}>]<([][])(()<>)>}>)](<[[<[<>()]({}[])>]]>({{<<[]{}>{[]
+<[{{[(<<([[[[<<>()><{}<>>](((){}))]([<{}{}>[<>()]](<[]()>[[]()]))][{{{<>}{[]{}}}{{{}<>}({}<>)}}[{({}{}>{{}<>}
+<[<{{([{[{[((([]())({}<>)){[[]()][{}{}]})]({{(()[])[()()]}})>(({[({}())[<>()]]{<<>{}>[<>{}]}})[[{[()<>]<<>
+[{([<<[<[{{<<{<>[]}({}[])>>{<{{}{}}[<><>]>([[]<>]<{}[]>)}}{[([()[]](<>))<{{}[]}<(){}>]]}}[[<{[<>[]]{[]<
+<[[([<{<{<[([[()[]]])<({[]()}({}()))[(<>{}){<>[]}]>]>(([<{{}()}(()[])>{{{}<>><<>[]>}][[({}<>)[<>[]]]{{
+[<((({((<<[[[{{}<>}{()<>}]]({(<>[])<()<>>}{(()()){{}{}}})]<<(({}<>))>{<<[]()>><[()()]<[]{}>>}>>>)(<<{<{<{
+(<(({(<(<<([<([]<>)[{}{}>>({{}()}[{}[]])]<({[]<>}[{}{}])<([][]){{}{}}>>)>{[(<<[][]><{}()>>{{<>{
diff --git a/10/src/main.rs b/10/src/main.rs
new file mode 100644
index 0000000..35fbf71
--- /dev/null
+++ b/10/src/main.rs
@@ -0,0 +1,148 @@
+use advent_lib::prelude::*;
+
+
+fn main() -> Result<()> {
+  let mut args = std::env::args();
+  if args.len() != 2 {
+    eprintln!("Usage: advent input");
+  }
+  let _ = args.next();
+  let filename = args.next().unwrap();
+
+  let input = advent_lib::read_lines_file(&filename)?;
+
+  let mut total_score = 0;
+  let mut incomplete_lines = Vec::new();
+  for line in &input {
+    let mut chars = line.chars().peekable();
+    let score = parse(&mut chars);
+    total_score += score;
+
+    if score == 0 {
+      incomplete_lines.push(line.clone());
+    }
+  }
+  println!("{}", total_score);
+
+  let mut completion_scores = Vec::new();
+  for line in &incomplete_lines {
+    let mut chars = line.chars().peekable();
+    let completion = repair(&mut chars, true).unwrap();
+    let mut score: i64 = 0;
+    for c in completion.chars() {
+      score *= 5;
+      score += match c {
+        ')' => 1,
+        ']' => 2,
+        '}' => 3,
+        '>' => 4,
+        _ => 0,
+      }
+    }
+    completion_scores.push(score);
+  }
+  completion_scores.sort();
+  let second_score = completion_scores[completion_scores.len() / 2];
+  println!("{}", second_score);
+
+  Ok(())
+}
+
+
+fn parse(chars: &mut std::iter::Peekable<std::str::Chars<'_>>) -> i64 {
+  match chars.next() {
+    None => {
+      return 0;
+    }
+    Some(open) => {
+      let open = open.clone();
+      loop {
+        match chars.peek() {
+          None => {
+            return 0;
+          }
+          Some(c) => {
+            let c = *c;
+            if "([{<".contains(|d| c == d) {
+              let score = parse(chars);
+              if score != 0 {
+                return score;
+              }
+            } else {
+              let _ = chars.next();
+              match (open, c) {
+                ('(', ')') => { return 0; }
+                ('[', ']') => { return 0; }
+                ('{', '}') => { return 0; }
+                ('<', '>') => { return 0; }
+                (_, ')') => { return 3; }
+                (_, ']') => { return 57; }
+                (_, '}') => { return 1197; }
+                (_, '>') => { return 25137; }
+                _ => { }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
+
+
+fn repair(chars: &mut std::iter::Peekable<std::str::Chars<'_>>,
+    is_top_level: bool)
+  -> Option<String>
+{
+  loop {
+    match chars.next() {
+      None => {
+        return Some(String::new());
+      }
+      Some(open) => {
+        let open = open.clone();
+        loop {
+          match chars.peek() {
+            None => {
+              let mut result = String::new();
+              result.push(match open {
+                '(' => ')',
+                '[' => ']',
+                '{' => '}',
+                '<' => '>',
+                _ => panic!("alas"),
+              });
+              return Some(result);
+            }
+            Some(c) => {
+              let c = *c;
+              if "([{<".contains(|d| c == d) {
+                match repair(chars, false) {
+                  None => { }
+                  Some(mut result) => {
+                    result.push(match open {
+                      '(' => ')',
+                      '[' => ']',
+                      '{' => '}',
+                      '<' => '>',
+                      _ => panic!("alas"),
+                    });
+                    return Some(result);
+                  }
+                }
+              } else {
+                let _ = chars.next();
+                if is_top_level {
+                  break;
+                } else {
+                  return None;
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+  }
+}
+
diff --git a/10/tests/main.rs b/10/tests/main.rs
new file mode 100644
index 0000000..ef0958a
--- /dev/null
+++ b/10/tests/main.rs
@@ -0,0 +1,17 @@
+use assert_cmd::prelude::*;
+//use predicates::prelude::*;
+use std::process::Command;
+
+
+#[test]
+fn personal_input() -> Result<(), Box<dyn std::error::Error>> {
+  let mut command = Command::cargo_bin("advent_10")?;
+
+  command.arg("input");
+  command.assert().success().stdout(
+      "387363\n\
+      4330777059\n");
+
+  Ok(())
+}
+
diff --git a/Cargo.lock b/Cargo.lock
index d1d0b51..a8c5722 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -73,6 +73,14 @@ dependencies = [
 ]
 
 [[package]]
+name = "advent_10"
+version = "0.1.0"
+dependencies = [
+ "advent_lib",
+ "assert_cmd",
+]
+
+[[package]]
 name = "advent_lib"
 version = "0.1.0"
 dependencies = [
diff --git a/Cargo.toml b/Cargo.toml
index f10de33..35009be 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,4 +10,5 @@ members = [
   "07",
   "08",
   "09",
+  "10",
 ]