advent-of-code

advent of code (partial solutions)
Log | Files | Refs | README

commit a6339400f1ca4c3ebe68ec7dd137e55ec6026242
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Wed, 13 Oct 2021 15:04:15 -0700

Initialize repo

Diffstat:
A2018/.gitignore | 2++
A2018/aoc01/Cargo.lock | 6++++++
A2018/aoc01/Cargo.toml | 7+++++++
A2018/aoc01/src/main.rs | 39+++++++++++++++++++++++++++++++++++++++
A2018/aoc02/Cargo.lock | 6++++++
A2018/aoc02/Cargo.toml | 7+++++++
A2018/aoc02/src/main.rs | 75+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2018/aoc03/Cargo.lock | 6++++++
A2018/aoc03/Cargo.toml | 7+++++++
A2018/aoc03/cargo | 1411+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2018/aoc03/ideas.md | 2++
A2018/aoc03/src/main.rs | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2018/aoc04/Cargo.lock | 146+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2018/aoc04/Cargo.toml | 10++++++++++
A2018/aoc04/src/main.rs | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2018/aoc05/Cargo.toml | 7+++++++
A2018/aoc05/src/main.rs | 3+++
A2018/readme.md | 1+
A2018/solutions.md | 3+++
A2019/README.md | 7+++++++
A2019/aoc01/Cargo.lock | 6++++++
A2019/aoc01/Cargo.toml | 9+++++++++
A2019/aoc01/src/main.rs | 34++++++++++++++++++++++++++++++++++
A2019/aoc02/Cargo.lock | 13+++++++++++++
A2019/aoc02/Cargo.toml | 10++++++++++
A2019/aoc02/src/main.rs | 7+++++++
A2019/aoc03/Cargo.lock | 6++++++
A2019/aoc03/Cargo.toml | 9+++++++++
A2019/aoc03/src/main.rs | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2019/aoc04/Cargo.lock | 6++++++
A2019/aoc04/Cargo.toml | 9+++++++++
A2019/aoc04/src/main.rs | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
A2019/aoc05/Cargo.lock | 6++++++
A2019/aoc05/Cargo.toml | 9+++++++++
A2019/aoc05/src/main.rs | 108+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2019/aoc06/Cargo.lock | 6++++++
A2019/aoc06/Cargo.toml | 9+++++++++
A2019/aoc06/src/main.rs | 36++++++++++++++++++++++++++++++++++++
A2019/aoc07/Cargo.lock | 30++++++++++++++++++++++++++++++
A2019/aoc07/Cargo.toml | 11+++++++++++
A2019/aoc07/src/main.rs | 59+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2019/aoc08/Cargo.lock | 6++++++
A2019/aoc08/Cargo.toml | 9+++++++++
A2019/aoc08/solution.py | 23+++++++++++++++++++++++
A2019/aoc08/src/main.rs | 70++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2019/aoc09/Cargo.lock | 13+++++++++++++
A2019/aoc09/Cargo.toml | 10++++++++++
A2019/aoc09/src/main.rs | 7+++++++
A2019/aoc10/Cargo.lock | 6++++++
A2019/aoc10/Cargo.toml | 9+++++++++
A2019/aoc10/src/main.rs | 188+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2019/aoc11/Cargo.lock | 13+++++++++++++
A2019/aoc11/Cargo.toml | 10++++++++++
A2019/aoc11/src/main.rs | 6++++++
A2019/aoc13/Cargo.lock | 13+++++++++++++
A2019/aoc13/Cargo.toml | 10++++++++++
A2019/aoc13/src/main.rs | 14++++++++++++++
A2019/aoc16/Cargo.lock | 6++++++
A2019/aoc16/Cargo.toml | 9+++++++++
A2019/aoc16/src/main.rs | 41+++++++++++++++++++++++++++++++++++++++++
A2019/aoc17/Cargo.toml | 9+++++++++
A2019/aoc17/src/main.rs | 3+++
A2019/aoc18/Cargo.lock | 6++++++
A2019/aoc18/Cargo.toml | 9+++++++++
A2019/aoc18/src/main.rs | 6++++++
A2019/aoc19/Cargo.lock | 13+++++++++++++
A2019/aoc19/Cargo.toml | 10++++++++++
A2019/aoc19/src/main.rs | 24++++++++++++++++++++++++
A2019/intcode/Cargo.lock | 6++++++
A2019/intcode/Cargo.toml | 9+++++++++
A2019/intcode/src/lib.rs | 222+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2019/run_all.sh | 12++++++++++++
A2020/.gitignore | 0
A2020/Makefile | 19+++++++++++++++++++
A2020/README | 13+++++++++++++
A2020/aoc01.c | 35+++++++++++++++++++++++++++++++++++
A2020/aoc02.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2020/aoc03.c | 47+++++++++++++++++++++++++++++++++++++++++++++++
A2020/aoc04.c | 139+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2020/aoc05.c | 36++++++++++++++++++++++++++++++++++++
A2020/aoc06.c | 42++++++++++++++++++++++++++++++++++++++++++
A2020/aoc07.py | 40++++++++++++++++++++++++++++++++++++++++
A2020/aoc08.c | 96+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2020/aoc09.c | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
A2020/aoc10.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2020/aoc11.c | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2020/aoc14.c | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A2020/aoc20.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AREADME | 7+++++++
89 files changed, 4164 insertions(+), 0 deletions(-)

diff --git a/2018/.gitignore b/2018/.gitignore @@ -0,0 +1,2 @@ +*/target/ +**/*.rs.bk diff --git a/2018/aoc01/Cargo.lock b/2018/aoc01/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc01" +version = "0.1.0" + diff --git a/2018/aoc01/Cargo.toml b/2018/aoc01/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aoc01" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +[dependencies] diff --git a/2018/aoc01/src/main.rs b/2018/aoc01/src/main.rs @@ -0,0 +1,39 @@ +// Re-did this to copy burntsushi's code basically +// https://github.com/BurntSushi/advent-of-code/blob/master/aoc01/src/main.rs +// + +use std::collections::HashSet; +use std::io::{self, Read}; + +fn main() { + let mut buffer = String::new(); + io::stdin().read_to_string(&mut buffer).unwrap(); + + part1(&buffer); + part2(&buffer); +} + +fn part1(input: &String) { + let mut result: i32 = 0; + for line in input.lines() { + result += line.parse::<i32>().unwrap(); + } + + println!(" part 1 answer: {}", result) +} + +fn part2(input: &String) { + let mut seen = HashSet::new(); + let mut current: i32 = 0; + seen.insert(current); + loop { + for line in input.lines() { + current += line.parse::<i32>().unwrap(); + if seen.contains(&current) { + println!(" part 2 answer: {}", current); + return + } + seen.insert(current); + } + } +} diff --git a/2018/aoc02/Cargo.lock b/2018/aoc02/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc-002" +version = "0.1.0" + diff --git a/2018/aoc02/Cargo.toml b/2018/aoc02/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aoc-002" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +[dependencies] diff --git a/2018/aoc02/src/main.rs b/2018/aoc02/src/main.rs @@ -0,0 +1,75 @@ +use std::collections::HashMap; +use std::fs::File; +use std::io::{self, Read}; + +fn main() { + let mut buffer = String::new(); + io::stdin().read_to_string(&mut buffer).unwrap(); + partone(&buffer); + parttwo(&buffer); +} + +fn partone(input: &String) { + let mut has_two_count = 0; + let mut has_three_count = 0; + for line_string in input.lines() { + let mut counter = HashMap::new(); + for character in line_string.chars() { + let count = counter.entry(character).or_insert(0); + *count += 1; + } + let mut has_two = false; + let mut has_three = false; + for (_, v) in &counter { + if *v == 3 { + has_three = true; + } + if *v == 2 { + has_two = true; + } + } + if has_two { + has_two_count += 1; + } + if has_three { + has_three_count += 1; + } + } + let checksum = has_two_count * has_three_count; + println!(" part 1 checksum: {}", checksum) +} + +fn parttwo(input: &String) { + for line_string in input.lines() { + let copy_string = input.clone(); + for substring in copy_string.lines() { + match compare_strings(line_string, substring) { + Some(v) => {println!(" part 2: {}", v); return} + None => {} + } + } + } +} + +fn compare_strings(a: &str, b: &str) -> Option<String> { + // check if off by 1 character + let comparison = a.chars().zip(b.chars()); + let mut num_diff = 0; + let mut output_string = String::new(); + for (a_char, b_char) in comparison { + if a_char != b_char { + num_diff += 1; + } + else { + output_string.push(a_char) + } + if num_diff > 1 { + break; + } + } + if num_diff == 1 { + return Some(output_string); + } else { + return None; + } +} diff --git a/2018/aoc03/Cargo.lock b/2018/aoc03/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc03" +version = "0.1.0" + diff --git a/2018/aoc03/Cargo.toml b/2018/aoc03/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aoc03" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +[dependencies] diff --git a/2018/aoc03/cargo b/2018/aoc03/cargo @@ -0,0 +1,1411 @@ +#1 @ 56,249: 24x16 +#2 @ 682,730: 13x20 +#3 @ 774,241: 22x23 +#4 @ 503,41: 17x15 +#5 @ 174,516: 17x15 +#6 @ 1,184: 16x24 +#7 @ 510,661: 15x29 +#8 @ 396,504: 23x26 +#9 @ 719,523: 26x20 +#10 @ 189,795: 20x24 +#11 @ 411,889: 20x16 +#12 @ 346,203: 29x22 +#13 @ 477,376: 18x27 +#14 @ 824,946: 15x29 +#15 @ 823,32: 23x26 +#16 @ 124,118: 20x18 +#17 @ 675,632: 22x26 +#18 @ 925,385: 22x15 +#19 @ 276,345: 16x13 +#20 @ 24,322: 19x23 +#21 @ 527,844: 23x26 +#22 @ 862,187: 24x27 +#23 @ 58,384: 13x20 +#24 @ 835,921: 22x12 +#25 @ 395,446: 21x27 +#26 @ 769,46: 14x19 +#27 @ 972,909: 21x10 +#28 @ 178,504: 12x28 +#29 @ 907,572: 10x21 +#30 @ 90,810: 25x12 +#31 @ 716,408: 11x26 +#32 @ 160,501: 11x10 +#33 @ 163,839: 22x26 +#34 @ 514,876: 20x26 +#35 @ 706,144: 26x16 +#36 @ 872,226: 11x17 +#37 @ 578,619: 26x15 +#38 @ 218,638: 17x21 +#39 @ 171,362: 17x17 +#40 @ 263,499: 11x14 +#41 @ 509,614: 21x14 +#42 @ 415,287: 10x24 +#43 @ 922,801: 13x25 +#44 @ 167,753: 29x10 +#45 @ 795,441: 18x22 +#46 @ 803,590: 15x27 +#47 @ 543,443: 22x15 +#48 @ 944,275: 21x15 +#49 @ 43,556: 22x29 +#50 @ 5,141: 13x23 +#51 @ 69,593: 12x19 +#52 @ 843,688: 14x25 +#53 @ 785,498: 23x29 +#54 @ 581,191: 11x29 +#55 @ 716,623: 19x13 +#56 @ 146,494: 28x29 +#57 @ 879,923: 29x23 +#58 @ 777,194: 17x17 +#59 @ 856,869: 18x19 +#60 @ 160,869: 22x12 +#61 @ 6,602: 15x24 +#62 @ 536,814: 18x17 +#63 @ 600,404: 22x23 +#64 @ 717,183: 27x26 +#65 @ 708,925: 16x15 +#66 @ 135,628: 27x17 +#67 @ 788,604: 28x27 +#68 @ 668,649: 19x27 +#69 @ 949,938: 11x25 +#70 @ 187,587: 17x10 +#71 @ 621,692: 22x27 +#72 @ 939,485: 18x12 +#73 @ 838,674: 27x18 +#74 @ 567,398: 13x10 +#75 @ 395,883: 10x22 +#76 @ 754,327: 28x21 +#77 @ 514,201: 26x13 +#78 @ 749,396: 10x11 +#79 @ 173,877: 11x17 +#80 @ 880,764: 15x25 +#81 @ 772,669: 10x11 +#82 @ 961,272: 16x22 +#83 @ 253,493: 10x20 +#84 @ 541,569: 19x18 +#85 @ 420,247: 24x19 +#86 @ 536,944: 10x21 +#87 @ 560,428: 21x26 +#88 @ 558,971: 28x21 +#89 @ 970,399: 14x22 +#90 @ 724,569: 19x11 +#91 @ 274,830: 21x28 +#92 @ 358,451: 29x13 +#93 @ 388,527: 19x13 +#94 @ 968,814: 14x20 +#95 @ 596,54: 26x12 +#96 @ 473,832: 14x14 +#97 @ 154,393: 22x28 +#98 @ 221,736: 29x12 +#99 @ 328,766: 11x10 +#100 @ 959,790: 15x28 +#101 @ 43,30: 14x18 +#102 @ 27,918: 25x13 +#103 @ 24,507: 19x17 +#104 @ 922,708: 15x12 +#105 @ 794,179: 13x10 +#106 @ 537,476: 26x16 +#107 @ 859,463: 27x26 +#108 @ 686,401: 21x19 +#109 @ 469,56: 22x17 +#110 @ 727,493: 24x25 +#111 @ 596,85: 25x13 +#112 @ 632,77: 6x8 +#113 @ 621,389: 20x25 +#114 @ 311,404: 21x20 +#115 @ 13,600: 21x24 +#116 @ 69,595: 28x21 +#117 @ 33,920: 18x22 +#118 @ 667,370: 19x18 +#119 @ 437,639: 13x22 +#120 @ 879,633: 28x21 +#121 @ 400,551: 21x10 +#122 @ 70,105: 24x26 +#123 @ 705,318: 14x21 +#124 @ 17,34: 19x16 +#125 @ 922,408: 18x23 +#126 @ 56,231: 14x21 +#127 @ 156,383: 25x28 +#128 @ 562,569: 24x11 +#129 @ 103,382: 26x22 +#130 @ 691,346: 28x18 +#131 @ 750,145: 28x27 +#132 @ 924,789: 29x14 +#133 @ 441,775: 29x10 +#134 @ 189,873: 24x14 +#135 @ 477,440: 15x23 +#136 @ 174,876: 20x22 +#137 @ 873,697: 24x13 +#138 @ 874,755: 10x17 +#139 @ 865,691: 12x26 +#140 @ 390,449: 21x20 +#141 @ 388,198: 26x18 +#142 @ 942,242: 29x29 +#143 @ 65,611: 11x28 +#144 @ 47,415: 11x16 +#145 @ 44,788: 16x25 +#146 @ 756,589: 11x11 +#147 @ 228,212: 25x24 +#148 @ 291,163: 10x12 +#149 @ 934,763: 25x29 +#150 @ 475,932: 18x22 +#151 @ 984,649: 11x11 +#152 @ 518,241: 22x29 +#153 @ 807,279: 16x19 +#154 @ 361,732: 23x24 +#155 @ 706,748: 15x12 +#156 @ 651,388: 22x27 +#157 @ 510,820: 18x20 +#158 @ 589,448: 15x12 +#159 @ 345,479: 29x11 +#160 @ 145,746: 24x28 +#161 @ 954,869: 25x16 +#162 @ 165,854: 11x15 +#163 @ 463,256: 12x27 +#164 @ 332,653: 21x13 +#165 @ 978,945: 16x22 +#166 @ 868,516: 29x13 +#167 @ 433,782: 27x29 +#168 @ 400,789: 14x11 +#169 @ 183,366: 28x14 +#170 @ 356,56: 18x21 +#171 @ 703,595: 18x26 +#172 @ 479,19: 16x28 +#173 @ 844,751: 21x12 +#174 @ 164,508: 11x10 +#175 @ 140,49: 26x22 +#176 @ 701,48: 10x20 +#177 @ 42,785: 22x15 +#178 @ 912,932: 10x22 +#179 @ 836,149: 10x24 +#180 @ 587,285: 17x29 +#181 @ 137,758: 29x18 +#182 @ 731,72: 29x21 +#183 @ 883,441: 26x12 +#184 @ 910,484: 16x13 +#185 @ 795,699: 12x14 +#186 @ 396,461: 12x14 +#187 @ 16,788: 22x24 +#188 @ 423,243: 21x23 +#189 @ 790,615: 23x12 +#190 @ 923,394: 24x29 +#191 @ 695,658: 16x12 +#192 @ 276,973: 17x20 +#193 @ 269,868: 10x17 +#194 @ 945,647: 14x27 +#195 @ 218,924: 12x29 +#196 @ 567,421: 10x20 +#197 @ 85,757: 20x17 +#198 @ 714,168: 14x17 +#199 @ 109,517: 27x19 +#200 @ 391,215: 26x27 +#201 @ 390,772: 12x21 +#202 @ 350,338: 11x12 +#203 @ 340,316: 11x10 +#204 @ 376,459: 27x17 +#205 @ 56,832: 19x15 +#206 @ 565,70: 10x4 +#207 @ 148,892: 18x13 +#208 @ 863,163: 15x22 +#209 @ 278,449: 24x19 +#210 @ 458,127: 12x24 +#211 @ 374,218: 14x21 +#212 @ 692,942: 24x15 +#213 @ 957,700: 24x17 +#214 @ 548,448: 11x18 +#215 @ 392,379: 18x20 +#216 @ 802,279: 17x14 +#217 @ 155,914: 26x14 +#218 @ 500,152: 10x21 +#219 @ 329,325: 28x25 +#220 @ 200,762: 18x15 +#221 @ 640,227: 15x17 +#222 @ 132,611: 17x23 +#223 @ 87,247: 20x16 +#224 @ 171,388: 20x22 +#225 @ 343,181: 11x27 +#226 @ 551,954: 17x24 +#227 @ 123,823: 23x27 +#228 @ 771,224: 26x15 +#229 @ 56,80: 26x13 +#230 @ 118,575: 28x29 +#231 @ 769,879: 24x20 +#232 @ 519,943: 25x29 +#233 @ 897,393: 15x19 +#234 @ 202,805: 25x20 +#235 @ 745,590: 23x28 +#236 @ 540,300: 17x25 +#237 @ 741,573: 11x17 +#238 @ 718,174: 6x7 +#239 @ 921,424: 19x26 +#240 @ 641,730: 18x14 +#241 @ 215,397: 18x12 +#242 @ 262,633: 22x18 +#243 @ 730,904: 23x23 +#244 @ 323,305: 29x14 +#245 @ 719,29: 12x23 +#246 @ 923,670: 27x13 +#247 @ 964,338: 13x26 +#248 @ 13,648: 17x21 +#249 @ 137,757: 11x12 +#250 @ 799,185: 24x20 +#251 @ 521,663: 26x11 +#252 @ 580,188: 29x26 +#253 @ 531,384: 17x28 +#254 @ 46,320: 20x21 +#255 @ 548,351: 23x20 +#256 @ 136,64: 25x24 +#257 @ 373,319: 12x22 +#258 @ 238,949: 16x27 +#259 @ 323,316: 13x11 +#260 @ 960,172: 15x18 +#261 @ 743,391: 15x17 +#262 @ 229,535: 11x25 +#263 @ 776,521: 14x20 +#264 @ 803,763: 14x24 +#265 @ 898,616: 19x18 +#266 @ 97,240: 25x14 +#267 @ 716,347: 13x29 +#268 @ 1,136: 23x28 +#269 @ 521,824: 24x13 +#270 @ 204,824: 15x20 +#271 @ 123,808: 14x18 +#272 @ 958,885: 21x19 +#273 @ 456,580: 10x11 +#274 @ 160,579: 24x15 +#275 @ 500,468: 19x28 +#276 @ 282,826: 15x16 +#277 @ 444,312: 11x13 +#278 @ 334,715: 8x3 +#279 @ 723,604: 25x25 +#280 @ 898,173: 20x13 +#281 @ 357,8: 14x19 +#282 @ 522,649: 26x17 +#283 @ 676,863: 17x17 +#284 @ 603,972: 3x7 +#285 @ 290,330: 21x25 +#286 @ 508,45: 13x16 +#287 @ 464,402: 16x19 +#288 @ 383,427: 21x21 +#289 @ 80,125: 21x11 +#290 @ 399,639: 23x19 +#291 @ 461,929: 23x11 +#292 @ 921,185: 24x24 +#293 @ 947,249: 17x21 +#294 @ 676,504: 15x11 +#295 @ 252,950: 11x25 +#296 @ 125,918: 27x27 +#297 @ 136,729: 10x15 +#298 @ 645,166: 18x28 +#299 @ 477,835: 25x28 +#300 @ 330,303: 20x15 +#301 @ 796,398: 19x26 +#302 @ 125,408: 28x15 +#303 @ 206,774: 25x17 +#304 @ 380,794: 12x15 +#305 @ 435,242: 12x22 +#306 @ 258,343: 23x15 +#307 @ 8,119: 29x23 +#308 @ 899,941: 20x17 +#309 @ 838,59: 21x15 +#310 @ 971,355: 24x17 +#311 @ 810,178: 19x14 +#312 @ 223,629: 24x23 +#313 @ 208,145: 18x22 +#314 @ 400,815: 11x14 +#315 @ 866,630: 22x28 +#316 @ 32,283: 20x25 +#317 @ 120,560: 29x26 +#318 @ 916,420: 13x12 +#319 @ 800,122: 17x20 +#320 @ 126,522: 13x10 +#321 @ 608,494: 11x16 +#322 @ 569,420: 12x10 +#323 @ 563,435: 23x12 +#324 @ 739,606: 17x10 +#325 @ 900,756: 18x18 +#326 @ 877,317: 11x16 +#327 @ 754,29: 27x23 +#328 @ 926,466: 10x24 +#329 @ 760,890: 29x27 +#330 @ 216,328: 27x28 +#331 @ 123,782: 29x11 +#332 @ 630,142: 20x27 +#333 @ 480,293: 10x13 +#334 @ 941,803: 22x11 +#335 @ 448,260: 17x23 +#336 @ 188,500: 16x18 +#337 @ 621,398: 15x22 +#338 @ 356,770: 19x27 +#339 @ 767,162: 10x16 +#340 @ 587,184: 18x23 +#341 @ 641,49: 14x11 +#342 @ 625,418: 16x16 +#343 @ 131,172: 23x27 +#344 @ 740,918: 20x13 +#345 @ 256,861: 23x25 +#346 @ 49,961: 12x16 +#347 @ 161,62: 28x14 +#348 @ 663,628: 24x21 +#349 @ 673,725: 12x15 +#350 @ 39,920: 6x7 +#351 @ 28,328: 12x28 +#352 @ 703,53: 28x10 +#353 @ 158,206: 25x29 +#354 @ 669,634: 13x25 +#355 @ 4,635: 28x17 +#356 @ 52,430: 21x16 +#357 @ 878,210: 13x19 +#358 @ 436,477: 6x6 +#359 @ 415,63: 21x28 +#360 @ 103,424: 23x25 +#361 @ 463,843: 12x18 +#362 @ 830,926: 10x11 +#363 @ 142,618: 18x23 +#364 @ 430,236: 14x12 +#365 @ 920,417: 15x17 +#366 @ 922,417: 18x23 +#367 @ 960,184: 13x12 +#368 @ 659,34: 24x26 +#369 @ 912,619: 19x18 +#370 @ 336,306: 12x27 +#371 @ 906,691: 22x22 +#372 @ 472,528: 10x29 +#373 @ 972,642: 13x29 +#374 @ 738,288: 28x27 +#375 @ 741,711: 20x18 +#376 @ 962,463: 15x20 +#377 @ 157,249: 16x22 +#378 @ 155,220: 24x21 +#379 @ 763,329: 21x22 +#380 @ 663,204: 14x28 +#381 @ 692,25: 16x18 +#382 @ 938,796: 25x16 +#383 @ 127,143: 29x19 +#384 @ 27,658: 21x14 +#385 @ 840,140: 15x22 +#386 @ 946,264: 19x13 +#387 @ 207,441: 24x14 +#388 @ 369,943: 20x26 +#389 @ 801,319: 29x14 +#390 @ 562,677: 20x27 +#391 @ 110,962: 21x22 +#392 @ 788,841: 18x26 +#393 @ 92,886: 19x21 +#394 @ 534,803: 29x25 +#395 @ 400,661: 16x15 +#396 @ 730,237: 20x27 +#397 @ 970,794: 17x28 +#398 @ 399,556: 23x15 +#399 @ 422,200: 16x14 +#400 @ 395,398: 21x10 +#401 @ 354,858: 26x17 +#402 @ 806,121: 14x29 +#403 @ 40,719: 17x17 +#404 @ 223,647: 16x23 +#405 @ 744,68: 10x24 +#406 @ 668,506: 16x20 +#407 @ 423,982: 23x17 +#408 @ 939,248: 11x24 +#409 @ 776,82: 19x16 +#410 @ 486,446: 16x10 +#411 @ 629,377: 16x18 +#412 @ 450,550: 26x17 +#413 @ 801,403: 18x26 +#414 @ 781,386: 26x23 +#415 @ 862,423: 10x23 +#416 @ 175,614: 25x15 +#417 @ 879,651: 11x10 +#418 @ 55,58: 23x23 +#419 @ 693,616: 21x25 +#420 @ 437,408: 12x21 +#421 @ 250,464: 12x14 +#422 @ 948,314: 17x24 +#423 @ 2,29: 17x24 +#424 @ 925,671: 12x13 +#425 @ 431,622: 12x22 +#426 @ 174,244: 12x29 +#427 @ 169,916: 24x24 +#428 @ 498,761: 25x24 +#429 @ 935,383: 11x20 +#430 @ 816,919: 18x14 +#431 @ 612,585: 19x22 +#432 @ 950,889: 23x21 +#433 @ 449,426: 16x12 +#434 @ 225,812: 23x26 +#435 @ 17,686: 29x23 +#436 @ 773,111: 20x15 +#437 @ 746,602: 22x10 +#438 @ 892,743: 19x25 +#439 @ 106,432: 24x19 +#440 @ 186,899: 13x25 +#441 @ 379,227: 21x13 +#442 @ 421,303: 24x13 +#443 @ 952,713: 16x27 +#444 @ 225,923: 23x29 +#445 @ 795,31: 12x12 +#446 @ 618,116: 17x26 +#447 @ 626,614: 11x16 +#448 @ 678,63: 26x15 +#449 @ 217,933: 19x24 +#450 @ 706,914: 28x15 +#451 @ 450,742: 25x21 +#452 @ 358,84: 14x29 +#453 @ 777,144: 24x13 +#454 @ 162,936: 18x15 +#455 @ 826,59: 8x16 +#456 @ 148,516: 29x16 +#457 @ 620,443: 27x27 +#458 @ 58,713: 13x24 +#459 @ 183,475: 26x29 +#460 @ 31,452: 28x12 +#461 @ 592,623: 22x28 +#462 @ 585,770: 20x22 +#463 @ 453,534: 19x18 +#464 @ 157,891: 26x20 +#465 @ 645,222: 14x19 +#466 @ 258,259: 23x17 +#467 @ 295,682: 12x5 +#468 @ 398,273: 16x12 +#469 @ 890,128: 25x11 +#470 @ 936,254: 26x26 +#471 @ 526,644: 28x17 +#472 @ 103,758: 16x25 +#473 @ 727,238: 29x16 +#474 @ 918,597: 11x25 +#475 @ 628,71: 15x23 +#476 @ 276,828: 17x11 +#477 @ 565,202: 27x15 +#478 @ 155,668: 19x20 +#479 @ 171,471: 15x27 +#480 @ 719,53: 29x26 +#481 @ 390,645: 26x22 +#482 @ 527,858: 12x11 +#483 @ 284,235: 18x13 +#484 @ 491,822: 28x17 +#485 @ 693,29: 12x10 +#486 @ 281,238: 18x13 +#487 @ 972,273: 18x23 +#488 @ 846,835: 19x29 +#489 @ 86,237: 24x27 +#490 @ 715,31: 16x12 +#491 @ 658,569: 3x16 +#492 @ 749,45: 15x17 +#493 @ 586,62: 23x24 +#494 @ 176,849: 19x29 +#495 @ 736,673: 10x19 +#496 @ 339,469: 12x16 +#497 @ 231,88: 17x28 +#498 @ 706,332: 22x18 +#499 @ 570,251: 19x25 +#500 @ 567,692: 17x26 +#501 @ 267,890: 27x25 +#502 @ 872,176: 22x12 +#503 @ 611,396: 14x26 +#504 @ 220,809: 16x26 +#505 @ 809,830: 13x23 +#506 @ 761,101: 14x22 +#507 @ 223,12: 12x23 +#508 @ 554,37: 19x11 +#509 @ 186,756: 20x13 +#510 @ 502,692: 28x15 +#511 @ 625,338: 11x29 +#512 @ 128,115: 26x21 +#513 @ 957,247: 25x20 +#514 @ 401,268: 25x23 +#515 @ 511,650: 25x17 +#516 @ 43,26: 25x25 +#517 @ 916,477: 22x11 +#518 @ 942,157: 20x17 +#519 @ 9,321: 29x25 +#520 @ 789,25: 16x15 +#521 @ 902,171: 29x18 +#522 @ 807,597: 10x12 +#523 @ 51,807: 15x23 +#524 @ 826,479: 20x20 +#525 @ 426,181: 12x21 +#526 @ 892,150: 16x29 +#527 @ 562,598: 12x11 +#528 @ 636,481: 15x28 +#529 @ 446,205: 23x15 +#530 @ 143,583: 18x29 +#531 @ 508,247: 12x23 +#532 @ 596,858: 18x16 +#533 @ 365,378: 13x20 +#534 @ 157,175: 24x21 +#535 @ 262,517: 16x15 +#536 @ 723,803: 8x5 +#537 @ 8,157: 22x19 +#538 @ 69,284: 28x16 +#539 @ 496,632: 23x13 +#540 @ 781,176: 20x13 +#541 @ 624,180: 17x17 +#542 @ 413,834: 14x10 +#543 @ 633,366: 29x25 +#544 @ 108,188: 14x24 +#545 @ 502,216: 21x10 +#546 @ 83,183: 13x17 +#547 @ 708,164: 15x28 +#548 @ 359,318: 21x26 +#549 @ 967,915: 18x25 +#550 @ 169,511: 15x25 +#551 @ 947,331: 18x12 +#552 @ 478,217: 26x21 +#553 @ 822,122: 22x28 +#554 @ 719,678: 12x16 +#555 @ 807,359: 20x20 +#556 @ 16,639: 9x9 +#557 @ 244,933: 24x12 +#558 @ 367,577: 13x11 +#559 @ 164,919: 21x21 +#560 @ 673,732: 18x10 +#561 @ 843,508: 27x28 +#562 @ 271,626: 19x12 +#563 @ 805,375: 28x12 +#564 @ 369,509: 15x27 +#565 @ 446,862: 25x21 +#566 @ 262,910: 28x18 +#567 @ 241,249: 19x22 +#568 @ 642,138: 13x29 +#569 @ 647,159: 22x25 +#570 @ 956,375: 25x28 +#571 @ 565,915: 21x18 +#572 @ 884,449: 27x18 +#573 @ 254,493: 16x24 +#574 @ 231,577: 21x13 +#575 @ 573,336: 14x8 +#576 @ 44,414: 25x27 +#577 @ 41,381: 25x27 +#578 @ 429,530: 29x12 +#579 @ 245,24: 12x29 +#580 @ 592,182: 22x29 +#581 @ 66,40: 16x12 +#582 @ 833,508: 19x25 +#583 @ 14,322: 10x27 +#584 @ 173,825: 24x22 +#585 @ 79,662: 28x19 +#586 @ 105,53: 13x15 +#587 @ 369,597: 12x12 +#588 @ 624,37: 23x14 +#589 @ 155,415: 13x18 +#590 @ 643,466: 16x16 +#591 @ 103,254: 18x21 +#592 @ 485,920: 11x10 +#593 @ 495,316: 16x29 +#594 @ 717,604: 18x27 +#595 @ 906,817: 26x29 +#596 @ 353,320: 29x26 +#597 @ 823,322: 14x18 +#598 @ 58,815: 12x28 +#599 @ 165,154: 22x24 +#600 @ 690,330: 27x18 +#601 @ 416,930: 16x26 +#602 @ 799,424: 10x11 +#603 @ 346,662: 10x23 +#604 @ 208,500: 27x23 +#605 @ 642,368: 22x13 +#606 @ 855,102: 28x22 +#607 @ 682,310: 27x13 +#608 @ 464,16: 20x15 +#609 @ 116,379: 14x10 +#610 @ 499,198: 23x29 +#611 @ 943,863: 26x18 +#612 @ 797,178: 28x26 +#613 @ 885,383: 28x22 +#614 @ 535,291: 22x28 +#615 @ 888,126: 10x28 +#616 @ 656,823: 13x18 +#617 @ 22,640: 3x9 +#618 @ 105,569: 19x21 +#619 @ 598,911: 11x11 +#620 @ 842,364: 28x15 +#621 @ 116,529: 18x10 +#622 @ 630,760: 21x16 +#623 @ 827,721: 14x19 +#624 @ 235,104: 8x7 +#625 @ 74,164: 11x15 +#626 @ 889,943: 29x21 +#627 @ 74,155: 26x22 +#628 @ 790,76: 26x28 +#629 @ 809,349: 10x22 +#630 @ 793,324: 10x24 +#631 @ 154,151: 18x20 +#632 @ 600,145: 14x20 +#633 @ 26,806: 28x18 +#634 @ 376,515: 13x14 +#635 @ 170,478: 24x25 +#636 @ 626,749: 20x19 +#637 @ 739,254: 22x22 +#638 @ 135,634: 25x15 +#639 @ 238,1: 26x26 +#640 @ 343,277: 19x12 +#641 @ 606,683: 16x23 +#642 @ 597,951: 12x11 +#643 @ 173,932: 27x24 +#644 @ 865,295: 29x15 +#645 @ 847,902: 15x11 +#646 @ 434,475: 12x13 +#647 @ 590,271: 10x21 +#648 @ 776,50: 28x15 +#649 @ 698,935: 26x18 +#650 @ 599,751: 20x26 +#651 @ 797,390: 14x17 +#652 @ 257,335: 19x27 +#653 @ 73,876: 22x28 +#654 @ 710,698: 10x13 +#655 @ 368,318: 18x23 +#656 @ 80,179: 16x20 +#657 @ 5,957: 21x28 +#658 @ 885,768: 18x13 +#659 @ 734,414: 10x13 +#660 @ 779,520: 23x23 +#661 @ 615,604: 11x12 +#662 @ 747,253: 28x18 +#663 @ 66,285: 10x22 +#664 @ 350,543: 12x24 +#665 @ 526,77: 19x18 +#666 @ 824,888: 14x16 +#667 @ 365,567: 18x26 +#668 @ 597,550: 22x16 +#669 @ 874,613: 19x19 +#670 @ 730,91: 14x14 +#671 @ 882,284: 27x13 +#672 @ 902,117: 10x10 +#673 @ 610,497: 6x9 +#674 @ 583,646: 25x16 +#675 @ 797,824: 27x22 +#676 @ 156,570: 19x12 +#677 @ 118,94: 12x11 +#678 @ 515,626: 11x17 +#679 @ 947,286: 20x10 +#680 @ 885,51: 23x23 +#681 @ 280,636: 11x27 +#682 @ 610,392: 28x15 +#683 @ 575,134: 17x20 +#684 @ 978,455: 22x16 +#685 @ 637,282: 21x17 +#686 @ 486,662: 25x29 +#687 @ 655,489: 21x29 +#688 @ 369,451: 14x17 +#689 @ 127,416: 21x25 +#690 @ 910,899: 12x11 +#691 @ 952,342: 10x19 +#692 @ 182,517: 13x29 +#693 @ 171,159: 22x19 +#694 @ 721,801: 25x11 +#695 @ 438,472: 27x26 +#696 @ 974,4: 16x29 +#697 @ 47,35: 10x18 +#698 @ 802,380: 19x13 +#699 @ 652,2: 15x13 +#700 @ 828,712: 13x13 +#701 @ 154,147: 17x12 +#702 @ 706,327: 14x13 +#703 @ 551,100: 28x27 +#704 @ 454,923: 10x24 +#705 @ 590,66: 18x14 +#706 @ 943,158: 12x25 +#707 @ 974,324: 11x24 +#708 @ 968,931: 25x21 +#709 @ 249,203: 10x21 +#710 @ 909,210: 15x22 +#711 @ 404,659: 17x21 +#712 @ 317,281: 29x19 +#713 @ 174,58: 13x27 +#714 @ 16,646: 13x25 +#715 @ 216,369: 26x16 +#716 @ 960,257: 29x21 +#717 @ 969,867: 21x21 +#718 @ 357,583: 29x21 +#719 @ 554,21: 24x17 +#720 @ 934,332: 16x16 +#721 @ 451,877: 27x21 +#722 @ 584,47: 12x25 +#723 @ 707,748: 19x16 +#724 @ 754,93: 29x20 +#725 @ 310,862: 24x10 +#726 @ 127,472: 29x21 +#727 @ 183,34: 10x11 +#728 @ 503,489: 20x23 +#729 @ 770,27: 10x18 +#730 @ 526,272: 10x5 +#731 @ 742,213: 22x14 +#732 @ 936,798: 22x19 +#733 @ 735,318: 27x23 +#734 @ 615,460: 27x22 +#735 @ 643,426: 26x28 +#736 @ 696,657: 22x24 +#737 @ 319,771: 19x19 +#738 @ 721,277: 28x16 +#739 @ 257,342: 13x22 +#740 @ 950,859: 13x16 +#741 @ 244,369: 26x11 +#742 @ 386,227: 26x12 +#743 @ 680,670: 11x24 +#744 @ 447,316: 15x25 +#745 @ 157,899: 23x20 +#746 @ 646,279: 16x17 +#747 @ 9,185: 24x26 +#748 @ 969,900: 26x20 +#749 @ 973,876: 10x12 +#750 @ 235,449: 17x11 +#751 @ 934,800: 12x13 +#752 @ 642,144: 25x14 +#753 @ 645,27: 25x24 +#754 @ 174,272: 22x14 +#755 @ 24,541: 29x16 +#756 @ 796,380: 22x15 +#757 @ 681,765: 19x22 +#758 @ 133,102: 25x22 +#759 @ 174,845: 20x25 +#760 @ 568,394: 14x25 +#761 @ 59,245: 27x17 +#762 @ 369,596: 25x15 +#763 @ 13,633: 21x21 +#764 @ 949,458: 22x21 +#765 @ 47,958: 16x28 +#766 @ 781,673: 12x26 +#767 @ 944,811: 16x24 +#768 @ 98,45: 21x13 +#769 @ 308,781: 20x13 +#770 @ 382,206: 24x18 +#771 @ 367,773: 19x29 +#772 @ 842,735: 27x25 +#773 @ 89,458: 16x23 +#774 @ 435,238: 4x3 +#775 @ 376,327: 11x18 +#776 @ 167,16: 21x23 +#777 @ 832,77: 15x14 +#778 @ 800,490: 28x23 +#779 @ 209,462: 18x15 +#780 @ 445,492: 14x23 +#781 @ 38,486: 19x22 +#782 @ 845,489: 26x29 +#783 @ 328,789: 17x25 +#784 @ 327,305: 27x29 +#785 @ 957,97: 25x21 +#786 @ 69,169: 10x14 +#787 @ 626,227: 20x29 +#788 @ 190,589: 4x4 +#789 @ 817,119: 18x14 +#790 @ 861,514: 14x10 +#791 @ 770,180: 19x16 +#792 @ 403,900: 17x12 +#793 @ 532,923: 15x25 +#794 @ 966,361: 26x19 +#795 @ 628,400: 26x25 +#796 @ 794,759: 15x21 +#797 @ 909,211: 21x12 +#798 @ 67,402: 28x16 +#799 @ 524,270: 15x11 +#800 @ 665,360: 20x12 +#801 @ 898,41: 25x15 +#802 @ 307,387: 16x23 +#803 @ 210,323: 24x26 +#804 @ 570,332: 29x23 +#805 @ 660,619: 27x12 +#806 @ 556,536: 26x17 +#807 @ 349,306: 10x26 +#808 @ 287,678: 25x22 +#809 @ 522,796: 15x25 +#810 @ 388,802: 15x19 +#811 @ 472,188: 24x15 +#812 @ 422,247: 26x20 +#813 @ 371,934: 21x19 +#814 @ 112,226: 20x15 +#815 @ 233,12: 23x19 +#816 @ 492,131: 10x23 +#817 @ 540,578: 19x12 +#818 @ 142,624: 12x10 +#819 @ 50,732: 11x25 +#820 @ 462,196: 18x17 +#821 @ 161,631: 28x21 +#822 @ 915,66: 28x29 +#823 @ 149,218: 12x24 +#824 @ 209,322: 29x25 +#825 @ 586,527: 18x10 +#826 @ 772,344: 26x25 +#827 @ 600,522: 12x21 +#828 @ 975,346: 17x27 +#829 @ 710,244: 10x22 +#830 @ 189,930: 25x21 +#831 @ 618,614: 11x14 +#832 @ 500,203: 16x20 +#833 @ 817,57: 25x22 +#834 @ 198,932: 16x11 +#835 @ 74,277: 15x17 +#836 @ 559,289: 12x29 +#837 @ 240,942: 14x26 +#838 @ 938,98: 10x27 +#839 @ 599,508: 24x18 +#840 @ 547,636: 20x10 +#841 @ 639,127: 13x24 +#842 @ 558,689: 28x15 +#843 @ 846,635: 22x21 +#844 @ 571,773: 28x17 +#845 @ 697,687: 18x24 +#846 @ 350,208: 16x24 +#847 @ 248,639: 17x10 +#848 @ 468,840: 14x29 +#849 @ 965,911: 23x21 +#850 @ 632,779: 17x21 +#851 @ 801,310: 11x21 +#852 @ 161,492: 12x21 +#853 @ 594,593: 21x19 +#854 @ 879,271: 13x25 +#855 @ 705,76: 29x21 +#856 @ 847,151: 22x12 +#857 @ 577,396: 23x20 +#858 @ 246,708: 18x28 +#859 @ 969,100: 4x5 +#860 @ 643,703: 10x29 +#861 @ 222,935: 29x23 +#862 @ 872,761: 12x22 +#863 @ 886,932: 11x10 +#864 @ 936,948: 19x12 +#865 @ 29,34: 14x22 +#866 @ 787,231: 17x29 +#867 @ 481,263: 16x17 +#868 @ 440,247: 13x13 +#869 @ 327,774: 14x29 +#870 @ 20,948: 11x11 +#871 @ 368,523: 16x23 +#872 @ 921,206: 13x28 +#873 @ 886,939: 10x13 +#874 @ 962,75: 10x17 +#875 @ 153,851: 26x27 +#876 @ 919,446: 14x17 +#877 @ 736,539: 21x10 +#878 @ 886,129: 27x15 +#879 @ 828,731: 21x18 +#880 @ 400,657: 23x13 +#881 @ 164,209: 27x15 +#882 @ 743,75: 9x14 +#883 @ 390,102: 25x21 +#884 @ 56,626: 17x21 +#885 @ 587,269: 26x13 +#886 @ 529,152: 13x20 +#887 @ 121,948: 27x27 +#888 @ 145,270: 25x23 +#889 @ 55,926: 12x23 +#890 @ 724,370: 29x29 +#891 @ 922,609: 23x15 +#892 @ 525,468: 24x26 +#893 @ 554,937: 11x24 +#894 @ 217,471: 22x27 +#895 @ 314,281: 10x26 +#896 @ 653,457: 12x25 +#897 @ 739,541: 24x10 +#898 @ 642,376: 14x26 +#899 @ 132,520: 22x25 +#900 @ 635,769: 3x15 +#901 @ 884,755: 25x24 +#902 @ 712,334: 10x11 +#903 @ 494,760: 28x17 +#904 @ 165,612: 16x22 +#905 @ 779,183: 18x20 +#906 @ 900,464: 17x23 +#907 @ 867,768: 26x22 +#908 @ 831,78: 19x14 +#909 @ 586,477: 26x12 +#910 @ 534,646: 25x18 +#911 @ 372,471: 26x17 +#912 @ 926,831: 14x11 +#913 @ 840,686: 21x11 +#914 @ 710,676: 13x17 +#915 @ 442,244: 19x23 +#916 @ 70,595: 25x12 +#917 @ 34,921: 25x21 +#918 @ 271,330: 26x22 +#919 @ 470,254: 14x22 +#920 @ 142,906: 25x15 +#921 @ 439,425: 15x15 +#922 @ 600,970: 12x15 +#923 @ 482,4: 23x22 +#924 @ 203,175: 17x13 +#925 @ 102,725: 18x17 +#926 @ 969,757: 16x11 +#927 @ 430,942: 11x16 +#928 @ 723,182: 18x29 +#929 @ 773,222: 11x19 +#930 @ 32,20: 19x28 +#931 @ 817,929: 18x21 +#932 @ 560,593: 11x16 +#933 @ 576,81: 29x25 +#934 @ 212,559: 29x14 +#935 @ 402,635: 19x18 +#936 @ 792,696: 14x21 +#937 @ 518,652: 11x4 +#938 @ 492,750: 27x15 +#939 @ 688,224: 27x21 +#940 @ 890,114: 16x19 +#941 @ 944,295: 22x22 +#942 @ 41,640: 19x25 +#943 @ 376,371: 11x19 +#944 @ 148,510: 16x20 +#945 @ 815,930: 18x12 +#946 @ 947,299: 26x22 +#947 @ 153,882: 10x13 +#948 @ 754,209: 23x15 +#949 @ 492,90: 25x13 +#950 @ 877,225: 17x19 +#951 @ 729,147: 20x17 +#952 @ 162,464: 21x27 +#953 @ 684,882: 28x28 +#954 @ 698,255: 24x16 +#955 @ 349,8: 27x24 +#956 @ 67,13: 19x25 +#957 @ 170,860: 12x16 +#958 @ 411,947: 23x25 +#959 @ 858,516: 17x29 +#960 @ 609,390: 13x14 +#961 @ 513,84: 21x11 +#962 @ 867,298: 18x8 +#963 @ 89,661: 16x14 +#964 @ 435,654: 14x19 +#965 @ 519,153: 11x10 +#966 @ 280,975: 20x20 +#967 @ 13,326: 11x11 +#968 @ 112,776: 23x15 +#969 @ 465,174: 12x26 +#970 @ 38,231: 17x14 +#971 @ 783,705: 26x28 +#972 @ 456,419: 28x27 +#973 @ 388,143: 22x29 +#974 @ 19,422: 21x23 +#975 @ 260,195: 25x22 +#976 @ 165,782: 17x14 +#977 @ 855,640: 14x20 +#978 @ 912,575: 24x17 +#979 @ 396,832: 20x16 +#980 @ 286,834: 26x21 +#981 @ 801,420: 11x14 +#982 @ 857,902: 25x26 +#983 @ 317,94: 17x12 +#984 @ 944,863: 17x29 +#985 @ 605,638: 25x11 +#986 @ 456,136: 15x23 +#987 @ 533,807: 10x15 +#988 @ 517,400: 19x14 +#989 @ 792,709: 27x29 +#990 @ 471,106: 6x18 +#991 @ 413,277: 22x13 +#992 @ 482,705: 23x27 +#993 @ 830,491: 16x25 +#994 @ 396,179: 19x22 +#995 @ 671,607: 22x19 +#996 @ 288,145: 20x14 +#997 @ 534,400: 16x24 +#998 @ 239,333: 20x12 +#999 @ 801,307: 12x24 +#1000 @ 714,606: 12x18 +#1001 @ 627,784: 22x11 +#1002 @ 734,20: 27x14 +#1003 @ 262,645: 23x14 +#1004 @ 445,670: 13x12 +#1005 @ 304,443: 21x24 +#1006 @ 199,5: 10x23 +#1007 @ 907,64: 25x13 +#1008 @ 553,953: 10x16 +#1009 @ 972,744: 26x20 +#1010 @ 766,180: 16x20 +#1011 @ 558,413: 29x11 +#1012 @ 299,456: 22x10 +#1013 @ 263,138: 29x13 +#1014 @ 746,17: 10x21 +#1015 @ 224,697: 27x19 +#1016 @ 182,609: 25x12 +#1017 @ 508,324: 20x10 +#1018 @ 758,200: 13x24 +#1019 @ 222,788: 24x13 +#1020 @ 254,197: 25x19 +#1021 @ 169,168: 22x20 +#1022 @ 618,120: 15x24 +#1023 @ 932,388: 4x7 +#1024 @ 220,142: 29x14 +#1025 @ 784,9: 16x15 +#1026 @ 658,715: 16x28 +#1027 @ 807,128: 29x28 +#1028 @ 128,240: 12x25 +#1029 @ 685,895: 19x27 +#1030 @ 582,930: 21x27 +#1031 @ 482,325: 25x22 +#1032 @ 659,442: 10x18 +#1033 @ 752,690: 20x16 +#1034 @ 168,762: 11x23 +#1035 @ 30,202: 26x20 +#1036 @ 290,442: 26x12 +#1037 @ 439,941: 27x23 +#1038 @ 563,121: 14x28 +#1039 @ 153,308: 22x11 +#1040 @ 743,157: 10x13 +#1041 @ 173,939: 12x16 +#1042 @ 334,562: 22x13 +#1043 @ 142,581: 25x20 +#1044 @ 195,609: 17x16 +#1045 @ 410,895: 19x20 +#1046 @ 233,495: 23x29 +#1047 @ 351,242: 24x13 +#1048 @ 595,641: 11x10 +#1049 @ 434,465: 19x11 +#1050 @ 418,672: 19x10 +#1051 @ 872,314: 22x25 +#1052 @ 631,721: 12x22 +#1053 @ 738,839: 28x28 +#1054 @ 49,226: 13x17 +#1055 @ 271,199: 16x13 +#1056 @ 200,828: 17x23 +#1057 @ 546,342: 10x16 +#1058 @ 6,166: 19x28 +#1059 @ 175,581: 22x23 +#1060 @ 36,665: 13x14 +#1061 @ 685,42: 14x22 +#1062 @ 282,626: 20x17 +#1063 @ 137,758: 23x26 +#1064 @ 105,205: 15x22 +#1065 @ 817,925: 21x14 +#1066 @ 608,901: 18x25 +#1067 @ 153,685: 13x13 +#1068 @ 745,162: 24x29 +#1069 @ 942,601: 16x22 +#1070 @ 690,776: 21x17 +#1071 @ 457,26: 12x14 +#1072 @ 224,27: 18x14 +#1073 @ 589,622: 29x13 +#1074 @ 479,270: 16x21 +#1075 @ 257,737: 11x28 +#1076 @ 122,195: 21x19 +#1077 @ 68,178: 17x10 +#1078 @ 28,727: 16x11 +#1079 @ 726,482: 20x16 +#1080 @ 39,923: 28x23 +#1081 @ 352,372: 29x15 +#1082 @ 786,670: 23x10 +#1083 @ 153,160: 24x11 +#1084 @ 235,325: 16x18 +#1085 @ 484,0: 10x25 +#1086 @ 22,36: 18x17 +#1087 @ 785,243: 6x17 +#1088 @ 505,198: 10x17 +#1089 @ 485,287: 16x10 +#1090 @ 466,342: 23x18 +#1091 @ 157,292: 19x22 +#1092 @ 641,606: 22x29 +#1093 @ 605,171: 25x19 +#1094 @ 562,903: 29x13 +#1095 @ 653,3: 19x18 +#1096 @ 601,848: 21x19 +#1097 @ 119,454: 18x24 +#1098 @ 819,876: 14x10 +#1099 @ 939,737: 25x23 +#1100 @ 662,614: 27x12 +#1101 @ 708,183: 11x14 +#1102 @ 353,47: 27x11 +#1103 @ 6,670: 12x27 +#1104 @ 438,504: 24x24 +#1105 @ 854,210: 20x23 +#1106 @ 661,859: 24x13 +#1107 @ 813,936: 27x12 +#1108 @ 285,470: 26x18 +#1109 @ 872,122: 11x15 +#1110 @ 799,825: 21x11 +#1111 @ 453,59: 19x24 +#1112 @ 571,600: 27x25 +#1113 @ 870,224: 16x22 +#1114 @ 11,16: 14x23 +#1115 @ 959,347: 22x25 +#1116 @ 137,931: 24x19 +#1117 @ 435,79: 22x28 +#1118 @ 37,318: 14x18 +#1119 @ 332,280: 22x11 +#1120 @ 434,950: 18x18 +#1121 @ 380,426: 25x23 +#1122 @ 362,749: 15x13 +#1123 @ 216,589: 21x11 +#1124 @ 228,740: 26x26 +#1125 @ 799,949: 26x14 +#1126 @ 691,948: 14x16 +#1127 @ 742,230: 25x20 +#1128 @ 174,881: 21x12 +#1129 @ 904,625: 13x12 +#1130 @ 52,413: 19x13 +#1131 @ 224,443: 12x15 +#1132 @ 680,361: 29x10 +#1133 @ 625,430: 27x23 +#1134 @ 378,494: 11x18 +#1135 @ 472,922: 23x11 +#1136 @ 694,958: 20x14 +#1137 @ 561,571: 17x16 +#1138 @ 356,863: 21x7 +#1139 @ 626,779: 13x27 +#1140 @ 469,284: 17x23 +#1141 @ 4,673: 22x18 +#1142 @ 342,176: 28x11 +#1143 @ 17,450: 16x11 +#1144 @ 784,389: 14x22 +#1145 @ 97,436: 10x19 +#1146 @ 934,692: 27x11 +#1147 @ 555,625: 29x18 +#1148 @ 253,456: 19x17 +#1149 @ 75,145: 24x17 +#1150 @ 544,857: 14x14 +#1151 @ 664,825: 27x18 +#1152 @ 20,578: 24x11 +#1153 @ 376,222: 14x18 +#1154 @ 214,762: 14x12 +#1155 @ 753,247: 12x22 +#1156 @ 728,675: 19x27 +#1157 @ 768,649: 28x23 +#1158 @ 647,363: 23x22 +#1159 @ 893,223: 14x24 +#1160 @ 727,519: 12x25 +#1161 @ 718,616: 11x16 +#1162 @ 415,970: 15x24 +#1163 @ 89,898: 11x14 +#1164 @ 868,883: 27x13 +#1165 @ 67,270: 29x22 +#1166 @ 263,480: 27x26 +#1167 @ 466,949: 17x26 +#1168 @ 653,562: 15x28 +#1169 @ 58,371: 26x22 +#1170 @ 761,22: 29x11 +#1171 @ 139,546: 27x18 +#1172 @ 58,600: 13x23 +#1173 @ 716,595: 12x27 +#1174 @ 196,845: 12x14 +#1175 @ 576,447: 24x10 +#1176 @ 319,314: 20x21 +#1177 @ 10,705: 11x15 +#1178 @ 430,933: 27x11 +#1179 @ 795,447: 18x26 +#1180 @ 924,782: 27x24 +#1181 @ 695,609: 18x13 +#1182 @ 600,180: 28x28 +#1183 @ 929,475: 25x23 +#1184 @ 363,776: 13x26 +#1185 @ 888,206: 17x14 +#1186 @ 876,136: 23x14 +#1187 @ 332,16: 20x10 +#1188 @ 554,966: 14x20 +#1189 @ 418,342: 20x19 +#1190 @ 175,826: 16x14 +#1191 @ 528,385: 15x29 +#1192 @ 925,117: 20x29 +#1193 @ 716,849: 23x13 +#1194 @ 164,394: 20x12 +#1195 @ 513,81: 24x13 +#1196 @ 841,475: 19x11 +#1197 @ 468,104: 14x24 +#1198 @ 806,495: 13x29 +#1199 @ 682,669: 29x16 +#1200 @ 429,776: 22x14 +#1201 @ 767,685: 29x25 +#1202 @ 398,881: 19x15 +#1203 @ 723,469: 22x18 +#1204 @ 158,738: 27x25 +#1205 @ 816,896: 11x18 +#1206 @ 780,498: 21x16 +#1207 @ 927,341: 15x16 +#1208 @ 826,55: 27x18 +#1209 @ 148,762: 24x11 +#1210 @ 556,546: 15x10 +#1211 @ 836,805: 26x15 +#1212 @ 548,794: 23x21 +#1213 @ 775,340: 11x18 +#1214 @ 54,390: 12x20 +#1215 @ 563,64: 24x14 +#1216 @ 569,693: 12x22 +#1217 @ 325,866: 25x22 +#1218 @ 753,611: 16x25 +#1219 @ 654,480: 13x29 +#1220 @ 83,255: 16x18 +#1221 @ 425,242: 23x20 +#1222 @ 350,590: 17x19 +#1223 @ 29,798: 10x27 +#1224 @ 147,92: 15x20 +#1225 @ 10,676: 15x21 +#1226 @ 93,103: 28x20 +#1227 @ 361,98: 20x16 +#1228 @ 552,300: 19x19 +#1229 @ 362,594: 20x29 +#1230 @ 509,889: 11x25 +#1231 @ 587,473: 19x17 +#1232 @ 710,387: 12x25 +#1233 @ 803,831: 20x26 +#1234 @ 102,938: 21x17 +#1235 @ 32,505: 27x10 +#1236 @ 798,885: 25x26 +#1237 @ 786,1: 18x28 +#1238 @ 830,673: 29x27 +#1239 @ 569,427: 4x10 +#1240 @ 236,226: 17x26 +#1241 @ 438,642: 11x24 +#1242 @ 713,305: 23x24 +#1243 @ 51,795: 18x13 +#1244 @ 549,847: 27x24 +#1245 @ 642,460: 18x13 +#1246 @ 399,222: 13x16 +#1247 @ 161,480: 19x10 +#1248 @ 888,226: 27x23 +#1249 @ 274,237: 26x28 +#1250 @ 16,323: 20x25 +#1251 @ 412,329: 24x19 +#1252 @ 377,188: 23x14 +#1253 @ 288,439: 19x22 +#1254 @ 759,110: 11x27 +#1255 @ 400,420: 21x13 +#1256 @ 446,663: 25x15 +#1257 @ 782,141: 11x19 +#1258 @ 374,442: 21x28 +#1259 @ 587,402: 13x11 +#1260 @ 78,152: 29x25 +#1261 @ 816,182: 6x4 +#1262 @ 382,939: 24x29 +#1263 @ 256,592: 12x27 +#1264 @ 83,909: 24x21 +#1265 @ 447,581: 13x17 +#1266 @ 679,654: 24x11 +#1267 @ 631,223: 15x26 +#1268 @ 180,366: 12x19 +#1269 @ 823,742: 12x15 +#1270 @ 221,290: 24x16 +#1271 @ 207,653: 23x23 +#1272 @ 774,513: 11x17 +#1273 @ 258,738: 19x10 +#1274 @ 161,356: 22x21 +#1275 @ 808,829: 27x15 +#1276 @ 28,653: 19x19 +#1277 @ 853,747: 21x13 +#1278 @ 600,627: 18x28 +#1279 @ 592,912: 16x10 +#1280 @ 133,722: 10x11 +#1281 @ 106,939: 13x17 +#1282 @ 68,251: 25x17 +#1283 @ 315,769: 26x18 +#1284 @ 250,365: 25x10 +#1285 @ 37,579: 26x24 +#1286 @ 122,411: 17x12 +#1287 @ 225,373: 12x15 +#1288 @ 444,587: 22x26 +#1289 @ 163,489: 27x11 +#1290 @ 460,8: 14x25 +#1291 @ 935,853: 22x17 +#1292 @ 255,953: 11x17 +#1293 @ 826,327: 10x20 +#1294 @ 953,245: 10x13 +#1295 @ 698,208: 17x21 +#1296 @ 748,189: 29x12 +#1297 @ 441,309: 26x13 +#1298 @ 666,500: 27x27 +#1299 @ 39,296: 16x14 +#1300 @ 463,261: 10x15 +#1301 @ 106,745: 20x28 +#1302 @ 153,946: 18x10 +#1303 @ 185,833: 12x26 +#1304 @ 15,135: 18x11 +#1305 @ 83,436: 17x24 +#1306 @ 296,333: 20x12 +#1307 @ 874,615: 17x22 +#1308 @ 118,543: 25x14 +#1309 @ 607,531: 14x25 +#1310 @ 694,399: 14x20 +#1311 @ 61,247: 18x7 +#1312 @ 363,947: 29x18 +#1313 @ 837,451: 13x17 +#1314 @ 293,470: 26x25 +#1315 @ 27,436: 16x15 +#1316 @ 724,398: 11x22 +#1317 @ 192,867: 16x11 +#1318 @ 958,58: 20x22 +#1319 @ 621,512: 14x12 +#1320 @ 39,498: 16x13 +#1321 @ 859,793: 11x16 +#1322 @ 863,529: 29x29 +#1323 @ 180,869: 23x14 +#1324 @ 593,134: 21x27 +#1325 @ 833,448: 17x22 +#1326 @ 83,812: 23x26 +#1327 @ 938,630: 25x20 +#1328 @ 877,513: 13x25 +#1329 @ 301,317: 29x12 +#1330 @ 931,951: 24x27 +#1331 @ 519,689: 24x18 +#1332 @ 165,449: 21x20 +#1333 @ 855,362: 27x10 +#1334 @ 647,348: 10x27 +#1335 @ 31,139: 17x24 +#1336 @ 219,960: 26x15 +#1337 @ 358,597: 15x22 +#1338 @ 277,504: 21x27 +#1339 @ 610,782: 28x10 +#1340 @ 548,940: 18x10 +#1341 @ 3,669: 18x17 +#1342 @ 832,502: 22x24 +#1343 @ 374,368: 25x18 +#1344 @ 381,97: 14x24 +#1345 @ 641,183: 29x24 +#1346 @ 974,913: 25x15 +#1347 @ 756,136: 26x24 +#1348 @ 390,965: 27x15 +#1349 @ 747,716: 17x16 +#1350 @ 363,222: 13x25 +#1351 @ 596,74: 17x19 +#1352 @ 178,384: 27x27 +#1353 @ 956,241: 26x20 +#1354 @ 846,48: 16x15 +#1355 @ 746,88: 29x14 +#1356 @ 402,878: 21x11 +#1357 @ 319,9: 28x23 +#1358 @ 467,748: 21x17 +#1359 @ 532,942: 12x14 +#1360 @ 581,613: 19x14 +#1361 @ 341,658: 22x29 +#1362 @ 483,657: 10x13 +#1363 @ 183,18: 18x13 +#1364 @ 208,425: 12x27 +#1365 @ 242,587: 25x18 +#1366 @ 853,843: 15x17 +#1367 @ 423,675: 6x3 +#1368 @ 889,642: 16x23 +#1369 @ 327,101: 13x19 +#1370 @ 983,436: 14x20 +#1371 @ 515,738: 16x18 +#1372 @ 825,940: 24x24 +#1373 @ 340,637: 20x19 +#1374 @ 432,604: 21x24 +#1375 @ 952,953: 21x25 +#1376 @ 92,714: 23x20 +#1377 @ 330,713: 16x11 +#1378 @ 62,49: 13x23 +#1379 @ 426,770: 23x26 +#1380 @ 920,908: 14x18 +#1381 @ 229,393: 18x11 +#1382 @ 762,237: 24x29 +#1383 @ 186,911: 22x25 +#1384 @ 942,297: 26x18 +#1385 @ 499,622: 18x15 +#1386 @ 787,183: 13x25 +#1387 @ 691,669: 21x16 +#1388 @ 409,150: 28x23 +#1389 @ 750,475: 15x25 +#1390 @ 859,426: 19x22 +#1391 @ 119,742: 22x13 +#1392 @ 233,31: 16x15 +#1393 @ 282,168: 22x21 +#1394 @ 303,431: 17x20 +#1395 @ 640,734: 14x19 +#1396 @ 686,598: 10x28 +#1397 @ 587,737: 19x17 +#1398 @ 952,261: 13x10 +#1399 @ 954,32: 23x19 +#1400 @ 632,767: 10x21 +#1401 @ 1,783: 21x20 +#1402 @ 68,407: 19x14 +#1403 @ 765,597: 26x15 +#1404 @ 741,266: 19x17 +#1405 @ 391,428: 11x10 +#1406 @ 607,907: 13x16 +#1407 @ 195,160: 22x22 +#1408 @ 469,952: 9x13 +#1409 @ 280,194: 13x20 +#1410 @ 870,757: 18x13 +#1411 @ 120,917: 19x14 diff --git a/2018/aoc03/ideas.md b/2018/aoc03/ideas.md @@ -0,0 +1,2 @@ +- try and use an iterator/map function +- take in input from stdin instead of file diff --git a/2018/aoc03/src/main.rs b/2018/aoc03/src/main.rs @@ -0,0 +1,82 @@ +use std::collections::HashSet; +use std::io::{self, Read}; + +type FabricPiece = (i16, i16); + +struct FabricClaim { + id: i16, + x_start: i16, + y_start: i16, + x_end: i16, + y_end: i16, +} + +fn main() { + let mut claimed_fabric: HashSet<FabricPiece> = HashSet::new(); + let mut overlapping_fabric: HashSet<FabricPiece> = HashSet::new(); + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + for line in input.lines() { + let claim = parse_line(line); + // still learning string manipulations + let claim_set: HashSet<FabricPiece> = claim.get_set(); + for item in &claim_set { + if claimed_fabric.contains(&item) { + overlapping_fabric.insert(*item); + } else { + claimed_fabric.insert(*item); + } + } + let mut intersects = false; + println!("processed {}", claim.id); + for subline in input.lines() { + let subclaim = parse_line(subline); + if subclaim.id != claim.id + && claim_set + .intersection(&subclaim.get_set()) + .collect::<Vec<&(i16, i16)>>() + .len() + > 0 + { + intersects = true; + break; + } + } + if !intersects { + println!("No intersection: {}", claim.id); + } + } + println!("{}", overlapping_fabric.len()) +} + +fn parse_line(line: &str) -> FabricClaim { + let data = line.split("#").nth(1).unwrap(); + let id: i16 = data.split(" ").next().unwrap().parse().unwrap(); + let data = line.split("@ ").nth(1).unwrap(); + let x_start: i16 = data.split(",").next().unwrap().parse().unwrap(); + let data = data.split(",").nth(1).unwrap(); + let y_start: i16 = data.split(":").next().unwrap().parse().unwrap(); + let data = data.split(" ").nth(1).unwrap(); + let x_end: i16 = x_start + data.split("x").next().unwrap().parse::<i16>().unwrap() - 1; + let y_end: i16 = y_start + data.split("x").nth(1).unwrap().parse::<i16>().unwrap() - 1; + FabricClaim { + id, + x_start, + y_start, + x_end, + y_end, + } +} + +impl FabricClaim { + fn get_set(&self) -> HashSet<FabricPiece> { + let mut output = HashSet::new(); + for x in self.x_start..self.x_end + 1 { + for y in self.y_start..self.y_end + 1 { + let inch = (x, y); + output.insert(inch); + } + } + output + } +} diff --git a/2018/aoc04/Cargo.lock b/2018/aoc04/Cargo.lock @@ -0,0 +1,146 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.6.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "aoc04" +version = "0.1.0" +dependencies = [ + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "chrono" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lazy_static" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "libc" +version = "0.2.48" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "memchr" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num-integer" +version = "0.1.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "num-traits" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_syscall" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "regex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "regex-syntax" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "thread_local" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "time" +version = "0.1.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "ucd-util" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "utf8-ranges" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" +"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" +"checksum libc 0.2.48 (registry+https://github.com/rust-lang/crates.io-index)" = "e962c7641008ac010fa60a7dfdc1712449f29c44ef2d4702394aea943ee75047" +"checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" +"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" +"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" +"checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f" +"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" +"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" +"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" +"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" +"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" +"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/2018/aoc04/Cargo.toml b/2018/aoc04/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "aoc04" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +[dependencies] +regex = "1" +chrono = "0.4" + diff --git a/2018/aoc04/src/main.rs b/2018/aoc04/src/main.rs @@ -0,0 +1,105 @@ +extern crate chrono; +extern crate regex; + +use chrono::prelude::*; +use regex::Regex; +use std::collections::HashMap; +use std::io::{self, Read}; + +#[derive(Debug)] +enum Event { + WakesUp, + FallsAsleep, + StartShift(i16), + Other, +} + +#[derive(Debug)] +struct Entry { + timestamp: NaiveDateTime, + event: Event, +} + +fn main() { + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + let mut log: Vec<Entry> = Vec::new(); + for line in input.lines() { + let entry = parse_entry(line); + log.push(entry); + } + log.sort_by_key(|k| k.timestamp); + let mut guard_sleeptime = HashMap::new(); + let mut current_guard: i16 = 0; + let mut asleep_minute: u32 = 0; + for entry in &log { + match entry.event { + Event::StartShift(t) => { + current_guard = t; + } + Event::FallsAsleep => { + asleep_minute = entry.timestamp.minute(); + } + Event::WakesUp => { + guard_sleeptime + .entry(current_guard) + .or_insert(Vec::new()) + .extend(asleep_minute..entry.timestamp.minute()); + } + Event::Other => (), + } + } + let mut sleepiest_guard = 0; + let mut max_minute_count = 0; + let mut sleepiest_minute = 0; + for (k, v) in &guard_sleeptime { + // could use some map stuff + let (minute, count) = mode(v); + if count > max_minute_count { + max_minute_count = count; + sleepiest_minute = minute; + sleepiest_guard = *k; + } + } + println!( + "Sleepiest guard: {}, sleepiest minute: {}, combo: {}", + sleepiest_guard, + sleepiest_minute, + sleepiest_guard as u32 * sleepiest_minute + ) + + // println!( + // "sleepy guard: {}, sleepiest minute: {}", + // sleepiest_guard, mode + // ); + // println!("result: {}", sleepiest_guard as u32 * mode) +} +fn mode(numbers: &[u32]) -> (u32, u32) { + let mut occurrences = HashMap::new(); + + for &value in numbers { + *occurrences.entry(value).or_insert(0) += 1; + } + + occurrences + .into_iter() + .max_by_key(|&(_, count)| count) + .expect("Cannot compute the mode of zero numbers") +} + +fn parse_entry(input: &str) -> Entry { + let re = Regex::new(r"\[(.*)\] (?:Guard #?(\d*?) )?(.*)?$").unwrap(); + let capture = re.captures(input).unwrap(); + let timestamp = capture.get(1).unwrap().as_str(); + let action = capture.get(3).unwrap().as_str(); + let event = match action { + "begins shift" => { + Event::StartShift(capture.get(2).unwrap().as_str().parse::<i16>().unwrap()) + } + "wakes up" => Event::WakesUp, + "falls asleep" => Event::FallsAsleep, + _ => Event::Other, // something wrong here... + }; + let timestamp = NaiveDateTime::parse_from_str(timestamp, "%Y-%m-%d %H:%M").unwrap(); + Entry { timestamp, event } +} diff --git a/2018/aoc05/Cargo.toml b/2018/aoc05/Cargo.toml @@ -0,0 +1,7 @@ +[package] +name = "aoc05" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +[dependencies] diff --git a/2018/aoc05/src/main.rs b/2018/aoc05/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/2018/readme.md b/2018/readme.md @@ -0,0 +1 @@ +wooohooo diff --git a/2018/solutions.md b/2018/solutions.md @@ -0,0 +1,3 @@ +https://www.forrestthewoods.com/blog/learning-rust-via-advent-of-code/adventofcode2018_forrestsmith_rust + + diff --git a/2019/README.md b/2019/README.md @@ -0,0 +1,7 @@ +# Advent of Code 2019 (Rust) + +![img](https://i.giphy.com/media/ddt9UYKI8BZtmKSS9S/giphy.webp) + +Each solution should take input from stdin from the input/input.txt file + +Run `./run_all` to compile and build all solutions (Note -- this doesn't work at the moment. Going to clean up everything later) diff --git a/2019/aoc01/Cargo.lock b/2019/aoc01/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc01" +version = "0.1.0" + diff --git a/2019/aoc01/Cargo.toml b/2019/aoc01/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc01" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc01/src/main.rs b/2019/aoc01/src/main.rs @@ -0,0 +1,34 @@ +/// Solution to Day 1: https://adventofcode.com/2019/day/1 + +use std::io::{self}; +use std::io::prelude::*; + +fn main() { + // Determine the total fuel requirements for a list of modules based on their mass + // Given the "base" (Part 1) fuel calculation and "sophisticated" (Part 2) calculation + // Input is a list of module masses (positive integers) separated by line breaks + // Overflows if total mass >= 2^32 + let mut partone: u32 = 0; + let mut parttwo: u32 = 0; + for line in io::stdin().lock().lines() { + let parsed = line.unwrap().parse::<u32>().unwrap(); + partone += base_calculate_fuel(parsed); + parttwo += sophisticated_calculate_fuel(parsed); + } + println!("part 1: {}", partone); + println!("part 2: {}", parttwo); +} + +fn base_calculate_fuel(mass: u32) -> u32 { + return (mass / 3) - 2 +} + +fn sophisticated_calculate_fuel(mass: u32) -> u32 { + let mut total = 0; + let mut current = base_calculate_fuel(mass); + while current > 0 { + total += current; + current = base_calculate_fuel(current); + } + return total +} diff --git a/2019/aoc02/Cargo.lock b/2019/aoc02/Cargo.lock @@ -0,0 +1,13 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc02" +version = "0.1.0" +dependencies = [ + "intcode 0.1.0", +] + +[[package]] +name = "intcode" +version = "0.1.0" + diff --git a/2019/aoc02/Cargo.toml b/2019/aoc02/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "aoc02" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +intcode = {path ="../intcode"} diff --git a/2019/aoc02/src/main.rs b/2019/aoc02/src/main.rs @@ -0,0 +1,7 @@ +use intcode; +use std::io::{self, Read}; + +fn main() { + let mut program_string = String::new(); + io::stdin().read_to_string(&mut program_string).unwrap(); +} diff --git a/2019/aoc03/Cargo.lock b/2019/aoc03/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc03" +version = "0.1.0" + diff --git a/2019/aoc03/Cargo.toml b/2019/aoc03/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc03" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc03/src/main.rs b/2019/aoc03/src/main.rs @@ -0,0 +1,74 @@ +use std::io::{self, Read}; +use std::collections::HashSet; + +fn main() { + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + let lines: Vec<&str> = input.lines().collect(); + let wire1_path: Vec<&str> = lines[0].split(",").collect(); + let wire2_path: Vec<&str> = lines[1].split(",").collect(); + let points1 = get_points(wire1_path.clone()); + let points2 = get_points(wire2_path.clone()); + let intersections = points1.intersection(&points2); + // part 1 + + let nearest_intersection = intersections.clone() + .map(|t| t.0.abs() + t.1.abs()) + .min() + .unwrap(); + println!("part 1: {}", nearest_intersection); + // part 2 + let nearest_intersection = intersections.clone() + .map(|t| get_length_to_point(wire1_path.clone(), *t) + get_length_to_point(wire2_path.clone(), *t)) // horrible + .min() + .unwrap(); + println!("part 2: {}", nearest_intersection); + // println!("part 2: {}", intersection); +} + +fn get_length_to_point(path: Vec<&str>, point: (i32, i32)) -> i32 { + // inefficient + let mut current_x = 0; + let mut current_y = 0; + let mut wire_len = 0; + for item in path { + let direction = &item[0..1]; + let amount: i32 = item[1..].parse().unwrap(); + for _ in 0..amount { + match direction { + "U" => current_y += 1, + "D" => current_y -= 1, + "L" => current_x -= 1, + "R" => current_x += 1, + _ => () + } + wire_len += 1; + if current_x == point.0 && current_y == point.1 { + return wire_len; + } + } + } + return -1; // bad + +} + +fn get_points(path: Vec<&str>) -> HashSet<(i32, i32)>{ + let mut path_points = HashSet::new(); + let mut current_x = 0; + let mut current_y = 0; + for item in path { + let direction = &item[0..1]; + let amount: i32 = item[1..].parse().unwrap(); + for _ in 0..amount { + match direction { + "U" => current_y += 1, + "D" => current_y -= 1, + "L" => current_x -= 1, + "R" => current_x += 1, + _ => () + } + path_points.insert((current_x, current_y)); + } + } + return path_points; +} diff --git a/2019/aoc04/Cargo.lock b/2019/aoc04/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc04" +version = "0.1.0" + diff --git a/2019/aoc04/Cargo.toml b/2019/aoc04/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc04" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc04/src/main.rs b/2019/aoc04/src/main.rs @@ -0,0 +1,52 @@ +use std::collections::HashSet; +use std::iter::FromIterator; + + +const RANGE: (i32, i32) = (134564, 585159); + +fn main() { + // part 1 + let result: Vec<Vec<i32>> = (RANGE.0..=RANGE.1) + .map(|n| number_to_vec(n)) + .filter(|v| v.windows(2).all(|w| w[0] <= w[1])) // check is sorted + .filter(|v| HashSet::<&i32>::from_iter(v.iter()).len() != v.len()) + .collect(); + println!("part 1: {}", result.len()); + // Much better solution: + // https://www.reddit.com/r/adventofcode/comments/e5u5fv/2019_day_4_solutions/f9mkj4v?utm_source=share&utm_medium=web2x + let part2 = result + .iter() + .filter(|v| { + let mut last_char = -1; + let mut seq = 1; + for (i,d) in v.iter().enumerate() { + if last_char == *d { + seq += 1; + if i == v.len()-1 && seq == 2{ + return true; + } + } + else { + if seq == 2 { + return true; + } + seq = 1 + } + last_char = *d; + } + return false}).count(); + println!("part 2: {}", part2); +} + +// copied from https://users.rust-lang.org/t/how-to-convert-a-number-to-numeric-vec/10404 +fn number_to_vec(n: i32) -> Vec<i32> { + let mut digits = Vec::new(); + let mut n = n; + while n > 9 { + digits.push(n % 10); + n = n / 10; + } + digits.push(n); + digits.reverse(); + digits +} diff --git a/2019/aoc05/Cargo.lock b/2019/aoc05/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc02" +version = "0.1.0" + diff --git a/2019/aoc05/Cargo.toml b/2019/aoc05/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc02" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc05/src/main.rs b/2019/aoc05/src/main.rs @@ -0,0 +1,108 @@ +use std::io::{self, Read}; + +fn main() { + let mut program_string = String::new(); + io::stdin().read_to_string(&mut program_string).unwrap(); + program_string.pop(); // Remove ending newline (?) + let program: Vec<i32>= program_string + .split(",") + .map(|i| { + i.parse::<i32>().unwrap()}) + .collect(); + // Part 1 + let input = 5; + run_program(program.clone(), input); + // part 2 +} + + +fn run_program(mut program: Vec<i32>, input: i32) { + let mut instruction_pointer = 0; + loop { + let current_instruction = program[instruction_pointer]; + let opcode = current_instruction % 100; + let get_values = |parameters| { + let mut out = Vec::new(); + for i in 1..=parameters { + let mut value = program[(instruction_pointer+i) as usize]; + let mode = (current_instruction / (i32::pow(10, i as u32)*10)) % 10; + if mode == 0 { // position mode + // value used as pointer + value = program[value as usize]; + } + out.push(value); + } + out + }; + if opcode == 1 { + let ptr = program[instruction_pointer + 3]; + let params = get_values(2); + program[ptr as usize] = params[0] + params[1]; + instruction_pointer += 4 + } + else if opcode == 2 { + let ptr = program[instruction_pointer + 3]; + let params = get_values(2); + program[ptr as usize] = params[0] * params[1]; + instruction_pointer += 4 + } + else if opcode == 3 { + let ptr = program[instruction_pointer + 1]; + program[ptr as usize] = input; + instruction_pointer += 2 + // input + } + else if opcode == 4 { + let params = get_values(1); + println!("Result {}", params[0]); + instruction_pointer += 2 + // output + } + else if opcode == 5 { + // jump if true + let params = get_values(2); + if params[0] != 0 { + instruction_pointer = params[1] as usize; + } + else { + instruction_pointer += 3 + } + } + else if opcode == 6 { + // jump if false + let params = get_values(2); + if params[0] == 0 { + instruction_pointer = params[1] as usize; + } + else { + instruction_pointer += 3 + } + } + else if opcode == 7 { + // less than + let ptr = program[instruction_pointer + 3]; + let params = get_values(2); + if params[0] < params[1] { // hm + program[ptr as usize] = 1; + } + else { + program[ptr as usize] = 0; + } + instruction_pointer += 4 + } + else if opcode == 8 { + let ptr = program[instruction_pointer + 3]; + let params = get_values(2); + if params[0] == params[1] { + program[ptr as usize] = 1; + } + else { + program[ptr as usize] = 0; + } + instruction_pointer += 4 + } + else if opcode == 99 { + return + } + } +} diff --git a/2019/aoc06/Cargo.lock b/2019/aoc06/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc06" +version = "0.1.0" + diff --git a/2019/aoc06/Cargo.toml b/2019/aoc06/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc06" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc06/src/main.rs b/2019/aoc06/src/main.rs @@ -0,0 +1,36 @@ +use std::io::{self, Read}; +use std::collections::{HashMap, HashSet}; +use std::iter::{successors, FromIterator}; + + +fn main() { + // read input to hashmap + let mut input_data = String::new(); + io::stdin().read_to_string(&mut input_data).unwrap(); + let orbits: HashMap<&str, &str> = input_data + .lines() + .map(|line| { + let a: Vec<&str> = line.split(")").collect(); + (a[1], a[0])}).collect(); + + // part 1 + let orbit_count = orbits + .iter() + .map(|(_,b)| successors(Some(b), |suborbit| orbits.get(*suborbit))) + .flatten() // same as flatmap + .count(); + + println!("part 1: {}", orbit_count); + + let suborbits = |orbit| successors(Some(orbit), |suborbit| orbits.get(*suborbit)); + let you: Vec<&&str> = suborbits(&"YOU").collect(); + let santa: Vec<&&str> = suborbits(&"santa").collect(); + let shared_descendents: HashSet<&&&&str> = HashSet::<Vec<&&&str>>::from_iter(you.iter()).intersection(&HashSet::from_iter(santa.iter())); + for (i, item) in suborbits(&"YOU").enumerate() { + if shared_descendents.contains(&&item) { + let result = i + suborbits(&"SANTA").position(|r| r == item).unwrap(); + println!("part 2: {}", result); + } + } + +} diff --git a/2019/aoc07/Cargo.lock b/2019/aoc07/Cargo.lock @@ -0,0 +1,30 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc07" +version = "0.1.0" +dependencies = [ + "intcode 0.1.0", + "itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "either" +version = "1.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "intcode" +version = "0.1.0" + +[[package]] +name = "itertools" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum either 1.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "bb1f6b1ce1c140482ea30ddd3335fc0024ac7ee112895426e0a629a6c20adfe3" +"checksum itertools 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f56a2d0bc861f9165be4eb3442afd3c236d8a98afd426f65d92324ae1091a484" diff --git a/2019/aoc07/Cargo.toml b/2019/aoc07/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "aoc07" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools="0.8" +intcode = {path = "../intcode"} diff --git a/2019/aoc07/src/main.rs b/2019/aoc07/src/main.rs @@ -0,0 +1,59 @@ +#[macro_use] extern crate itertools; + +use intcode; +use itertools::Itertools; +use std::io::{self, Read}; + +fn main() { + let mut program_string = String::new(); + io::stdin().read_to_string(&mut program_string).unwrap(); + + // Part 1 + //let result = (0..=4) + // .permutations(5) + // .inspect(|x| println!("Running permutation {:?}", x)) + // .map(|x| x.iter().fold(0, |amplitude, ps| { + // let mut program = intcode::Program::from_string(program_string.clone()); + // program.input = vec![amplitude, *ps]; + // program.run_until_output().unwrap() + // })) + // .max(); + //println!("part 1: {:?}", result); + //run_program(program.clone(), input); + let mut max = 0; + let mut best = vec![]; + for permutation in (5..=9).permutations(5) { + let mut programs: Vec<intcode::Program> = vec![]; + for signal in permutation.iter() { + let mut program = intcode::Program::from_string(program_string.clone()); + program.input = vec![*signal]; + program.step(); // read input + programs.push(program); + } + let mut amplitude = 0; + let mut doabreak = false; + loop { + for i in 0..programs.len() { + println!("{:?}", programs[i]); + programs[i].input = vec![amplitude]; + match programs[i].run_until_output() { + Some(a) => amplitude = a, + None => { + doabreak = true; + break + } + } + } + if doabreak { + break + } + } + if amplitude > max { + max = amplitude; + best = permutation.clone(); + } + } + println!("part 2: {:?} {:?}", max, best); + // part 2 +} + diff --git a/2019/aoc08/Cargo.lock b/2019/aoc08/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc08" +version = "0.1.0" + diff --git a/2019/aoc08/Cargo.toml b/2019/aoc08/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc08" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc08/solution.py b/2019/aoc08/solution.py @@ -0,0 +1,23 @@ +import itertools + + +def chunked_iterable(iterable, size): + it = iter(iterable) + while True: + chunk = tuple(itertools.islice(it, size)) + if not chunk: + break + yield chunk + + +with open("input/input.txt") as f: + smallest_layer = 1 + minim = 25 * 6 + tmp = None + a = chunked_iterable(f.read(), minim) + for i in a: + if i.count("0") < minim and i.count("0") != 0: + minim = i.count("0") + tmp = i + print(tmp) + print(tmp.count("1") * tmp.count("2")) diff --git a/2019/aoc08/src/main.rs b/2019/aoc08/src/main.rs @@ -0,0 +1,70 @@ +use std::io::{self, Read}; + +// Refactored based on https://github.com/sethetter/aoc-2019/blob/master/day-08/src/main.rs after +// completing +fn main() { + let height = 6; + let width = 25; + let layer_size = height * width; + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + input.pop(); + let count_digit = |f: &[u32], digit| f.iter().filter(|x| *x == &digit).count(); + + // part 1 + let nums = input + .chars() + .map(|c| c.to_digit(10).unwrap()) + .collect::<Vec<u32>>(); + let fewest_zeros = nums + .chunks(layer_size) + .min_by(|a, b| count_digit(a, 0).cmp(&count_digit(b, 0))) + .unwrap(); + + let result = count_digit(fewest_zeros, 1) * count_digit(fewest_zeros, 2); + + println!("part 1: {}", result); + let layers: Vec<&[u32]> = nums + .chunks(layer_size) + .collect::<Vec<&[u32]>>(); + + let mut image: Vec<Vec<u32>> = vec![]; + for layer in layers { + // initialize + for i in 0..height { + match image.get(i) { + Some(_) => (), + None => image.push(vec![]) + } + for j in 0..width { + let mychar = layer[i * width + j]; + let result = image[i].get(j); + if result == None { + image[i].push(mychar) + } + else { + let newchar = match image[i][j] { + 0 => 0, + 1 => 1, + 2 => mychar, + _ => panic!() + }; + image[i as usize][j] = newchar; + } + } + } + } + + + println!("part 2:"); + for line in image { + for a in line { + match a { + 1 => print!("O"), + 0 => print!("_"), + _ => panic!() + } + } + print!("\n"); + } +} diff --git a/2019/aoc09/Cargo.lock b/2019/aoc09/Cargo.lock @@ -0,0 +1,13 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc09" +version = "0.1.0" +dependencies = [ + "intcode 0.1.0", +] + +[[package]] +name = "intcode" +version = "0.1.0" + diff --git a/2019/aoc09/Cargo.toml b/2019/aoc09/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "aoc09" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +intcode = {path = "../intcode"} diff --git a/2019/aoc09/src/main.rs b/2019/aoc09/src/main.rs @@ -0,0 +1,7 @@ +use intcode; + +fn main() { + let mut program = intcode::Program::from_stdin(); + program.input = vec![2]; + program.run_until_stop(); +} diff --git a/2019/aoc10/Cargo.lock b/2019/aoc10/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc10" +version = "0.1.0" + diff --git a/2019/aoc10/Cargo.toml b/2019/aoc10/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc10" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc10/src/main.rs b/2019/aoc10/src/main.rs @@ -0,0 +1,188 @@ +use std::io::{self, Read}; +use std::collections::HashSet; + +fn main() { + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); + let asteroids: HashSet<(i32,i32)> = input + .lines() + .enumerate() + .map(|(i, line)| line + .chars() + .enumerate() + .filter(|(_, space)| *space == '#') + .map(move |(j, _)| (j as i32 ,i as i32 ))) + .flatten() + .collect(); + + let best = asteroids + .iter() + .map(|a1| { + let count = asteroids.iter().filter( + |a2| { +<<<<<<< Updated upstream + *a2 != a1 && asteroids.iter().filter(|a3|{ + let result = check_if_between(*a1,**a2,**a3); + result + }).count() == 0 // includes self +||||||| merged common ancestors + **a2 != **a1 && asteroids.iter().filter(|a3|{ + check_if_between(**a1,**a2,**a3) + }).count() > 1 // includes self +======= + **a2 != **a1 && asteroids.iter().filter(|a3|{ + let obstruct = check_if_between(**a1,**a2,**a3); + if obstruct { + println!("Found {:?} between {:?} and {:?}", a3, a1, a2); + return true + } + else{ + println!("Found {:?} not between {:?} and {:?}", a3, a1, a2); + return false + }}).count() == 0 // includes self +>>>>>>> Stashed changes + } + ).count(); + count + }).max().unwrap(); + println!("{:?}", best); +} + +<<<<<<< HEAD:rust/aoc10/src/main.rs +<<<<<<< Updated upstream +fn gcd(mut m: i32, mut n: i32) -> i32 { + // modified for 0 +||||||| merged common ancestors:aoc10/src/main.rs +fn gcd(mut m: i32, mut n: i32) -> i32 { + // modified for 0 +======= +fn num_steps(mut m: i32, mut n: i32) -> i32 { + // gcd modified for 0 +>>>>>>> 4276669f522a710ff645c5c0c0fbbb9026004c1c:aoc10/src/main.rs + if n == 0 { + return m.abs() +||||||| merged common ancestors +fn check_if_between(a: (usize, usize), b: (usize, usize), c: (usize, usize)) -> bool { + // checks if c is between a and b + let xdiffab = b.0 as i32 - a.0 as i32 ; + let ydiffab = b.1 as i32 - a.1 as i32; + let xdiffac = c.0 as i32 - a.0 as i32; + let ydiffac = c.1 as i32- a.1 as i32; + // flat special case + if xdiffab == 0 || xdiffac == 0 { + return xdiffab == xdiffac +======= +fn check_if_between(a: (usize, usize), b: (usize, usize), c: (usize, usize)) -> bool { + if c == a || c == b { + return false + } + // checks if c is between a and b + let xdiffab = b.0 as i32 - a.0 as i32 ; + let ydiffab = b.1 as i32 - a.1 as i32; + let xdiffac = c.0 as i32 - a.0 as i32; + let ydiffac = c.1 as i32- a.1 as i32; + // flat special case + if xdiffab == 0 || xdiffac == 0 { + return xdiffab == xdiffac +>>>>>>> Stashed changes + } + else if m == 0 { + return n.abs() + } + while m != 0 { + let old_m = m; + m = n % m; + n = old_m; + } + n.abs() + } + +fn check_if_between(a: (i32, i32), b: (i32, i32), c: (i32, i32)) -> bool { + if c == a || c == b { + return false + } + let badiff = (b.0 -a.0 , b.1 -a.1 ); + let num_steps = num_steps(badiff.0, badiff.1); + let step = (badiff.0 / num_steps, badiff.1 / num_steps); + let mut tracer = (a.0 , a.1 ); + for _ in 0..=num_steps { + tracer = (tracer.0 + step.0, tracer.1 + step.1); + if tracer == (c.0 , c.1 ) { + return true + } + else if tracer == (b.0 , b.1 ) { + return false; + } + } + false +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_line_of_sight() { + let a=(0,0); + let b=(2,2); + let c=(1,1); + assert!(check_if_between(a, b, c)); + } + #[test] + fn test_not_inline_of_sight() { + let a=(0,0); + let b=(2,3); + let c=(1,1); + assert!(!check_if_between(a, b, c)) + } + #[test] + fn test_wonky() { + let a=(0,0); + let b=(4,6); + let c=(2,3); + assert!(check_if_between(a, b, c)) +} + #[test] + fn test_inf_slope() { + let a=(0,0); + let b=(0,2); + let c=(0,1); + assert!(check_if_between(a, b, c)) + } + #[test] + fn test_0_slope() { + let a=(0,0); + let b=(2,0); + let c=(1,0); + assert!(check_if_between(a, b, c)) + } + #[test] + fn test_b_is_c() { + let a=(0,0); + let b=(0,2); + let c=(0,2); + assert!(!check_if_between(a, b, c)); + } + + #[test] + fn test_a_is_c() { + let a=(0,0); + let b=(0,2); + let c=(0,0); + assert!(!check_if_between(a, b, c)) + } + #[test] + fn test_broken_case() { + let a=(3,2); + let b=(1,2); + let c=(4,2); + assert!(!check_if_between(a, b, c)) + } + #[test] + fn test_broken_case2() { + let a=(1,2); + let b=(4,2); + let c=(0,2); + assert!(!check_if_between(a, b, c)) + } +} diff --git a/2019/aoc11/Cargo.lock b/2019/aoc11/Cargo.lock @@ -0,0 +1,13 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc11" +version = "0.1.0" +dependencies = [ + "intcode 0.1.0", +] + +[[package]] +name = "intcode" +version = "0.1.0" + diff --git a/2019/aoc11/Cargo.toml b/2019/aoc11/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "aoc11" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +intcode = {path="../intcode"} diff --git a/2019/aoc11/src/main.rs b/2019/aoc11/src/main.rs @@ -0,0 +1,6 @@ +use intcode; + +fn main() { + let mut program = intcode::Program::from_stdin(); + program.run_until_stop(); +} diff --git a/2019/aoc13/Cargo.lock b/2019/aoc13/Cargo.lock @@ -0,0 +1,13 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc13" +version = "0.1.0" +dependencies = [ + "intcode 0.1.0", +] + +[[package]] +name = "intcode" +version = "0.1.0" + diff --git a/2019/aoc13/Cargo.toml b/2019/aoc13/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "aoc13" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +intcode = {path = "../intcode"} diff --git a/2019/aoc13/src/main.rs b/2019/aoc13/src/main.rs @@ -0,0 +1,14 @@ +use intcode; + +fn main() { + let mut program = intcode::Program::from_stdin(); + let mut program2 = program.clone(); + program.run_until_stop(); + let part1 = program.output + .chunks(3) + .filter(|x| x[2] == 2).count(); + println!("{}", part1); + program2.memory[0] = 2; + program2.input = vec![0]; +} + diff --git a/2019/aoc16/Cargo.lock b/2019/aoc16/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc16" +version = "0.1.0" + diff --git a/2019/aoc16/Cargo.toml b/2019/aoc16/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc16" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc16/src/main.rs b/2019/aoc16/src/main.rs @@ -0,0 +1,41 @@ +use std::iter; +use std::io::{Read, self}; + +fn main() { + let mut input_string = String::new(); + std::io::stdin().lock().read_to_string(&mut input_string).unwrap(); + + let input_vec: Vec<u32> = iter::repeat(input_string + .chars() + .map(|x| x.to_digit(10).unwrap() ) + ) + .cycle() + .take(1000) + .flatten() + .collect(); + let base_pattern: Vec<i32> = vec![0, 1, 0, -1]; + + let calculate_step = |vec: &Vec<u32>, n| { + let mut result = 0; + let mut pattern = base_pattern + .iter() + .flat_map(|x| iter::repeat(x) + .take(n)) + .cycle(); + pattern.next(); // skip first value + for (val, mult) in vec.iter().zip(pattern) { + result += *val as i32 * *mult; + result = result % 10 + } + (result.abs() % 10) as u32 + }; + + let mut result = input_vec.clone(); + for i in 0..100 { + result = (1..=result.len()) + .into_iter() + .map(|x| calculate_step(&result, x)) + .collect(); + println!("{}", i); + }; +} diff --git a/2019/aoc17/Cargo.toml b/2019/aoc17/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc17" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc17/src/main.rs b/2019/aoc17/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +} diff --git a/2019/aoc18/Cargo.lock b/2019/aoc18/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc18" +version = "0.1.0" + diff --git a/2019/aoc18/Cargo.toml b/2019/aoc18/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "aoc18" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/aoc18/src/main.rs b/2019/aoc18/src/main.rs @@ -0,0 +1,6 @@ +use std::io::{self, Read}; + +fn main() { + let mut input = String::new(); + io::stdin().read_to_string(&mut input).unwrap(); +} diff --git a/2019/aoc19/Cargo.lock b/2019/aoc19/Cargo.lock @@ -0,0 +1,13 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aoc19" +version = "0.1.0" +dependencies = [ + "intcode 0.1.0", +] + +[[package]] +name = "intcode" +version = "0.1.0" + diff --git a/2019/aoc19/Cargo.toml b/2019/aoc19/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "aoc19" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +intcode = {path="../intcode"} diff --git a/2019/aoc19/src/main.rs b/2019/aoc19/src/main.rs @@ -0,0 +1,24 @@ +use std::io::{Read, self}; +use intcode; + +fn main() { + let mut input_string = String::new(); + io::stdin().read_to_string(&mut input_string).unwrap(); + + let mut count = 0; + for x in 0..=49 { + for y in 0..=49 { + let mut program = intcode::Program::from_string(input_string.clone()); + program.input = vec![x,y]; + println!("{} {}", x, y); + program.run_until_stop(); + let output = program.output; + println!("{:?}", output); + if output == vec![1] { + count += 1 + } + } + } + + println!("{}", count); +} diff --git a/2019/intcode/Cargo.lock b/2019/intcode/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "intcode" +version = "0.1.0" + diff --git a/2019/intcode/Cargo.toml b/2019/intcode/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "intcode" +version = "0.1.0" +authors = ["alex wennerberg <awennerberg@cloudbakers.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2019/intcode/src/lib.rs b/2019/intcode/src/lib.rs @@ -0,0 +1,222 @@ +use std::io::{self, Read}; + +#[derive(Debug, Clone)] +pub struct Program { + pub memory: Vec<i64>, + pointer: usize, + relative_base: i64, + pub input: Vec<i64>, + pub output: Vec<i64>, +} + +impl Program { + pub fn from_stdin() -> Program { + let mut program_string = String::new(); + io::stdin().read_to_string(&mut program_string).unwrap(); + Program::from_string(program_string) + } + + pub fn from_string(program_string: String) -> Program { + let mut memory: Vec<i64> = program_string + .replace("\n", "") // Remove ending newline + .split(",") + .map(|i| i.parse::<i64>().unwrap()) + .collect(); + for _ in 0..100000 { + memory.push(0); + } + Program { + memory: memory, + pointer: 0, + relative_base: 0, + input: vec![], + output: vec![] + } + } + + pub fn run_until_stop(self: &mut Self) { + loop { + let (_, stop) = self.step(); + if stop { + return + } + } + } + + pub fn run_until_output(self: &mut Self) -> Option<i64> { + loop { + let (output, stop) = self.step(); + match output { + Some(i) => return Some(i), + None => {}, + } + if stop { + return None; + } + } + } + + pub fn step(self: &mut Self) -> (Option<i64>, bool) { + // returns output if there is some + let operation = self.memory[self.pointer]; + let opcode = operation % 100; + let mut output = None; + let mut stop = false; + if opcode == 1 { + let mut ptr = self.memory[self.pointer + 3]; + if operation / 10000 == 2 { + ptr = self.relative_base + ptr; + } + let params = self.get_values(operation, 2); + self.memory[ptr as usize] = params[0] + params[1]; + self.pointer += 4 + } + else if opcode == 2 { + let mut ptr = self.memory[self.pointer + 3]; + if operation / 10000 == 2 { + ptr = self.relative_base + ptr; + } + let params = self.get_values(operation, 2); + self.memory[ptr as usize] = params[0] * params[1]; + self.pointer += 4 + } + else if opcode == 3 { + let mut ptr = self.memory[self.pointer + 1]; + if operation / 10000 == 2 { + ptr = self.relative_base + ptr; + } + if operation == 203 { + self.memory[(self.relative_base + ptr) as usize] = self.input.pop().unwrap(); + } + else { + self.memory[ptr as usize] = self.input.pop().unwrap(); + } + self.pointer += 2 + // input + } + else if opcode == 4 { + let params = self.get_values(operation, 1); + self.output.push(params[0]); + output = Some(params[0]); + self.pointer += 2 + // output + } + else if opcode == 5 { + // jump if true + let params = self.get_values(operation, 2); + if params[0] != 0 { + self.pointer = params[1] as usize; + } + else { + self.pointer += 3 + } + } + else if opcode == 6 { + // jump if false + let params = self.get_values(operation, 2); + if params[0] == 0 { + self.pointer = params[1] as usize; + } + else { + self.pointer += 3 + } + } + else if opcode == 7 { + // less than + let mut ptr = self.memory[self.pointer + 3]; + if operation / 10000 == 2 { + ptr = self.relative_base + ptr; + } + let params = self.get_values(operation, 2); + if params[0] < params[1] { // hm + self.memory[ptr as usize] = 1; + } + else { + self.memory[ptr as usize] = 0; + } + self.pointer += 4 + } + else if opcode == 8 { + let mut ptr = self.memory[self.pointer + 3]; + if operation / 10000 == 2 { + ptr = self.relative_base + ptr; + } + let params = self.get_values(operation, 3); + if params[0] == params[1] { + self.memory[ptr as usize] = 1; + } + else { + self.memory[ptr as usize] = 0; + } + self.pointer += 4 + } + else if opcode == 9 { + let params = self.get_values(operation, 1); + self.relative_base += params[0]; + self.pointer += 2 + //implement + } + else if opcode == 99 { + stop = true; + + }; + (output, stop) + } + + fn get_values(self: &Self, operation: i64, num_params: usize) -> Vec<i64>{ + let mut out = Vec::new(); + for i in 1..=num_params { + let mut value = self.memory[(self.pointer+i) as usize]; + let mode = (operation / (i64::pow(10, i as u32)*10)) % 10; + if mode == 0 { // position mode + // value used as pointer + value = self.memory[value as usize]; + } + if mode == 2 { // relative mode + value = self.memory[(self.relative_base as i64 + value) as usize] // usize? + } + out.push(value); + } + out + } + +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn day5_test() { + let mut program = Program::from_string("3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99".to_string()); + program.input = vec![9]; + assert_eq!(program.run_until_output().unwrap(), 1001) + } + + #[test] + fn day7_test() { + let mut program = Program::from_string("109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99".to_string()); + let mut output = vec![]; + let mut stop = false; + while !stop { + match program.run_until_output() { + Some(o) => output.push(o), + None => stop = true + } + } + assert_eq!(output, vec![109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99]); + } + + #[test] + fn day7_test2() { + let mut program = Program::from_string("1102,34915192,34915192,7,4,7,99,0".to_string()); + assert_eq!(program.run_until_output().unwrap(), 1219070632396864) + } + + #[test] + fn day7_test3() { + let mut program = Program::from_string("104,1125899906842624,99".to_string()); + assert_eq!(program.run_until_output().unwrap(), 1125899906842624) + } + +} diff --git a/2019/run_all.sh b/2019/run_all.sh @@ -0,0 +1,12 @@ +echo "Building all days" +for i in aoc* +do + cargo build --manifest-path=$i/Cargo.toml --release +done + +for i in aoc* +do + echo "Running $i" + $i/target/release/$i < $i/input/input.txt + echo "" +done diff --git a/2020/.gitignore b/2020/.gitignore diff --git a/2020/Makefile b/2020/Makefile @@ -0,0 +1,19 @@ +# the compiler: gcc for C program, define as g++ for C++ +CC = gcc + +# compiler flags: +# -g adds debugging information to the executable file +# -Wall turns on most, but not all, compiler warnings +CFLAGS = -g -Wall -std=c99 + +# the build target executable: +TARGET = aoc + +all: $(TARGET) + +$(TARGET): $(TARGET).c + $(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c + +clean: + find . -type f -name 'aoc[0-9][0-9]' -delete + $(RM) *.txt diff --git a/2020/README b/2020/README @@ -0,0 +1,13 @@ +alexandria ocasio-cortez 2020 + +written in C99 C + +I am not good at C + +make aoc[number] to build + +./aoc[number] reads from stdin + +Output is part 1 solution, then part 2 solution, newline delimited. + +acccidentally deleted day 12 and 13 -- will come back to them later diff --git a/2020/aoc01.c b/2020/aoc01.c @@ -0,0 +1,35 @@ +#include <stdio.h> + +#define TARGET 2020 +#define MAX_LENGTH 200 + +int main() { + int entrycount[TARGET]; + int entries[MAX_LENGTH]; + for (int i = 0; i < TARGET; i ++) { + entrycount[i] = 0; + } + int entry; + int c; + while(scanf("%d", &entry) == 1) { + if(entrycount[TARGET - entry] == 1) { + // Part 1 + printf("%d\n", entry * (TARGET - entry)); + } + entries[c] = entry; + entrycount[entry] = 1; + c++; + } + + for (int i = 0; i < c ; i ++) { + for (int j = i+1; j < c; j++) { + int diff = 2020 - entries[i] - entries[j]; + if (diff > 0 && entrycount[diff] == 1) { + // Part 2 + printf("%d\n", entries[i] * entries[j] * diff); + return 0; + } + } + } + return 1; +} diff --git a/2020/aoc02.c b/2020/aoc02.c @@ -0,0 +1,60 @@ +#include <stdio.h> +#include <string.h> + +#define MIN 0 +#define MAX 1 +#define CHAR 2 +#define PW 3 + +int main() { + char input[32]; + int valid_one = 0; + int valid_two = 0; + while(fgets(input, 32, stdin)) { + char c; + int mode = 0; + int min = 0; + int max = 0; + char req; + int count = 0; + + int pp = 1; + int valid_pos = 0; + for(int i = 0; 1; i++ ) { + c = input[i]; + if(c == ' ' || c == '-'){ + mode++; + } else if(c == ':'){ + continue; + } else if(mode == MIN){ + min = min * 10 + c - '0'; + } else if(mode == MAX){ + max = max * 10 + c - '0'; + } else if(mode == CHAR){ + req = c; + } else if(mode == PW){ + if(c == req){ + count ++; + if(pp == min || pp == max){ + valid_pos++; + } + } + if(c == '\0') { + break; + } + pp++; + } + } + if(count <= max && count >= min){ + valid_one++; + } + if(valid_pos == 1) { + valid_two++; + } + } + // Part 1 + printf("%d\n", valid_one); + // Part 2 + printf("%d\n", valid_two); + return 0; +} diff --git a/2020/aoc03.c b/2020/aoc03.c @@ -0,0 +1,47 @@ +#include <stdio.h> +#include <string.h> + +#define INPUT_LENGTH 323 +#define INPUT_WIDTH 31 + +int get_trees(char slope[INPUT_LENGTH][INPUT_WIDTH], int right, int down) { + int x = 0; + int y = 0; + int trees = 0; + while(y < INPUT_LENGTH - 1){ + x = x + right; + if(x >= INPUT_WIDTH){ + x = x - INPUT_WIDTH; + } + y = y + down; + if(slope[y][x] == '#'){ + trees++; + } + } + return trees; +} + +int main() { + char slope[INPUT_LENGTH][INPUT_WIDTH]; + int row = 0; + char input[INPUT_WIDTH]; + while(fgets(input, INPUT_WIDTH + 2, stdin)) { // \0 and \n i think + for(int c=0; c<INPUT_WIDTH; c++ ){ + slope[row][c] = input[c]; + } + row++; + } + + + int slope31 = get_trees(slope, 3, 1); + // Part 1 + printf("%d\n", slope31); + int result = slope31 + * get_trees(slope, 1, 1) + * get_trees(slope, 5, 1) + * get_trees(slope, 7, 1) + * get_trees(slope, 1, 2); + // Part 2 + printf("%d", result); + return 0; +} diff --git a/2020/aoc04.c b/2020/aoc04.c @@ -0,0 +1,139 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> + + +#define PASSPORT_LENGTH 256 + +int valid_passport(char passport[PASSPORT_LENGTH], int part) { + int fields = 0; + char field[4]; + char value[32]; + for(int c=0; passport[c] != '\0'; c++ ){ + if(passport[c] == ':'){ + fields++; + field[0] = passport[c-3]; + field[1] = passport[c-2]; + field[2] = passport[c-1]; + field[3] = '\0'; + int i = 0; + char p = passport[c]; + while(p != '\n' && p != '\0' && p != ' ') { + if(p != ' ' && p != '\n' && p != ':'){ + value[i] = passport[c]; + i++; + } + c++; + p = passport[c]; + } + value[i] = '\0'; + if(part == 1){ + continue; // part 1, skip this validation + } + if(strcmp(field, "byr") == 0){ + int birth_year = atoi(value); + if(birth_year > 2002 || birth_year <1920) { + return 0; + } + } else if (strcmp(field, "iyr") == 0) { + int issue_year = atoi(value); + if(issue_year > 2020 || issue_year <2010) { + return 0; + } + } else if (strcmp(field, "eyr") == 0) { + int exp_year = atoi(value); + if(exp_year < 2020 || exp_year >2030) { + return 0; + } + } else if (strcmp(field, "hgt") == 0) { + if(value[2] == 'i' && value[3] == 'n'){ + value[2] = '\0'; + int height = atoi(value); + if(height > 76 || height < 59) { + return 0; + } + } else if(value[3] == 'c' && value[4] == 'm') { + value[3] = '\0'; + int height = atoi(value); + if(height > 193 || height < 150) { + return 0; + } + } else { + return 0; + } + } else if (strcmp(field, "hcl") == 0) { + int j; + if(value[0] != '#' || strlen(value) != 7) { + return 0; + } + for(j=1; value[j] != '\0'; j++) { + char ch = value[j]; + if (!((ch >= '0' && ch <= '9') || + (ch >= 'a' && ch <= 'f'))) { + return 0; + } + } + } else if (strcmp(field, "ecl") == 0) { + if(strcmp(value, "amb") == 0){ + } else if(strcmp(value, "blu") == 0){ + } else if(strcmp(value, "brn") == 0){ + } else if(strcmp(value, "gry") == 0){ + } else if(strcmp(value, "grn") == 0){ + } else if(strcmp(value, "hzl") == 0){ + } else if(strcmp(value, "oth") == 0){ + } else { + // invalid + return 0; + } + } else if (strcmp(field, "pid") == 0){ + int j; + for(j=0; value[j] != '\0'; j++) { + if(!isdigit(value[j])) { + return 0; + } + } + if(strlen(value) != 9){ + return 0; + } + } + } + } + if(fields == 8){ + return 1; + } else if(fields == 7 && strstr(passport, "cid:") == NULL) { + return 1; + } + return 0; +} + +int main() { + int valid_passports_one = 0; + int valid_passports_two = 0; + char last_char = ' '; + int i = 0; + char c; + char passport[PASSPORT_LENGTH]; + while ((c = getc(stdin))){ + if((last_char == '\n' && c == '\n') || c == EOF) { + passport[i] = '\0'; + if(valid_passport(passport, 2)){ + valid_passports_one++; + valid_passports_two++; + } else if(valid_passport(passport, 1)){ + valid_passports_one++; + } + if(c == EOF){ + break; + } + i = 0; + } + passport[i] = c; + i++; + last_char = c; + } + // Part 1 + printf("%d\n", valid_passports_one); + // Part 2 + printf("%d", valid_passports_two); +} diff --git a/2020/aoc05.c b/2020/aoc05.c @@ -0,0 +1,36 @@ +#include <stdio.h> + +#define INPUT_LENGTH 16 +#define SEATS 1024 +#define ROW_BITS 7 +#define COLUMN_BITS 3 + +int seats[SEATS]; + +int calc_id(char ticket[INPUT_LENGTH]) { + int i; + int id = ticket[0] == 'B'? 1: 0; + for(i=1; i < ROW_BITS; i++) { + id = id << 1; + if(ticket[i] == 'B') id++; + } + for(; i < ROW_BITS + COLUMN_BITS; i++) { + id = id << 1; + if(ticket[i] == 'R') id++; + } + return id; +} + +int main() { + char input[INPUT_LENGTH]; + while(fgets(input, INPUT_LENGTH, stdin)) { + seats[calc_id(input)] = 1; + } + int i = SEATS-1; + while(seats[i] == 0) i--; + // Part 1 + printf("%d\n", i); + while(seats[i] == 1) i--; + // Part 2 + printf("%d", i); +} diff --git a/2020/aoc06.c b/2020/aoc06.c @@ -0,0 +1,42 @@ +#include <stdio.h> + +int countb(int n) { + unsigned int count = 0; + while (n) { + count += n & 1; + n >>= 1; + } + return count; +} + +int main() { + int total_one = 0; + int total_two = 0; + int group_one = 0; + int group_two = -1; + int person = 0; + char last_char = ' '; + char c; + while ((c = getc(stdin))){ + if((last_char == '\n' && c == '\n') || c == EOF) { + total_one += countb(group_one); + total_two += countb(group_two); + group_one = 0; + group_two = -1; + if(c == EOF){ + break; + } + } else if(c == '\n') { + group_one |= person; + group_two &= person; + person = 0; + } else { + person |= (1 << (c - 97)); + } + last_char = c; + } + // Part 1 + printf("%d\n", total_one); + // Part 2 + printf("%d\n", total_two); +} diff --git a/2020/aoc07.py b/2020/aoc07.py @@ -0,0 +1,40 @@ +# this day is in python, may redo in C later + +import sys + +lines = sys.stdin.read().split("\n") + +rules = {} +for line in lines[:-1]: + outer_bag = line.partition("bags")[0] + inner_bags = line.partition("contain")[2].split(",") + parsed_bags = [] + for i in inner_bags: + i = i.strip() + if not i.startswith("no"): + parsed_bags.append({"q": int(i[0]), "color": i.partition( " bag")[0].partition(" ")[2]}) + + rules[outer_bag.strip()] = parsed_bags +seen = [] +holds_gold = 0 +for k,v in rules.items(): + seen = [k] + while seen: + current = seen.pop() + for value in rules[current]: + seen.append(value["color"]) + if current == "shiny gold": + holds_gold += 1 + if len(seen) == 0: + break + +def get_subs(color): + result = 0 + for value in rules[color]: + result += value["q"] * (get_subs(value["color"]) + 1) + return result + +# part 1 +print(holds_gold) +# part 2 +print(get_subs("shiny gold")) diff --git a/2020/aoc08.c b/2020/aoc08.c @@ -0,0 +1,96 @@ +#include <stdio.h> + +#define ACC 0 +#define JMP 1 +#define NOP 2 + +struct instr { + int code; + int val; + int ran; +}; + +struct instr bootcode[1024]; +char instruction[32]; +int flipped = -1; + +int flip_instr(int j) { + /* printf("flipping %d\n", j); */ + if(bootcode[j].code == JMP) { + bootcode[j].code = NOP; + } else if(bootcode[j].code == NOP) { + bootcode[j].code = JMP; + } + flipped = j; +} +int reset_flip_instr() { + if(flipped > -1){ // unflip + /* printf("un"); */ + flip_instr(flipped); + } + int i = 0; + for(i; i<1024; i++) { + // reset computer + bootcode[i].ran = 0; + } + flipped++; + if((bootcode[flipped].code == JMP) || (bootcode[flipped].code == NOP)) { + flip_instr(flipped); + } +} + +int main() { + int i = 0; + // generate program + while(fgets(instruction, 32, stdin)) { // \0 and \n i think + int code = -1; + if(strncmp("acc", instruction, 3) == 0){ + code = ACC; + } else if(strncmp("jmp", instruction, 3) == 0){ + code = JMP; + } else if(strncmp("nop", instruction, 3) == 0){ + code = NOP; + } + char* substr = malloc(10); + strncpy(substr, instruction+4, 8); + int val = atoi(substr); + struct instr tmp = {code, val, 0}; + bootcode[i] = tmp; + i++; + } + + // execute program + int p = 0; + int accumulator = 0; + int first_run = -1; + while(1) { + if(bootcode[p].ran){ + // Part 1 + if(first_run){ + printf("%d\n", accumulator); + } + p = 0; + accumulator = 0; + reset_flip_instr(); + first_run = 0; + continue; + } else { + bootcode[p].ran = 1; + } + int code= bootcode[p].code; + int val = bootcode[p].val; + /* printf("p%d a%d c%d v%d\n",p, accumulator, code, val); */ + if(code == ACC){ + accumulator += val; + } + if( code == JMP){ + p += val; + } else { + p++; + } + if(p == 1024 ){ + printf("Not in a loop -- %d\n", accumulator); + return; + } + } +} diff --git a/2020/aoc09.c b/2020/aoc09.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <string.h> + +#define PREAMBLE 25 + +int xmas[1024]; + +int main() { + int i = 0; + // generate program + char* input[32]; + int partone; + while(fgets(input, 32, stdin)) { // \0 and \n i think + int value = atoi(input); + xmas[i] = value; + i++; + if(i > PREAMBLE){ + int sums = 0; + int j, k; + for(j=i-PREAMBLE-1; j < i; j++) { + for(k=i-PREAMBLE-1; k < i; k++) { + if(xmas[j]+xmas[k] == value && xmas[j] != xmas[k]) { + sums = 1; + } + } + } + if(!sums){ + printf("%d\n", value); + partone = value; + } + } + } + for(i = 0; i <= 1024; i++) { + int sum = 0; + int j; + int max = 0; + int min = 100000000; // idk + for(j = i; sum < partone; j++) { + sum += xmas[j]; + if (xmas[j] < min) { + min = xmas[j]; + } + if (xmas[j] > max) { + max = xmas[j]; + } + if(sum == partone){ + printf("%d\n", min + max); + return; + } + } + } +} diff --git a/2020/aoc10.c b/2020/aoc10.c @@ -0,0 +1,54 @@ +#include <stdio.h> + +#define INPUT_LENGTH 98 + +int joltages[INPUT_LENGTH]; + +int cmpfunc (const void * a, const void * b) { + return ( *(int*)a - *(int*)b ); +} + + +unsigned long long int paths[256]; + +unsigned long long int get_value(int v) { + if (v < 0) { + return 0; + } else if (v == 0) { + return 1; + }else { + return paths[v]; + } +} +int main() { + char input[8]; + int i = 0; + while (fgets(input, 8, stdin)) { + joltages[i] = atoi(input); + i++; + } + qsort(joltages, INPUT_LENGTH, sizeof(int), cmpfunc); + int last = 0; + int freq[4] = {0}; + for(i=0; i<INPUT_LENGTH; i++) { + freq[joltages[i]-last]++; + last = joltages[i]; + } + freq[3]++; // device voltage + // Part 1 + printf("%d\n", freq[1] * freq[3]); + // Part 2 + int device_voltage = joltages[INPUT_LENGTH] + 3; + int possible_arrangements = 1; + + int value; + for(i=0; i<=INPUT_LENGTH; i++) { + if(i == INPUT_LENGTH) { + value = value + 3; + } else { + value = joltages[i]; + } + paths[value] = get_value(value-2) + get_value(value-1) + get_value(value-3); + } + printf("%lld\n", paths[value]); +} diff --git a/2020/aoc11.c b/2020/aoc11.c @@ -0,0 +1,130 @@ +#include <stdio.h> + +/* This one is messy */ + +#define EMPTY 'L' +#define OCCUPIED '#' +#define FLOOR '.' + +#define WIDTH 90 +#define HEIGHT 91 +/* #define WIDTH 10 */ +/* #define HEIGHT 10 */ + +typedef char SEATGRID[HEIGHT][WIDTH]; +SEATGRID seats; + + +void copy_seats(SEATGRID from, SEATGRID to) { + int x,y; + for(y=0;y<HEIGHT;y++) { + for(x=0;x<WIDTH;x++) { + to[y][x] = from[y][x]; + } + } +} + +int swap_seats(int mode) { // returns n occupied + char newseats[HEIGHT][WIDTH]; + int x, y; + int occupied = 0; + for(y=0;y<HEIGHT;y++) { + for(x=0;x<WIDTH;x++) { + char state = seats[y][x]; + int neighbors[8][2] = { + {-1,-1}, {-1, 0}, {-1, 1}, {0, -1}, /* 0 0 */ {0, 1}, {1, -1}, {1, 0}, {1, 1} + }; + int n; + int occupied_adjacent = 0; + for(n=0; n < 8; n++) { + // For part two, we keep searching in this direction + int vision = 1; + while (1) { + int xdiff = neighbors[n][0] * vision; + int ydiff = neighbors[n][1] * vision; + if( + x+xdiff >= 0 + && x+xdiff < WIDTH + && y+ydiff >= 0 + && y+ydiff < HEIGHT + ){ + if (seats[y+ydiff][x+xdiff] == OCCUPIED ) { + occupied_adjacent++; + break; + } else if (seats[y+ydiff][x+xdiff] == EMPTY ) { + break; + } + } else { + break; + } + if(mode == 1) { + break; + } + vision++; + } + } + char new_state; + if(state == EMPTY && occupied_adjacent == 0) { + new_state = OCCUPIED; + } else if(state == OCCUPIED && occupied_adjacent >= 4 + mode - 1) { + new_state = EMPTY; + } else { + new_state = state; + } + if(new_state == OCCUPIED){ + occupied++; + } + newseats[y][x] = new_state; + } + } + // copy over + copy_seats(newseats, seats); + return occupied; +} + +void print_seats() { + int x, y; + for(y=0;y<HEIGHT;y++) { + for(x=0;x<WIDTH;x++) { + printf("%c", seats[y][x]); + } + printf("\n"); + } + printf("\n"); +} + +int main () { + int x = 0; + int y = 0; + char c; + while(( c = getc(stdin))) { + if(x > WIDTH) { + x = 0; + y++; + } + seats[y][x] = c; + x++; + if(c == EOF){ + break; + } + } + int last = -1; + int occ; + SEATGRID temp; + copy_seats(seats, temp); + while(occ != last ) { + last = occ; + // specify part number + occ = swap_seats(1); + } + printf("%d\n", occ); + // Reset + occ = 0; + copy_seats(temp, seats); + while(occ != last) { + last = occ; + occ = swap_seats(2); + /* print_seats(); */ + } + printf("%d\n", occ); +} diff --git a/2020/aoc14.c b/2020/aoc14.c @@ -0,0 +1,105 @@ +#include <stdio.h> + +#define LINE_SIZE 64 +#define MEMORY_SIZE 9999999 +#define MASK_SIZE 36 + +typedef char bitmask[MASK_SIZE]; + +long long int memory_v1[MEMORY_SIZE]; +long long int memory_v2[MEMORY_SIZE]; + +void parse_mask(char* input_line, char* dest) { + int i; + for(i=0; i<MASK_SIZE; i++) { + dest[i] = input_line[i+7]; + } +} + +void parse_mem(char* input_line, int* index, long long int* target) { + int i; + for(i=4; input_line[i] != ']'; i++) { + *index = *index * 10 + input_line[i]- '0'; + } + for(i+=4; input_line[i] != '\n'; i++) { + *target = *target * 10 + input_line[i] - '0'; + } +} + +long long int apply_mask(long long int target, bitmask mask) { + int i; + for(i=0; i<MASK_SIZE; i++) { + if(mask[i] == '1') { + target |= (1ULL << (MASK_SIZE - i - 1)); + } else if(mask[i] == '0') { + target &= ~(1ULL << (MASK_SIZE - i - 1)); + } // X -> Do nothing + } + return target; +} + +long long int get_memory_sum(int version) { + int i; + long long int result = 0; + for(i=0; i<MEMORY_SIZE; i++) { + if(version == 1) { + result += memory_v1[i]; + } else if(version == 2) { + result += memory_v2[i]; + } + } + return result; +} + +/* a nightmare */ +void apply_memory_v2(int index, long long int target, bitmask mask) { + int i; + int newindex = index; + for(i=0; i<MASK_SIZE; i++) { + if(mask[i] == '1') { + newindex |= (1ULL << (MASK_SIZE - i - 1)); + } else if(mask[i] == '0') { + } else if (mask[i] == 'X') { + mask[i] = '0'; + int j; + bitmask newmask1; + bitmask newmask2; + for (j=0; j<MASK_SIZE; j++) { + newmask1[j] = mask[j]; + } + newmask1[i] = '0'; + index &= ~(1ULL << (MASK_SIZE - i - 1)); + apply_memory_v2(index, target, newmask1); + for (j=0; j<MASK_SIZE; j++) { + newmask2[j] = mask[j]; + } + newmask2[i] = '1'; + apply_memory_v2(index, target, newmask2); + } + } + printf("%d %d %lld %s\n", index, newindex, target, mask); + memory_v2[newindex] = target; +} + +int main () { + char input_line[LINE_SIZE]; + bitmask mask; + while(fgets(input_line, LINE_SIZE, stdin)) { + int index = 0; + long long int target = 0; + if ( input_line[1] == 'a' ) { // Mask line + parse_mask(input_line, mask); + } else if ( input_line[1] == 'e' ) { // memory line + parse_mem(input_line, &index, &target); + memory_v1[index] = apply_mask(target, mask); + bitmask v2_mask; + int i; + for (i=0; i<MASK_SIZE; i++) { + v2_mask[i] = mask[i]; + } + apply_memory_v2(index, target, v2_mask); + } + } + printf("%lld\n", get_memory_sum(1)); + printf("%lld\n", get_memory_sum(2)); +} diff --git a/2020/aoc20.c b/2020/aoc20.c @@ -0,0 +1,56 @@ +#include <stdio.h> + +#define image_size 10 + +struct Frame { + char imgseg[image_size][image_size]; + int id; +}; + +void setsides(struct Frame *f) { + int y=0; + for(x=0;x<image_size; x++) { + + } + +} +void frameprint(struct Frame *f) { + int x=0; + int y=0; + for(y=0;y<image_size; y++) { + for(x=0;x<image_size; x++) { + printf("%c", f -> imgseg[y][x]); + } + printf("\n"); + } +} +int parse_tile_line(char* input) { + int i; + int result = 0; + for(i=5; i<9; i++) { + result = result * 10 + input[i] - '0'; + } + return result; +} + +int main() { + char line[image_size + 3]; + struct Frame frames[11]; + int y = 0; + int n = 0; + while(fgets(line, image_size + 3, stdin)) { + struct Frame f; + if(line[0] == 'T'){ + f.id = parse_tile_line(line); + y = 0; + n++; + } else if (line[0] == '#' || line[0] == '.') { + int x; + for(x=0;x<image_size; x++) { + f.imgseg[y][x] = line[x]; + } + frameprint(&f); + } + y++; + } +} diff --git a/README b/README @@ -0,0 +1,7 @@ +advent of code + +still haven't completed a full year + +2021: TBD +2020: C +2019: Rust