diff --git a/1-report_repair/.gitignore b/1-report_repair/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/1-report_repair/.gitignore @@ -0,0 +1 @@ +/target diff --git a/1-report_repair/.vscode/tasks.json b/1-report_repair/.vscode/tasks.json new file mode 100644 index 0000000..ffef723 --- /dev/null +++ b/1-report_repair/.vscode/tasks.json @@ -0,0 +1,13 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "type": "cargo", + "command": "run", + "problemMatcher": [ + "$rustc" + ], + "label": "rust: cargo run" + } + ] +} \ No newline at end of file diff --git a/1-report_repair/Cargo.lock b/1-report_repair/Cargo.lock new file mode 100644 index 0000000..99c15ac --- /dev/null +++ b/1-report_repair/Cargo.lock @@ -0,0 +1,239 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "ansi_term" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +dependencies = [ + "winapi", +] + +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "bitflags" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "clap" +version = "2.33.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "textwrap", + "unicode-width", + "vec_map", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "heck" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "hermit-abi" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +dependencies = [ + "libc", +] + +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.81" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "report_repair" +version = "0.1.0" +dependencies = [ + "itertools", + "structopt", +] + +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c" +dependencies = [ + "clap", + "lazy_static", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "1.0.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "unicode-segmentation" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796" + +[[package]] +name = "unicode-width" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + +[[package]] +name = "version_check" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/1-report_repair/Cargo.toml b/1-report_repair/Cargo.toml new file mode 100644 index 0000000..0cd0894 --- /dev/null +++ b/1-report_repair/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "report_repair" +version = "0.1.0" +authors = ["Guilhem MARION "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools = "0.9.0" +structopt = "0.3.20" diff --git a/1-report_repair/data/input.txt b/1-report_repair/data/input.txt new file mode 100644 index 0000000..ee00017 --- /dev/null +++ b/1-report_repair/data/input.txt @@ -0,0 +1,200 @@ +1749 +1897 +881 +1736 +1161 +1720 +1676 +305 +264 +1904 +1880 +1173 +483 +1978 +1428 +1635 +1386 +1858 +1602 +1916 +1906 +1212 +1730 +1777 +1698 +1845 +1812 +1922 +1729 +1803 +1761 +1901 +1748 +1188 +1964 +1935 +1919 +1810 +1567 +1849 +1417 +1452 +54 +1722 +1784 +1261 +1744 +1594 +1526 +1771 +1762 +1894 +1717 +1716 +51 +1955 +1143 +1741 +1999 +1775 +1944 +1983 +1962 +1198 +1553 +1835 +1867 +1662 +1461 +1811 +1764 +1726 +1927 +1179 +1468 +1948 +1813 +1213 +1905 +1371 +1751 +1215 +1392 +1798 +1823 +1815 +1923 +1942 +1987 +1887 +1838 +1395 +2007 +1479 +1752 +1945 +1621 +1538 +1937 +565 +1969 +1493 +1291 +1438 +1578 +1770 +2005 +1703 +1712 +1943 +2003 +1499 +1903 +1760 +1950 +1990 +1185 +1809 +1337 +1358 +1743 +1707 +1671 +1788 +1785 +1972 +1863 +1690 +1512 +1963 +1825 +1460 +1828 +1902 +1874 +1755 +1951 +1830 +1767 +1787 +1373 +1709 +1514 +1807 +1791 +1724 +1859 +1590 +1976 +1572 +1947 +1913 +1995 +1728 +1624 +1731 +1706 +1782 +1994 +1851 +1843 +1773 +1982 +1685 +2001 +1346 +1200 +1746 +1520 +972 +1834 +1909 +2008 +1733 +1960 +1280 +1879 +1203 +1979 +1133 +1647 +1282 +1684 +860 +1444 +1780 +1989 +1795 +1819 +1797 +1842 +1796 +1457 +1839 +1853 +1711 +1883 +1146 +1734 +1389 diff --git a/1-report_repair/src/main.rs b/1-report_repair/src/main.rs new file mode 100644 index 0000000..433fb5a --- /dev/null +++ b/1-report_repair/src/main.rs @@ -0,0 +1,66 @@ +use std::io::{BufRead, BufReader}; +use std::path::{PathBuf, Path}; +use std::fs::File; +use itertools::Itertools; + +use structopt::StructOpt; + + +#[derive(StructOpt, Debug)] +struct Opt { + /// Input file + #[structopt(parse(from_os_str))] + input_file: PathBuf, +} + +fn main() { + // Check argv + let opts = Opt::from_args(); + // eprintln!("opts = {:?}", opts); + // Load file if possible + let file_path = Path::new(&opts.input_file); + let input = File::open(file_path).unwrap(); + let buffered_input = BufReader::new(input); + let lines: Vec = buffered_input.lines().filter_map(Result::ok).collect(); + // eprintln!("lines_iter = {:?}", lines_iter); + + /* First, naïve solution */ + // while let Some(line) = lines_iter.next() { + // let iter_clone = lines_iter.clone(); + // // eprintln!("iter_clone = {:#?}", iter_clone); + // for line2 in iter_clone { + // let l1: i64 = line.parse().unwrap(); + // let l2: i64 = line2.parse().unwrap(); + // if l1 + l2 == 2020 { + // eprintln!("l1 = {:#?}", l1); + // eprintln!("l2 = {:#?}", l2); + // dbg!(l1 + l2); + // dbg!(l1 * l2); + // } + // } + // } + + let res_two = find_2_sum_to_2020(lines.iter().filter_map(|x| Result::ok(x.parse::())).collect()); + let res_three = find_3_sum_to_2020(lines.iter().filter_map(|x| Result::ok(x.parse::())).collect()); + //let res_three = find_sum_to_2020(3); +} + +fn find_3_sum_to_2020(numbers: Vec) -> Option<(i64,i64, i64)> { + for (i,j, k) in numbers.into_iter().tuple_combinations() { + if i + j + k == 2020 { + println!("Found {} and {} and {} whose sum is {} and whose product is {}", i, j, k, i+j+k, i*j*k); + return Some((i,j,k)); + } + } + None +} + +fn find_2_sum_to_2020(numbers: Vec) -> Option<(i64,i64)> { + for (i,j) in numbers.iter().tuple_combinations() { + if i + j == 2020 { + println!("Found {} and {} whose sum is {} and whose product is {}", i, j, i+j, i*j); + return Some((*i,*j)); + } + } + None +} diff --git a/2-password_philosophy/.gitignore b/2-password_philosophy/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/2-password_philosophy/.gitignore @@ -0,0 +1 @@ +/target diff --git a/2-password_philosophy/Cargo.lock b/2-password_philosophy/Cargo.lock new file mode 100644 index 0000000..117f472 --- /dev/null +++ b/2-password_philosophy/Cargo.lock @@ -0,0 +1,70 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "anyhow" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c0df63cb2955042487fad3aefd2c6e3ae7389ac5dc1beb28921de0b69f779d4" + +[[package]] +name = "password_philosophy" +version = "0.1.0" +dependencies = [ + "anyhow", + "thiserror", +] + +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "1.0.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thiserror" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" diff --git a/2-password_philosophy/Cargo.toml b/2-password_philosophy/Cargo.toml new file mode 100644 index 0000000..3d26b36 --- /dev/null +++ b/2-password_philosophy/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "password_philosophy" +version = "0.1.0" +authors = ["Guilhem MARION "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.35" +thiserror = "1.0.22" diff --git a/2-password_philosophy/data/input.txt b/2-password_philosophy/data/input.txt new file mode 100644 index 0000000..082b283 --- /dev/null +++ b/2-password_philosophy/data/input.txt @@ -0,0 +1,1000 @@ +13-17 s: ssssssssssssgsssj +7-9 p: pnlzhcppvl +5-6 z: zzbwrv +7-15 w: wwwwwcqwwwwwwwww +8-9 h: hhhhhhhhsh +12-13 l: mtrkqfllrglll +3-4 t: nntt +10-14 g: svgggggfhqggghlg +3-10 x: djxxxpmcxx +1-10 z: ztzzzgzzzz +3-4 j: jjjjj +3-4 c: fbhnsccbc +2-4 q: thql +15-18 w: tcwzpwzfwwqftvczbw +5-7 l: lblwblbmllqnlbl +3-4 b: bvbfnbb +4-5 f: ffgzf +7-9 c: cctcccccc +5-6 k: szkgsk +2-5 n: nqvnmgnqnsxfn +2-10 s: dsfsbsssltss +12-14 s: ssskrssssssfsxpsqsp +13-15 j: jjjjjjjjjjjjjjjj +16-17 l: jllclhllkgcpljzwk +6-9 f: fsffwffbffbfff +5-9 s: xtzscxsstcss +6-9 h: hmnhshhhhqhrthmh +3-6 x: xxxxxx +9-11 m: mcmmmktmtmmmmm +2-6 r: grrprrsmr +15-16 v: vvvvvvvvvvvvvvwdv +2-14 j: jmjdbhjjjjjjjxnjj +5-9 r: rrwrrrrrr +3-9 b: wbbcbvbtbbbbb +2-9 r: rrtjlplkrgmrrrrxq +9-12 s: sssshsmsssss +2-14 t: qzxxvthtthtthv +2-11 p: pvlsppwmgcspl +12-15 s: dsjqsshdssbssstsssss +3-9 k: tkkkpkkklk +7-15 s: sssssssssssssgsssss +6-9 x: xxxsxzxglpwxl +2-3 x: xxmh +7-9 g: ggsggggggg +4-17 t: vtttrrrhtghfjvnqtttj +1-2 n: jgnpn +11-12 k: vlkkbkkkkklk +9-12 v: vvvvvvvvwvvvv +10-11 j: jjjjljjjjvm +1-5 x: vvxlx +3-4 l: flll +10-11 q: qqqqqqqqqlq +4-5 d: vdvhmpdtrdhdzfdsgk +14-16 b: bbqbbbxbhrbpbtmhbbb +18-19 d: dzpnbxngpgsjtnvtcdd +2-16 v: jtrhtlfhvkbbflfq +15-17 q: qqqsqqqqqqjqqqlqm +5-6 q: tqrhtqqspdqvzqbx +4-8 b: lbbzbwtv +10-13 f: hrsnsfflfffsfjff +10-14 k: kkjkkkkkkkkkkkkkkhk +4-9 c: ccwcccccc +5-7 r: grkrrrwjrrgbdtd +8-12 p: tgspnljpfhtr +5-6 v: vvvvvvm +5-7 v: vvvvvvv +6-8 q: qqqqqdqqq +2-4 v: xfvqvlp +3-4 g: gghb +3-14 z: xflgzzrkzqzxzzxgd +1-7 g: ldsgswgdgdmjlggb +5-10 h: rhhmhhnbdhhqhwp +16-18 m: mmmmmmwmmmmmmmmmmmm +5-11 j: scssgcjjjjpzjjn +13-14 s: wznksvkfvfskfs +3-9 q: qdqqkqtbcnqqqsrklqbf +7-9 c: cccchcmcvdcczwt +15-16 g: gggdgggggggggggg +1-5 k: kkkkkk +7-10 q: qqqqqqqqqqqqq +3-12 b: bbbrhbspbrbfbbqbbbb +3-5 r: gczrgr +2-6 h: whnlvhsftp +8-20 h: fhhhsdfhhfzgmhpqhhjh +15-16 z: sbzzzzzzdzjbwhgb +4-8 h: jgtbmhwb +8-9 s: hssksrnhlsdslssvcsbs +2-6 v: vvvvvvv +13-14 x: xxxxxxxxxxxxnsbx +12-13 l: pgllllltpdfpxlll +2-17 v: vqnncnxkssmhvkzstzgp +4-5 r: rrrhw +8-11 p: pppdppphppp +6-7 t: lrmqtts +8-12 h: hhlthhhhhhhhhtrzh +9-10 g: jpgpmpcrwfkz +12-13 w: wwwwwwwwwwhwwww +5-13 l: jwtlqglllllxkllls +2-4 c: ncpcgd +3-7 l: llslllll +2-5 n: jdfwnn +3-5 z: xctxd +4-6 l: lllrll +6-7 q: fqqqqqqzqqqqq +9-12 c: gccwgwqlcxccchchcrcb +7-12 p: pppgpppppppps +10-16 g: xrgfggzzghtgxgbggg +7-11 d: tdddddqdwdgxldj +11-14 p: pppppbpppppppppp +1-2 j: jhjj +8-9 v: pvvvvvvvcgvq +5-6 n: qcrhnnkktxvdxcp +7-12 x: lfnxxxdxxxxp +10-12 s: sssssssssbsgs +2-3 x: rqhzxmjnjxx +13-14 w: wwwwvwwwwwwwqhww +10-11 t: dgttttgttttt +7-9 w: wdzwwwwjj +4-10 v: vvsjvvbvvncvvvvxv +6-8 w: wwwwwpwq +7-9 j: jtjjjjrjmxg +5-11 z: zzdgztshstzczw +1-4 s: ssss +3-10 p: pqppgrphrpkdmp +9-12 x: xxxqxxxlxxsx +3-4 v: nvswzv +3-9 d: vdjvdcxdkdd +2-10 v: vvjcvvvzvkb +11-14 g: gggzggggggjgghg +4-19 p: pppqppppppppppppppvq +3-5 n: ngznkgdpn +13-14 t: tttwtbtttttxxmttt +3-7 q: qnqqqqqtqqz +3-4 r: rkgr +9-12 l: lqkfljzllqtl +5-8 m: vpmmsnfmtxbcknlmpb +15-19 s: ssptssnhsksnszsdpqss +13-14 j: jsjjjjnjjjjjjjj +6-9 p: ppppppppz +5-8 r: tqzbnvgsvfrx +7-9 h: hhhhhhhhp +8-11 s: ssssssssssss +3-10 t: ttttttttttttt +4-5 g: ngtgg +7-8 n: tnnnnnnqn +12-16 x: bxxxxxzxxxxxxxbxx +1-3 z: zzzt +11-14 x: xxgxxxxxxxwcxfx +6-11 v: rgkkhpkjvvf +16-17 n: nfgnnnnnnnnnnnngvn +3-7 w: wkwwwww +5-16 g: ggggcggwgggggggggg +1-3 l: sjvjlkzrpn +17-19 p: pppppppppppppppptpd +2-6 b: vjjwbqbdbpwsbw +4-8 g: gggggjvgd +2-6 w: pzzpwdm +3-10 g: ggggcggggggg +1-3 v: vxvjcvcpslpfn +9-10 r: qrrwrrjrrr +5-10 m: qbmdzvqmxnnmmmtk +2-14 q: vqttpdjhqvkqzqxz +12-13 r: rrxbrrrrrcrptjrr +13-15 s: cscssssssssssssss +7-10 z: zxbrzxbdbhzzzfzz +2-16 n: skqkxqmqbvbrnspnrgq +14-18 b: bbxsbbdpbnbbbnbbbpbb +5-8 b: bmcrdhbbk +11-13 f: fffffffzfffwffb +5-6 w: wwbwlww +12-14 d: gzxclqbnmnxjlzd +13-19 z: fzzzctzzdsbgzzzzwzpb +2-12 w: lcwwtwwpwffdjqwms +9-10 x: hznxnxxxxxxxgkxx +2-4 g: cwfjtlgf +11-12 k: bqfkkkklkkkkb +2-4 l: llllgxk +5-9 m: cpwmqkzhxs +8-15 b: bbwlwkblvbwdvrjbgsb +3-4 f: ffmff +4-10 c: nqxcqcfcqc +10-12 d: ddqddddddtdhd +3-4 n: dghnnqnn +6-15 s: rsbxbrfmssdknppw +2-13 m: mmkmmmmqdmkmmm +8-12 n: nnnnnnnnnnnn +2-5 d: mdkwd +14-15 l: hllllllllllllgl +6-11 g: jgccfnggggpgkt +4-6 j: jjjtjjjjjj +9-12 v: hgpjjlvhvhljb +2-4 g: jfwdgfr +4-5 f: fhffffchf +16-17 j: jjjjjjjjjjjjjjjjj +1-4 t: tcttwtttttrkt +6-13 x: qmxfxxwxrxdxxxfvgv +6-7 c: cckpccc +3-10 m: qwmmpknsgmdmfvrcvw +2-4 r: rszv +1-7 q: qqqqqqqq +1-6 l: lzlmjl +11-12 q: mqqqqxbqqrqqqdqqbkq +8-11 h: jtvbhxhhphhhh +9-11 b: bbbbfbzbzbb +5-7 l: gljssxddzscvhwrlrb +3-6 c: fxcbccddxxcn +3-5 s: ssssz +17-18 n: jctqdsjchwknkffpnn +8-10 c: crtwbwcfcqkf +3-5 r: qrzqc +7-12 z: zzzzzzzzsfzsz +13-15 p: pppppppppzrllplp +11-12 h: nhhhhjhqhhplhhh +4-5 l: lllll +4-10 g: gggzgggggg +15-16 h: qhhhshrhhfhhhhch +5-7 k: jsrvnjlkq +16-17 p: pppplppppppppppml +13-14 m: xqhmjdmrmmmffr +6-11 c: cccccgccccrccccccc +9-10 l: llllllllxllt +8-9 b: bbbpbbbwbdnkbb +5-9 m: sfmmpmmmzn +5-15 k: kkkkkkkkkkkkkkkckkkk +3-4 h: hhhh +15-19 g: gggwgggrslgxjgfgbfs +12-13 d: dddddddddddxb +6-14 k: kkrgdvhscffwwm +14-16 m: zmmmmqmmmmmmmgmm +8-9 w: wwwwgwwww +1-12 x: xxxxxxxxxxxx +1-5 b: bwrbbfwgh +1-3 t: ftttttttttttttt +10-11 m: mwmmmwkmxsf +8-9 t: tqtttttttdtttt +7-8 z: hzbkpzfg +2-3 h: htblhdhh +3-4 p: pptnlpc +4-7 l: lqlnqhljt +12-14 n: nnnnnnnnnnjnnt +1-4 d: dszd +12-13 f: fvrffffffffkfff +9-15 t: bkzstqvtgtwxtzqttd +6-7 v: vrvvvkgv +6-9 n: knbpnnjnnsn +5-8 n: nznkzzqrbn +9-12 s: ssscssssgsqwsspssp +4-16 q: slqqqqqhqqqqqqdqc +1-3 d: gdttdd +2-6 h: hhqzmh +4-9 k: lkckkpbzkl +8-17 b: bbbbkbbpbbbbbbbbn +1-2 r: bqmrw +8-9 s: ztssqssbz +1-13 s: stbqmhspsdgjs +8-10 z: trnsmlxzmzzzz +6-8 v: vlxvgzbzvvv +3-6 c: xddhwtcbpcf +13-19 g: rjvsgpnfjvzlxxzzgxgm +5-9 m: qffpmxmfmk +14-15 c: dcfwcpxcmvpxxtcbmzhc +6-10 k: jkpbkvghpxksfkkk +2-3 j: jmgjjjj +7-12 z: szrznmkjxnzj +4-9 s: ssssssssss +2-4 h: hkqvfgpsxlnhtrqr +6-11 g: gggglrlgggwv +1-6 v: vrbvlvrvv +4-10 j: jjjjjjjjjz +3-12 k: kkjkkkkkfckgkkkkk +3-15 x: xxrxxxxxxxwxpxg +5-8 v: vvhvvdzvqfrvgqvt +5-17 z: zznzzzzzzzzzzzzvf +4-12 n: fdrncrggjlbgbmwv +6-17 d: tcddhdbdvtsnrdstd +1-10 m: mqljmgchlmsx +4-6 l: fbllbl +8-9 p: kpmtpphwp +3-6 j: sjjjjj +5-6 n: nnnnbs +7-12 p: ppqppngcphpk +5-15 x: xxxxgxxxxxxxxxqx +1-3 p: ppppm +3-6 w: wwwkwww +1-4 r: rrrx +3-4 z: zzznp +12-14 n: tnzwtmnnnnndnfnnn +9-10 d: ddfdddtdddd +4-14 l: hvllsgncmhxhwl +10-15 j: kxftfsmjvjgslsjpp +2-10 g: gtgvggqggggxggdg +1-9 v: cvnxhhffnbcv +1-14 c: ccccccccccccccc +3-8 q: fnqmkbhqtbjqvczq +2-4 v: fvphvgv +10-11 k: kkkkkkkkkpt +1-10 d: dddldkddmdd +4-6 x: xxxxxxxx +4-11 k: kxkfkkkskkrkmk +1-6 n: nlmngnkqww +1-9 j: jjjjjjjjsj +5-6 b: bbbbbb +9-11 q: qqnqqmqqqpq +4-7 r: drrrrsrrz +10-15 n: nnhncnpsnxtnpnqnnghn +3-6 d: ddddddd +4-7 x: bxvxbxjwxgx +1-2 n: cmpwsbjzghgndj +2-4 r: przczfjfrbwj +3-17 k: qbvmqxxffdfpkwxdgxv +7-12 v: llmjvscvjvpvp +2-7 z: vzxzxxz +9-18 r: srdrjcrrrvhrcqrrrr +7-8 f: rffffvtrfsqff +5-8 w: pdcwwvmwwwkzwwjwxks +3-4 c: cccc +15-19 c: cccccccnccclbnplccqc +2-13 f: fffffffffffffff +3-9 t: thrkzdttb +6-11 p: pppppgppppjp +5-8 q: qqqrqfqs +7-11 r: crprgtwwrzp +2-10 f: qfhgfftfdbfnlffffff +4-5 h: dhvvlcw +3-6 s: sffsfws +2-7 b: jrvxbhbp +10-11 w: wwwgwwwwwkb +5-9 d: dddddddddddddkdv +4-14 b: bbbbbbbbbbbbbbb +4-8 x: xxxxdxbqxc +5-9 l: phlkhlllbc +1-2 s: ssgskqvrsrwdt +19-20 x: xcxqxvxxxtstnqxhxxxx +6-7 x: gxxxxgb +4-5 c: cccccc +3-10 q: pzzjqjqpfbqws +4-10 t: ttdttsccttpt +14-18 c: ccrccccccccccccccrc +2-5 x: xxzqx +5-11 c: qbckpccckccccws +5-6 g: gggggg +3-5 n: wknbnnlnnq +9-13 j: jjxjjjnjjjdqjjj +5-9 s: smsxsrfss +2-4 v: vxphvvk +6-7 x: xxxqxxbbx +1-3 g: zrgtghjwd +4-5 n: nmntwnn +6-8 g: ggznggggg +4-5 k: tkkzs +9-10 g: hqdhggggqggk +12-16 w: wwztwmwwspwhmwwz +3-5 m: mmmvmjmmm +3-4 j: jjjj +6-16 z: kzbtzqrkzzcfhvpwjszx +3-9 f: ffwffffffff +13-15 b: bbbmsbbbbbbwbbbbwb +11-14 n: nnnnnnnnnnnnnnv +8-9 v: bvvflvvbjvbtjqrvsxf +1-5 g: gjgnggg +15-16 n: nnnnnnnnnnnnnnwvqnn +12-13 l: lllhllrlllllllll +5-6 l: llmlll +8-9 z: zzqzdzvzzzz +3-4 d: ntdd +4-5 b: sbndbkjxldqpzfbzbqx +2-5 t: bwcfzdlfslsd +4-5 d: dddddd +1-3 t: jtpt +10-12 q: qqqqgqqqqqqmqq +10-19 m: mmmmmmmmmsmmmmmmmgs +2-14 x: xxxxxgxvxmxxxbx +3-13 l: tzljvxspwxdnl +6-10 p: lhnppkpswrppgppzpppn +2-6 j: djgwjjhvpwkcgsfbf +10-11 p: ppppppppprpppppp +7-12 l: lvgcbnlclvjlk +6-11 z: zzzzzzzzzzn +3-5 x: xzvhxnpwbxgxx +4-6 h: hhlrhnl +8-10 b: brngbslhqhb +6-11 s: ssqjxsssdsssss +2-5 s: dbjdjknspbdldfbjd +10-16 z: ctzzzzznzcwzztzl +14-15 j: jjjjjjjjjjjjjjjj +9-13 d: qvdpwddddddddd +10-12 c: ccccchcccccq +3-5 x: xxxxx +13-14 t: ttstttztttttltt +3-16 k: qvfjklgzlwfwnbjklqdx +12-13 g: ggggggtgggggggvg +11-15 j: vqzjvzvxjhjnjtj +7-8 t: tttttttg +6-7 x: xxxxfmn +10-13 m: mmlmmgvfmmmdmmcmmq +7-14 w: wwkwwwwwwwmptwww +17-18 b: bbbbbbbbbbbbbbbbbb +2-8 c: kbvcnrpx +16-17 n: nnnnnnnnpnnnnnngl +10-15 k: kbkjkdkwpkkhkkksklx +2-12 p: pjhdkvwdltvqrhm +2-4 x: vxhxxk +3-5 m: mmfmf +6-8 n: ngnggfnwnn +9-16 b: bnbbbtcbbbvbbrbbbbb +2-8 p: ppphpzppcgptpprhpp +9-12 x: xxxxxxxxxxxx +5-7 d: dknbddd +7-9 r: rrrrrrrrj +3-6 f: fjmfxk +3-4 n: jnnnbjckggnpjnddhx +6-12 d: dznpsfdtdsdndjddvcdd +7-12 x: xxxxxxhqxxxbxbsx +1-2 k: kkfkkkk +4-7 l: lprlqllll +10-13 x: qxxqkjxxxxxxmz +3-8 f: rxfffwcff +4-5 s: cpscszdssc +5-6 t: tttftt +2-6 p: kpvtkprdqhxzpxrbfp +6-12 s: ksnsklwqfssdsbsss +6-7 l: lzlflfl +7-9 t: ttktttttt +8-14 d: hdddzndhsddpfpdxt +8-10 d: ddnddrddvxbzskddzd +11-13 v: mvhvrtvvvvzvrvdv +4-5 g: gggjw +3-6 m: xhmrpm +7-13 k: kkkkkkkkkkkkk +10-13 n: nnnnnnmnngnnnnnn +7-15 m: kcmtmjtmwjmcsbbms +13-16 j: jjjjjjjjjjjjpjjlj +2-4 n: nnmnkn +12-14 j: jjjjjjjjjjjdjj +1-2 c: cchc +9-12 m: mmmqbmlwmmjmzmmml +3-8 r: rrkkrrrt +4-5 k: wckknxkpkktmks +9-10 d: ddddpdddnpx +1-8 q: qmpmxzfqnqctwpprm +10-12 q: sgkfxhqjkqqq +5-11 p: rwpppdlmhpptkbrlp +1-2 d: lzrbxnlcsqhssgdpvjs +5-6 c: scccck +4-5 s: ssshxsssws +3-11 l: nslwgmxmtblzttxxg +10-11 z: zzzzzzzzzzz +7-8 j: bjjjjjqdbjj +7-8 d: glpfjbpdxd +2-4 k: wkvwrk +1-5 c: vtcgcbc +16-17 x: xxxxxxxxxxxxxxxxm +2-11 f: ffffffsfffffffffffff +4-8 m: mrmmmmmmmmmmmm +2-3 x: xvzxx +2-4 h: hxpn +13-17 x: xxxxxxxxxxxrxpxxxx +4-13 q: wcqqtwwmwqqtqmqtqrqq +10-12 d: dddtdqdnjxdzdfdd +13-14 f: jffffsffmffqjff +6-7 d: sxdvddddwqxd +5-11 d: ddddfdddddcdddd +11-14 b: bbbbbbbbbhlbbj +3-4 p: pfpp +4-7 j: jjjgwkgwnfffvfzfl +6-9 l: gknrmjgxtlzcbvkgxb +4-10 n: nnnnnnnnntnnnnnnxn +1-4 r: rjrr +3-4 m: nkmr +9-10 f: fffffffffff +2-6 r: rnhtml +3-12 q: qqkqqqqqqqqkqqqqq +3-10 r: rrnrrrrrrrrrrrrr +6-8 m: bmmmdmmmmdmh +10-12 g: ppdvvxgkhfskfqc +2-10 v: txpvkgvcbqvqfk +1-5 p: tqcvbtp +6-7 z: zzzzzzz +7-16 z: fdjbbkrzjzdbdblhxb +2-4 x: xlkz +4-11 m: glhknzmvqzfmnsbn +6-8 q: qhmdgqvq +8-16 t: tttdtttdtttttttbvt +4-7 v: vptcmgvvjvvvfvvmht +7-8 t: ttttttngt +5-15 t: ztgbttrntttdvgtptjdb +10-12 b: bvndbbbbbbbbbbbbtb +2-3 t: sbqts +12-16 w: wwwwwwwwwwwwwnwww +2-3 m: kmmr +12-15 k: kkmkrkkkkzkdkrgkk +5-13 h: hhhhzhhhhhhhzhhhh +16-17 l: lllllllllllllcllq +1-3 b: bbjb +2-5 t: vtjhmf +4-5 q: vzdqfd +2-3 n: nnnn +7-14 j: jpjjjjjjljjjjjjjj +12-15 j: crsjpjjjqjjfjkv +10-11 t: ttttttttttttt +1-2 j: jjbjsjvhbfssznf +9-13 f: ffmfffffzfffgfff +15-18 g: sgblrqdftpwzggvgqt +19-20 r: rrrrrrrrrrrrrrrrrrvj +1-4 j: mjlt +3-10 x: jxxxxxxxxgxxx +6-7 p: ppptppp +7-8 b: jbmnbmsc +2-6 f: zshfcbhsh +2-5 r: rrrqwtrvclf +3-8 g: chgtwlbg +11-15 n: knnhnnhnnnpnlknnkhnn +3-8 z: zkqlzzpmjph +5-10 b: bbbbhbbbbbbbbbbbbb +6-15 c: ccccdkrncwrcclc +6-7 c: ckcccwdhcc +12-13 t: ntttktttttftttt +5-8 j: jpjzcjjjjj +7-8 k: kpkkksbkkkkkr +9-12 s: sqssssbssxcs +3-7 p: pbbplhtfpktpnppx +5-7 n: ncnnnsn +4-6 s: sssrss +3-16 v: kvvvvvvczvvvvvvvkww +3-6 k: kkkpmk +8-9 h: hhhhhhhmb +7-9 c: czwcccmtckccc +5-7 t: tstglltkt +2-6 c: cccccv +11-14 z: zzzkzqzzzzzvzzz +3-4 d: ddch +4-6 j: jjjjjvj +5-9 c: cccccccccccccc +7-9 j: hjkwpjjbjfsq +4-6 t: tttlcdb +13-15 z: zzzzzzzzzsqzzgzzzkz +8-10 t: ptckdjtsptlmzrktwcw +2-5 n: tnbhnnkvnq +11-12 m: fqmmmmmqmtmkcmmvnwmm +7-8 z: zzzzztvl +6-7 j: jbpjjjjpxmqxcbwsjrjj +2-8 t: ttkdzfwdtflfswlkntt +6-11 j: rnjjjjjjjjj +10-13 f: fwhkbfdfffvfs +5-8 l: pflplntf +3-5 r: rrrrr +16-20 g: gggggggggggggggggggg +1-12 t: xtnsxbjtttxtt +7-9 r: zrrrrrkrnrrrrrrrrr +2-11 n: nrjnnnwnnprnnn +10-12 z: zzzkxzzhznzdz +7-13 d: pdcjdddqddlddcdkdxk +10-15 r: rrrbrrrmvrcphrrqr +1-3 l: rsll +7-8 x: xxxqvrxx +5-14 p: ppcdvppbppppjpbg +5-11 x: dxdxdhkxxvxqxxxfx +6-12 r: pvbfrhqrhftqrrxcrr +4-7 t: zdbtzst +1-13 k: kkkpkghkqkskk +5-17 g: gvggqgggggqmgxggfgg +12-13 l: llllwllllllwf +2-11 b: bbbbbbbbbbbbb +7-17 h: hhhhhhhhhhhhhhhhhh +2-3 w: lwww +2-3 s: vstcs +4-6 s: vssssxss +14-16 r: fmrrrrrrrrrrwwrvrr +6-7 g: dgwgggp +12-16 g: wggxgggrggggzgbgggg +7-9 s: tjhxrscnsscssssnms +3-12 n: nnnnnnnnjnnlnnnnn +7-8 b: zncbmbglqbbbbpgm +12-18 l: lllllllllllvlllllwl +10-16 q: qqqgqfqqqqqrrqgqq +1-7 n: nnnsnrnnnp +10-11 q: qqqqqbqqqqq +5-8 k: bnsfzkkwfkknkccwqkm +4-5 c: ccdcccc +5-9 z: nlsgzzzdz +2-3 k: xkgxhqkpftx +10-13 d: ddddddddhdddddddd +4-6 x: xmjxwxx +14-16 z: zzzzzzzzzzzzzrzq +3-14 n: qnznjvlzdnnrgwfr +7-13 s: sssxsspsssssrz +4-11 k: pkkkcklbkkkk +9-11 x: xxxxxxxxxxtx +4-6 z: zzjzzfz +3-6 d: zddddddz +10-20 c: smccccvcpbccbqcxbccq +13-15 m: mmmmmvmmmjmnnmlpsm +12-13 j: jjjjjjjjjjjjj +3-5 m: pmmbm +7-17 m: mmmmmwcmmdfqrmmhlmm +3-17 g: gcggnggbgdggggggg +10-16 b: sqpsqkfbnbqzswbb +3-4 w: wwwn +5-6 d: dddddpd +12-15 m: mmmmmmdmmmqlmnvms +13-15 j: jjjjjtjjjjjjzjcj +17-18 t: ttttttttjtttttttttt +17-18 d: dcddmchdwbqrllsxjdv +16-17 h: hshghhndnhhfhhhhh +3-5 g: ggggch +6-13 c: ccvccpccccccvcccccc +2-4 h: hbfh +3-9 l: lllptphml +2-3 s: xwrqssfzr +9-13 m: mktmmwmmmmrmmrqmmmcm +8-11 l: rkvxvrglltlc +1-8 q: jfqqxngqnqchq +2-6 x: zxgjxx +5-14 g: mlbgvdglrgcqjgz +4-5 t: tqgtv +2-6 s: ssfnzs +9-11 m: mxwhmmmmmmzm +1-5 d: dbhjzd +2-16 f: fffffffffffkffffff +6-10 b: dbbbbbbbbbbb +5-6 x: xxxmxxcx +7-8 l: lllpllcb +16-17 d: dzdddddddddddddddd +3-10 t: tklkqftnwcj +9-15 g: jccxpmfjgntpptgkkcvt +1-8 r: sdrwgcvprt +4-5 v: nhbwx +17-18 z: zzzzzzzzzzzzzzzzxsz +5-13 l: cbdklqhnklkmwhpp +4-5 f: fffff +1-4 q: qpwq +9-11 x: vxxgrgxxfvvgx +3-4 r: rrfd +3-16 x: sxqxxxxxxxxxxxxwxxx +5-8 s: ssssssss +5-13 b: jbbhqqbblbbbbfcb +17-18 p: ppppppppprpppwppphp +3-9 p: kdpnpfphppvffpwf +7-8 r: jvrrrrrnrpqrn +5-6 m: ncmmdxmm +10-11 v: vvvvvvvvvdl +3-8 g: jlsscggg +1-3 m: gwms +4-5 f: fpkvnf +6-15 j: zfdrxjgxtbkbbjjctmsk +5-6 v: qnnbvvwqvbwqblqd +2-5 v: kvhvt +2-6 x: lxrgsxg +6-8 s: sssxswsjsssxss +1-6 t: dxwjttnqkt +13-14 s: sssssssssssvjg +1-2 t: rtttnf +9-17 h: hjhhhvhhbhhwhhhhphd +2-3 m: mmmwcm +10-12 v: vvvvvvvvvvvv +6-10 j: flcjtzwhwsnjjjrjrj +3-8 d: ddmrddddd +5-8 c: ccccslcrwrc +13-14 s: hpsqtxvkrsssshh +11-15 t: hrxtjgtwtlmpqfx +11-14 l: llbxlsllllqrqlllzlb +3-4 c: crlcvcxwd +3-9 s: vjbsxhwwdvshfxstc +7-8 f: jfhnffbgsfjfwf +15-16 x: ksxqvfsvnxsgvwgpjzl +16-19 g: gggggggggggggggdggg +9-11 h: hhhhhchhzmqhh +2-6 f: kfdlcfrxftzgq +2-8 p: ppnppkpwwmgp +1-2 g: ggfgrg +1-7 n: nnnnnnqwnnn +5-6 h: hzjgthqphwhnjh +10-15 l: xlllllllvlllllll +3-4 l: lzjb +4-6 l: ldzlql +7-12 b: mzlbqzbrqjjbddr +10-13 t: tttttxtttpttt +4-6 d: dddddd +4-5 k: kzvkkrkf +1-2 h: fqml +17-18 f: jhtfdfgmnchprbwbfrf +3-10 s: sjsnsksbdsss +1-17 j: jgcbjmjjjjjcxsjjjjhj +15-16 k: tkjkjbkkrkkkklmgkj +2-13 k: kkkkfkqkkkkkkkkpkk +4-13 d: ddkkdtddzdnnddjdd +1-3 v: fxvnxdvxnrbjs +8-11 s: sssssssssspssssss +1-8 k: khkkkkkkhk +8-9 k: kkktmkkzk +4-9 w: wrqdfwxwnfwwwnmzww +3-5 l: lgtcvl +13-18 n: nnnnnnnnnnqnnnvnnnn +15-17 z: zzzzzzzzzhzzzzqzv +3-5 q: lxnqsvk +8-13 g: rzzwdlzgbcmggct +10-14 d: ddvdbddddnddpd +6-10 d: dphsszqrvz +8-16 b: bnbgfbkbbbqlbcbbgqbb +13-15 d: dddjddmqndddddddvjdd +8-11 q: tnhgqkqfpjhwqgktq +1-3 n: nnnbn +11-12 f: fwfffbfcvflff +7-8 s: sssglsvssvls +2-5 z: zzzzzzzzzqjzz +2-11 m: mhzrwphzxgj +4-6 k: kkkwkd +8-15 m: mrmmmmmzmmmmzmgmm +1-7 w: wwwwwwxwwww +1-3 l: nllllllll +4-5 m: zbshj +3-9 x: xssxqxxxsxkzx +5-9 d: dnpfhsdmrxbvgxqrs +7-12 r: vhrgcnxrvksg +8-10 c: ccccccctzv +16-17 l: lllllllllllllllhl +6-15 n: nnnnnnngnnfhwwzsnnn +6-19 z: zzzzzlzzzzzzzzzzzjv +7-12 b: bxfbbwsjtbbvbqvbmbpb +5-14 g: gggcjggggggggmgg +5-8 d: wdddddkdpd +4-17 x: xtxxxxxxxxxxxxxxmkx +4-10 c: cccccccccjcscv +9-11 v: ttjzfjldvvmswpqt +5-8 r: tjrwhzgfrkgfq +5-8 m: cvhsmnzmncsfmbqmm +7-8 z: krctfpzz +2-6 w: mlnlswvh +12-15 t: zrntxzttqlthfdttt +1-8 r: pkcsjkrrrzxxsfnjw +5-15 p: xbhpkpnngpqvpcwdppg +3-4 t: tttt +8-11 j: wjjjmjjjjjqp +8-14 h: gjslnklhhkhthxh +2-6 q: qqlqqq +3-6 p: pppgppppppppppp +7-11 l: llhllllrllllxldllll +11-12 d: lddkdddddddddd +4-12 z: zwlzzqsvvclw +15-18 c: tflkxflqccwkmlckck +8-12 h: hhhhrhhhhfwhhh +6-9 r: rrrmrjrrvkrrjrdr +8-19 k: tmdlkcktbkkskvkbkbz +1-13 s: ssssssssssssss +4-5 v: xtcfvx +1-15 s: shtssssswghsfsss +2-4 k: krkl +7-12 q: dxqqqhqqqtqj +1-5 r: rrrvvrrrr +5-9 t: ttrttftxztnhtvkcmtth +7-9 g: gngkcggrg +12-13 z: zzzzzzzzzzzbk +3-4 l: lslllc +4-5 t: pqchpk +5-6 h: hhhhml +15-16 h: qhhhhhhhhhhhhhhhhhmh +5-6 d: ddddfs +1-6 d: dthfdzddfnsdddm +14-15 d: ddddddddndhtddsdnddh +5-7 j: qjjjpjplljjc +2-6 q: qqqqqqq +3-4 b: bbbb +5-6 s: ssssjjs +1-6 b: bbbbfb +7-13 m: cpvmbbnnrmzwf +2-4 f: fnhn +6-7 d: gdktlddrdlvmqdtddpzv +4-5 w: cwlww +6-9 z: zmdrgzlmzx +5-10 m: mjbjmmmlmmwxm +2-4 s: ssnhht +8-16 t: tttttttdtttdtttjtt +3-5 z: wxgzhtswb +13-14 l: lllllblpllllchll +4-8 g: vggqzvggnggggggggg +8-9 h: hhthkshhpnhqhgh +4-7 l: hglxklpl +2-3 w: mkmgkwzwmw +6-7 h: hhhhhrz +4-6 f: tdffff +1-7 l: lmfhgqschjqglrvwwnnz +12-13 g: gggggggggggfhggg +2-10 m: ntmmmdjmmmsvmm +1-2 s: sqsssssssssss +3-8 f: frnthfcfxfft +7-16 w: wwwwwwmwwnwwwwmk +11-13 j: jjkjrjjjjjjjjjd +3-4 s: ssvc +3-13 t: ddttttnnqpqztzbbdv +3-5 g: gggggg +3-4 r: rrrzlklfljqvz +5-12 m: kdgmmrszqpfsbmz +11-14 g: gqgvzgxhgbtngxggh +7-16 k: qqptmhhfkhsgkhbmkx +5-8 p: ppppptppp +2-17 x: vxtxpvnxvlctrcpfxxx +2-3 w: bwmwjwwwwwtnqwxc +4-5 g: gggggg +4-7 z: znzwzzzs +4-5 v: kvvvv +10-14 r: rrrrrrrrrbrrrx +4-5 t: xtttt +4-11 w: wwwwwwdcmkrwx +6-7 c: ccccccjc +12-14 w: wkwwwwwwwhwlwwwk +5-9 s: hmssssssssss +2-4 r: rrrjsh +12-13 m: mmmmmmmmmmmmmx +3-5 s: sshsvssss +4-5 l: xllwnshchfdfk +16-18 w: wwpwwpwwwmwwzwwtwwww +2-9 c: zsfgbrrprlszrr +10-11 n: thnmfndnnbnnbhnnnn +13-14 v: vvvcvvvvvvvvvvv +3-4 n: rwcm +14-15 t: tttttztttttttpjt +5-8 j: jjjjwhjdj +5-8 f: fffffffm +6-7 z: zzqzzzz +12-19 j: kjrfnsjnhjdzgqpcjzvh +3-7 p: pxpdvcqdptxpvk +1-4 c: wccqj +1-2 w: pwsqhwjdhcm +2-3 b: bfbn +10-19 q: qqqqqqqqqtqqqsqrqqq +5-8 p: pppppppppppppppp +10-13 g: rjghslgbggkgjdgvp +3-9 z: fnnfzzdnf +9-16 g: tlgtgggggggggggqm +3-12 r: rrrvccrrvbdbncrrr +1-4 v: jvhbv +15-16 v: vvvdvvcvvvpvvvvvvvv +3-4 g: ggggg +7-8 w: wwwwwwmpw +4-9 s: gkxshzkpssc +2-8 q: pqttnpqqqfwqs +3-4 n: nlnp +3-4 h: phhh +16-18 g: hqsxhmmpfgggmgpqhrjg +15-17 w: wwgwwwwwwwwwwwmwl +7-9 x: xxxxxxmxv +1-7 s: ssssssbs +1-3 x: dxlxxx +3-6 p: wpxppq +5-7 c: clcclcfcbccc +3-5 s: sbmst +3-5 d: xqmdn +5-10 z: zbzwfddkzzc +18-19 d: dpdddddddddddddddwcv +3-4 r: rrrr +8-9 f: ffnffffwd +12-16 h: hxnlxghzkpcpdhqqvl +6-7 m: jngclmm +5-13 m: rmmmpmrmmmmmjmmmm +1-3 f: dfwfs +7-8 l: lclllwllll +16-18 j: jjjjjjjjjjpjnjjgjbj +12-15 f: fffffffffffnfftfffff +9-13 w: qbnpmklbwxdbbwkklpwb +1-3 j: mjkj +1-3 h: hphwdh +3-5 x: vrxxb +1-15 v: mvvvvvvvvvvvvvj +8-12 v: lvzfvzvvnjtvvvvvv +4-6 g: gggvggggg +13-20 l: zdllslnlxslqpnvgwlwm +2-4 l: lllhll +3-14 k: kckzddtzbmvkpkhb +4-5 k: hbkgbxzj +2-4 p: lppp +2-11 r: rrrrrbrrbrrrrwrrrwr +4-7 k: knkqkkk +7-8 r: njrrrrrrrr +4-7 h: phhhnhdhc +4-5 r: nsnrrfktwbbhrrrh +4-5 q: qqzvzsvkq +6-7 b: jbbbbbbbkbgb +5-11 f: ffffcfffffgff +12-16 v: vfvvqvvdvvvlhvzjvmzv +9-10 v: vvzvvtvvjgvv +1-7 v: vvvvvvvv +3-12 z: zmncxhrdzdmtcbxtlrzq +3-7 r: rbfbrjrr +12-13 n: nnnnnnnnpnnldnn +5-12 j: jjjjjjjjjjjlj +3-6 s: sssfsgss +13-17 h: hhhfhhhhhhhhvhhhhhhh +5-10 g: gggxkggggvg +1-4 b: hbbtb +14-15 t: tttttttttttttnb +7-14 d: ddddddddddddddhdw +15-16 d: rbdddbdwmjdhmpdd +7-13 s: kxpdntprmskcs +3-5 m: gmdmpj +4-5 j: jjjjjvjsj +1-14 q: qmqqqntqcqxmqsqkqq +4-5 q: tqxqq +8-11 m: mmmxmmmvmmv +5-8 q: qqqqrqqw +5-15 d: dqdddddddddddvspd +1-4 t: tttttt +12-15 z: dhzzxwfjgnzhzxt +8-11 v: kdnmfnmqvvdvqdlvk +16-18 s: sssssssssssssssjstss +2-5 c: ccwdccc +3-11 x: nxjxxxxxxxxxxx +13-15 v: vvvvfvvqvlvvvvvv +4-11 s: sssszssnqjsbsvs +9-18 j: gxhjjjjjnjjsjjjrjjjj +3-4 t: ttfttt +9-10 s: qzgxjhpsss +9-10 q: qqqqnrtxrqqsqqq +6-13 k: kkkrgspkkkpwjshmk +9-12 h: xhhhmhbhhhdhh +3-12 g: gfgggggjgggggggggg +13-15 z: zzfzzszzzzzzvzzzhzw +5-15 m: mzrmmmmndchfzmmrr +5-10 z: zzzzzzmzzh +4-5 s: wscfc +3-6 m: kmmtmm +5-7 h: hhhhchh +4-14 w: wwgwwwqwsfrjvmbwj +2-9 v: vwvvwvmjcqnxv +9-10 x: qxxhfxchrx +17-18 x: xxxxxxxxxxxxxxxxwp +4-6 v: vvvvvtv +11-14 l: lcqlclllllrlddxlzll +1-4 r: trrn +10-13 h: thnsxphnfgvhvq +11-12 s: sssssssssshsss +10-11 z: rqpzszzmzdz +3-6 q: qrqqqq +5-6 h: hhkhhhh +8-16 h: wqhjvhlgwtsgvlpf +3-6 f: gqfpcfsfhfjgrbqv +3-5 l: lqllsrjlv +6-10 v: vvvvvvkvjv +3-8 t: gtttcbnkxxstttd +2-6 j: jjjjbjz +10-15 j: ftwjtfzjmjsvwjj +8-11 d: ddsksddddzfd +2-3 b: bhngbb +14-16 c: mllmcbfxwxrqlcjcw +7-8 q: qqqqqqdv +5-6 s: slkzlfvg +3-5 q: qqqqq +3-12 p: pddpdpszrppxcpjgv +11-18 r: rrrrrrrrrrprqrrrrr +3-4 c: cscckcxcn +11-13 g: gvgwmlngggqggrtgtkg +5-7 b: smfpbbb +7-18 l: sqmlklvkqfjrgtqhzr +6-7 k: kkpqqfgz +7-9 n: fnndnnxnndn +11-12 c: ccccccccccxv +6-9 d: dddvdddddddvd +1-4 v: nvjfv +3-8 g: gggggggg +6-7 x: xxxxxxx +4-5 c: scccc +6-13 q: nchlfqqqlqnqqqtq +1-8 r: srrrrrrnrrrrrrr +4-5 p: sdpscpppp +9-11 r: rrrdrkrrrqg +3-5 m: xwmscmmm +7-11 r: rrrfrrrrkfrvrf +4-6 b: bbfbbb +4-9 v: rblrvrvpvz +2-8 w: wwwvwgwww +8-9 w: wwwwwwwwzw +16-18 t: ttttttttttttttttttt +8-9 n: nfrzsdjxr +1-2 w: wwfwwmfbww +2-4 s: dfsksft +1-13 d: dwdrccnddqmndcl +1-4 f: qfflf +3-7 d: dnddjpdfgc +3-5 l: lkglx +1-13 j: jjjjgbjtpjjhd +15-16 j: jjjjjjvjjjjjjjjjdjj +4-13 t: tttxztttttttkt +4-5 m: mmmmm +4-6 j: jgjrjwjfjx +8-11 t: ttbjttvttsttdqtn +14-15 w: wwwwwwwwwwwwwkjw +1-6 x: nrscxn +3-13 w: wwwwwvgnwbwwwwwwv +12-15 p: pppppppppppjpppppppp +5-11 v: vvvkvbvwkwnvvvsxvv +1-11 m: mmmmmmmmmmtm +10-11 c: cccccccccwc +5-8 f: xvgstwfxfhxknds +12-13 t: tttttztttttttt +4-17 k: vkpkfkkkqnkqnkgkkknk +9-12 k: kkwpzpdzxhxk +14-17 v: fgvvvvvvvvvvvjpvv +7-8 k: kndnqkkk +7-11 c: gfcbccccjvcskcmrcxc +4-5 n: ngtnr +3-12 k: mtcfszkdhkdkd diff --git a/2-password_philosophy/src/main.rs b/2-password_philosophy/src/main.rs new file mode 100644 index 0000000..cc82f93 --- /dev/null +++ b/2-password_philosophy/src/main.rs @@ -0,0 +1,111 @@ +use std::ops::RangeInclusive; +use anyhow::Result; + +#[derive(Debug, PartialEq)] +struct PasswordPolicy { + char: u8, + range: RangeInclusive, +} + +impl PasswordPolicy { + fn check_password(&self, password: &str) -> bool { + self.range.contains( + &password + .as_bytes() + .iter(). + filter(|&&c| c == self.char) + .count() + ) + } + + fn check_password_newpolicy(&self, password: &str) -> bool { + (password.chars().nth(self.range.start()-1).unwrap() as u8 == self.char) ^ (password.chars().nth(self.range.end()-1).unwrap() as u8 == self.char) + } +} + +#[derive(Debug, thiserror::Error)] +enum ParseError { + #[error("Expected {0}")] + Expected(&'static str) +} + +fn parse_line(line: &str) -> Result<(PasswordPolicy,String)> { + let (policy_s, password) = { + let mut tokens = line.split(": "); + ( + tokens.next().ok_or(ParseError::Expected("Coucou"))?, + tokens.next().ok_or(ParseError::Expected("Coincoin"))?, + ) + }; + let policy = { + let (range_s, char_s) = { + let mut tokens = policy_s.split(' '); + ( + tokens.next().ok_or(ParseError::Expected("Range"))?, + tokens.next().ok_or(ParseError::Expected("Char"))?, + ) + }; + let (min_s, max_s) = { + let mut tokens = range_s.split('-'); + ( + tokens.next().ok_or(ParseError::Expected("Min"))?, + tokens.next().ok_or(ParseError::Expected("Max"))?, + ) + }; + PasswordPolicy { + char: if char_s.len() == 1 { + char_s.as_bytes()[0] + } else { + // return Err(ParseError::Expected("policy byte to be exactly one byte")); + return Err(ParseError::Expected("password policy byte to be exactly 1 byte").into()); + }, + range: (min_s.parse()?)..=(max_s.parse()?), + } + }; + Ok((policy, password.to_string())) +} + +fn main() -> Result<()> { + let count = include_str!("../data/input.txt") + .lines() + .map(parse_line) + .map(Result::unwrap) + .filter(|(policy,password)| policy.check_password(password)) + .count(); + println!("{} passes are valid", count); + let count_new_policy = include_str!("../data/input.txt") + .lines() + .map(parse_line) + .map(Result::unwrap) + .filter(|(policy,password)| policy.check_password_newpolicy(password)) + .count(); + println!("{} passes are valid with new policy", count_new_policy); + Ok(()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_is_valid() { + let policy = PasswordPolicy{ char: b'b', range: 1..=4 }; + assert_eq!(policy.check_password("boumbaby"), true); + assert_eq!(policy.check_password("b-b-b-boumbaby"), false); + assert_eq!(policy.check_password("oumay"), false); + } + + #[test] + fn test_parse_line() { + assert_eq!( + parse_line("1-5 b: boulbi").unwrap(), + ( + PasswordPolicy { + char: b'b', + range: 1..=5, + }, + "boulbi".to_owned(), + ) + ) + } +} diff --git a/3-toboggan_trajectory/.gitignore b/3-toboggan_trajectory/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/3-toboggan_trajectory/.gitignore @@ -0,0 +1 @@ +/target diff --git a/3-toboggan_trajectory/Cargo.lock b/3-toboggan_trajectory/Cargo.lock new file mode 100644 index 0000000..85fa51a --- /dev/null +++ b/3-toboggan_trajectory/Cargo.lock @@ -0,0 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "toboggan_trajectory" +version = "0.1.0" diff --git a/3-toboggan_trajectory/Cargo.toml b/3-toboggan_trajectory/Cargo.toml new file mode 100644 index 0000000..777a780 --- /dev/null +++ b/3-toboggan_trajectory/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "toboggan_trajectory" +version = "0.1.0" +authors = ["Guilhem MARION "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/3-toboggan_trajectory/data/input.txt b/3-toboggan_trajectory/data/input.txt new file mode 100644 index 0000000..d193cf2 --- /dev/null +++ b/3-toboggan_trajectory/data/input.txt @@ -0,0 +1,323 @@ +.#.#....##.......#..........#.. +...#...........##...#..#....... +#.####......##.#...#......#.#.. +##.....#.#.#..#.#............#. +##.....#....#.........#...##... +###..#.....#....#.............. +..........#..#.#..#.#....#..... +##.....#....#.#...#.##......... +#...#......#....##....#..#.#... +.##.##...#....##..#.#.....#...# +.....#.#..........##.#........# +.##..................#..#..##.# +#.#..........##....#.####...... +.#......#.#......#.........#... +#....#..##.##..##........#.#... +##..#.##..#...#..####.#..#..... +###....#.###.##...........##..# +.....#.##.....##.#..#####....## +....#.###....#..##....##...#... +..###.#...##.....#.##..#..#.#.. +#...#..#..#.........#..#....... +##..#.#.....#.#.#.......#...#.# +...#...##.#........#...#....... +..#..#.#..#...#...#...........# +........#.....#......#...##.... +#........##.##.#.#...#...#..... +####.......#.##.###.#....#..... +...#...........#...#......#...# +##...#...#............#.......# +....#...........##.......#..... +###......#.....#....#...#.#...# +.....##..........#.......#.#... +##.##.##...#......#....#....... +##..#.#..#......#...#..#....... +....#....##.##............####. +..#.###..#.##.###..#.##.......# +#.##..#.#.....#..#.....##...... +..##..#.....##.#.##........#... +.#..#.#......#..#............#. +.....#..#.#...#....#.##.#...... +.#...##.#..#.#...##...##..##... +###............#.#..#..#...#... +..#..##.####.#.....#.....##.### +#....#.##..##....#..#...#.##.#. +.....#.##.........##...##...... +.........####.#....#.#......#.# +.........#.#..#...#.#..#.#....# +.#.....#..##.##..##....#....... +..........##......#.##.###....# +.##...###..##.#...#........##.. +..............#.#....#.#.###.## +..##.##.......#.#......##...#.. +.#.....#..##..#.###...#..#.##.# +#.....#.#..#...#........#...#.. +.#......#....#.#.....###...#..# +..##.#....#..##......#.....#... +..#.#.##..#.....#.####..###.... +.........#......#..#........... +..#........#.##.#.....##.##..#. +.......#.........#....#...#.#.. +.##.....#.#....#.#.......#..... +..........#.##........##...##.. +###..###.#.#..#..#####.##.#.##. +..##..##.#.#...#..#.#.#......#. +#..#..#..#..##..#.....#......#. +..#....#.##..#......##......... +..#.##......#...##.#......#.... +.......#..#.##.#.....#......... +.......#.#.#.###...##......#... +.....#.#..........#..#...#..... +....##..........#..........##.. +..#......#.....#.##.#..#...#.#. +....#.....#..#...#..#.#.##..### +.####....#........#...#........ +...##.#.##.#..#...##...#.##.... +....#...#...#.#.#.#...#..#..... +.....#...#.#.....#.#........##. +..#.#.......###.#.....##....... +......#.........##....#....#..# +.............##.....##......... +.........##...##.......#.....#. +##.........#..........#.###..## +...#.....#......#....#..##..... +##..#...#...##.#.....#.#......# +..#...##.#.......#.#......#.##. +......#.......#.#...........#.. +..........#.....##............# +#........#...#..#.......###.##. +.##...........#.#........#.#.#. +...#..##...#.#....#####.#...... +.....##...###...#..#.##...####. +...#....#.....#..#.......#..... +#....#....#...#..#..#.######..# +#.###...........#......#...#..# +.#.#.#.#..#....#....#...##.#... +.#..#.........#.#....###...#... +......#..##.##..........#....## +.....#......##....##.....#...#. +.#...#.#.#....##....#..#....#.# +..................#..###.#..##. +..#.........#......#....#..###. +#.#.....#..#..#....###..###.... +..##..##.#..##........##...##.. +##..#........##..###..#.....#.# +..#..###..#......#....#...#...# +#..#.#..............##.#..#.#.. +.....####....#...####.....#.#.. +.....#....##.#......###........ +##.##...#.#.#.#.......#....##.. +.#......#...#.#....#..##.#.##.# +#.#.##.#.#......#..##........## +...##.....#.....#...#..###...#. +........###.....#.....#...##..# +.....#.##.##......#.#....#...#. +.#....##.......#..#.####....... +.#..#....#..........#......#.#. +.#.##.##.....###.#.#........... +.........#......#..##.......... +....#...##.#.#.#..#.#.........# +..#.....#.##...#..#..#.###....# +...#.##......#.....##....#..... +###............#.#....#...#.... +.......#.....#..#.#.#....#..#.# +...#......#.#..##..#....#...#.# +............##........##..##... +..#..#.##..#......###..#....... +........#.........#............ +..#...#.#########.#...##..###.. +#....#......#.......#.#.....#.. +#.#..#....###.###....#...#.#... +#...###.#.#.......#.##......#.. +.................#...#.#.#..... +##....#...#........#....#.#..#. +......#.....#...#..........#.#. +##..........#...#..........#.## +..#.#.##.#....#.#......#...##.. +.....#.......#..#.....#........ +#.##.#..##..#.......##......... +....#......#..#..#.#...#....... +...#....#................###... +.##.....#.#....#.#..........##. +...#..#....#.##.##......#...... +..#.#....#.......#.#..##....... +....#.....#..........##.#.##### +#.....................##..#..#. +.###..#.##.......##.#...#..#... +...###.......#..#...#......#..# +#..#...#.#..#.#..#..#.##....... +#...##.......#..#..#.##..###... +......#....#.#.#........#.##..# +..##..#....#....#..#.#..#...... +..##.#...#.#######..#...#.....# +..#....#..#.........#..##...... +...#....#.#......#..#..#.#..... +#..#....#........#.#..##....### +#....#..##......##.##.....#.### +...#.#..........#..#.#.#.#.##.. +......##..#.#..#.#....#....#... +##....#....#..#..#.##......#... +....#.#..##.#.#...###....##.#.. +...#.......##..#.......#...#... +......##.......#..##.....#...#. +...#.#...#...........#...#..... +.#....#...#......##.##..###..#. +.#..........#...#...#...##.##.. +.....###..#.....#..##....#.#### +..#.###..#..##..##.....#.#..... +.............#.###...##.#.....# +....###.......###.#.....#..#.#. +........##.#.........#.....###. +.....###.#..#.....#...#..#..... +.#....#..##.#..#.#....#.......# +........#......#.#..#.#..#...## +...#.##.##......#.............. +.#.....##.#.....#..#......##... +#..#..#.....#.....#.....###.... +.##...........#..#.##.....#.... +..#.#......#.#...#.##.#..#...## +...#..........#.....#.......... +#.#.#.#.#...#....#...#.....##.. +#......##...#...#..........#.#. +....##........#.#.............. +#..#.#.#..#........##......#.## +........####...##.#.....#...... +....#........#.#..#..##..#.#... +.#.....#..###...#..#.....#..#.. +#......###.#..#....#..#.#...... +....#.....##.##..#...#.#..##.#. +..##..#...#.#......#....#...#.# +#..##...##..#...###...#..#..... +.......#.....#...........##.... +#..##....#........#....##..#.#. +.#........#..##...###.#..#..... +.#.#....#..##...#...##.#..###.. +#.........#.......#.....#.#.... +#..#.....#.#.###.#..#......#... +....#..#.#....#..##..###....### +###.##.#.#..#...........#.#.#.. +..##.#.......#......#..##....#. +.....#.#.#.......##.......#...# +...........#.##....##.##....#.# +...#.......#..#.##..#......#..# +#.#.#...#......##.#...........# +##........#...........###.#..#. +..........#.#.#....#.#..##.#.#. +...#.#.#....#..........#..#.... +#.#....###.#.#..#.......###...# +.#....#......#.#.#..#..#....... +......##.............#....#.#.# +.#..........#.........#.##..... +##....#....##....#..#.......#.. +#.##.##.#..#..#.....#..#.##.#.. +.#..#.......##..#.....##.##.... +.......#..........#.#.##..#.##. +....#.....#.#...##....##....... +.......#.........#...##....##.# +#.....#......#..........#...#.. +...#.#.......#.#..#....###..#.. +.....#.#.#.........#........... +.#..###.#.#........#.#......... +.........#..#......##...##....# +...###..#.....##.....#.###....# +.##...#...#........###.#..#.... +.##........#..#.###.######.##.# +##.#...#.#....#..##.#....##.... +.......##.....##.#..###.#...... +..##...##........#.......#....# +#..##...#.####...###......#...# +.##.....#.##.#.#.....###.#..##. +..###....#.#.###.#....#........ +....#..###..#...#....#..#..#.#. +#.#.##....##...##.......#...... +.........#...#....#..#......... +.............#...#..##.#....... +...#.##.......#...#.#..##.##... +.####.#.##..#.#......#.##...#.# +.#..#.#.....#.................# +..#.##..###....#...#......####. +..##..##...........#....#...#.. +....#...#...#...#.......#....#. +#.#...###...#...#.#...#....##.# +......#...#.#.......#.....#...# +....##...#.#.#....#....#.#....# +.....#.....#...##..#...#....##. +#.....#....#......##.##....#... +...#.#....#...#....#.#....##..# +...#.#..#...##....###..#....... +...##......###...###.#...#..#.. +##.......#.......###.......#..# +..##.##..###.#............#...# +#.....##..#..##....##..#....... +......#.#...#......#.....#..... +#...........#....#..##.##.#.... +.......#..#......#...#....#...# +.#...##...........#......#...#. +#........#....##...###.#....#.. +.....#.......##.........#.##... +.#.###..#....#..##.#..#.#..#... +#.......#.##.#.#....#.#..#....# +###.....#.#.......#..#......#.# +#..#.#.......#.#..##..##.#.#... +#..#.#.#.###........#.....#...# +#.#.#..#..##.....#...........#. +..#.#..#.....#...#...#...##.... +...#.##......#...##.#...#.#.#.# +#..#.#.#.#.......####.......... +..#......#.#......##.###.....## +..#...##..#.........##....#.##. +##.##.##.#.#.....#..........##. +.#.....###.#..#....#..#.###...# +#...##.......###....#.#..#..... +..#....##.........##.........## +......#....#.##.......#........ +..#.#.#..#...#...#...##.#...#.. +......#..##.#.#.#...##...#.#.## +#..#...##.#.....#...#.##....... +..#..#.........##.#...#.##...## +##.##.#....#.......#.##..#..... +.....##...##.##...##.........## +#......#...#.......#...#...#... +...##...........#...#..#....... +.#.##.#..#........#....#....... +#.#...#..#......##...#.#.##.... +##........####..#.#...#.#.##.## +#..#.#.##......##.#.#..#....... +.....#.........#..#.####....#.. +......##..#....#...#.#....#.... +#...##........#.........#.....# +.#.#...#.#.#..#............##.# +.#..#....#....#.....#...#.....# +..###...#..#.....#.##.###...#.# +.#.###..#..#...#.#...#.#......# +#...#####......###........##... +.....#.....#..#.#....#..##..... +....##...#.#.##.#####...#....#. +.#.#.........##.#.......#..##.. +.#...#.#...#...#....#.#...##.#. +.##...#..#.#..#......#.#.#..##. +..#.....#..#.....##.....#...... +..#........#..##...#.......###. +.#....#.......#....#....#..#... +....#......#.#.#.........#..... +..##...#.#.#...#.#........#.... +.#.....####...##.#..#...##..... +...#.....#...#...#....#....#... +.........#..#.#.....#..#.#..#.. +.........##...........#.......# +......#..#.....##...#.##.#..... +.#......##........##...#.#.##.. +.....#.#..##...........#..#..#. +...#.......#...#.#..#.##..#.##. +...#.......#.....#.#...#.##.#.. +#.....#.............##.#..####. +.#...#......#...##.#....#.#.... +.##..##.##....#.#.....#.......# +...#...#....#....##.#..#....##. +..............##....#.......#.# +.#.#.#...##..#..#...###.#..#... +.#.#...#.#..#.#..#...######..#. +........#......#.#..#.#....#... +..###.....###.#.##....#...##... +.##.#.....#.......##.......#... +..#..##...#..........#.#....#.# diff --git a/3-toboggan_trajectory/src/lib.rs b/3-toboggan_trajectory/src/lib.rs new file mode 100644 index 0000000..c36a494 --- /dev/null +++ b/3-toboggan_trajectory/src/lib.rs @@ -0,0 +1,133 @@ +use std::{fmt}; + +#[derive(Clone, Copy, PartialEq)] +pub enum Terrain { + Plain, + Tree, +} + +impl Default for Terrain { + fn default() -> Self { + Terrain::Plain + } +} + +impl fmt::Debug for Terrain { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{}", match self { + Terrain::Plain => '.', + Terrain::Tree => '#', + }) + } +} + +#[derive(Debug, Copy, Clone, PartialEq, Default)] +pub struct Vec2 { + pub x: i64, + pub y: i64, +} + +impl From<(i64, i64)> for Vec2 { + fn from((x,y): (i64, i64)) -> Self { + Self { x, y } + } +} + +#[derive(Clone)] +pub struct Map { + size: Vec2, + tiles: Vec +} + +impl fmt::Debug for Map { + fn fmt(&self,f: &mut fmt::Formatter) -> fmt::Result { + // A most honourable moment, but chaining debugs means lots of spare ""[] + //let dd: Vec = self.tiles.chunks_exact(self.size.x as usize).map(|x| format!("{:?}", x)).collect(); + for line in self.tiles.chunks_exact(self.size.x as usize) { + let line_s: String = line.iter().map(|x| format!("{:?}", x)).collect(); + writeln!(f, "{}", line_s)? + } + // let banana = self.tiles + // .chunks_exact(self.size.x as usize) + // .map(|x| format!("{:?}", x)) + // .collect::>() + // .join("\n"); + // writeln!(f, "{}", banana) + Ok(()) + } +} + +impl Map { + pub fn new(size: Vec2) -> Self { + Self { + size, + tiles: vec![Default::default();(size.x*size.y) as usize] + } + } + + pub fn get(&self, pos: Vec2) -> Terrain { + self.tiles[self.idx(pos).unwrap_or_default()] + } + + pub fn set(&mut self, pos: Vec2, tile: Terrain) { + if let Some(idx) = self.idx(pos) { + self.tiles[idx] = tile; + } + } + + fn wrap_coords(&self, pos: Vec2) -> Option { + if !(0..=self.size.y).contains(&pos.y) { + None + } else { + Some(Vec2{ + x: pos.x % self.size.x, + y: pos.y}) + } + } + + fn idx(&self, pos: Vec2) -> Option { + self.wrap_coords(pos).map(|pos| (pos.x + pos.y * self.size.x) as usize) + } + + pub fn from_bytes(s: &[u8]) -> Self { + let rows = s.iter().filter(|&&x| x == b'\n').count(); + let cols = (s.len() - rows) / rows; + println!("Size : {} {}", rows, cols); + let mut res = Self::new((cols as i64,rows as i64).into()); + + let mut pos = Vec2 { x: 0, y: 0 }; + for tile in s { + match tile { + b'\n' => { + pos.y += 1; + pos.x = 0; + } + b'#' => { + res.set(pos, Terrain::Tree); + pos.x += 1; + } + _ => { + res.set(pos, Terrain::Plain); + pos.x += 1; + } + } + } + res + } + + pub fn solve(&self, slope: (i64, i64)) -> i64 { + let mut seek_pos = Vec2 { x: 0, y: 0}; + let mut tree_count = 0; + loop { + if self.get(seek_pos) == Terrain::Tree { + tree_count += 1; + } + if seek_pos.y + slope.1 >= self.size.y { + break; + } + seek_pos.y += slope.1; + seek_pos.x += slope.0; + } + tree_count + } +} \ No newline at end of file diff --git a/3-toboggan_trajectory/src/main.rs b/3-toboggan_trajectory/src/main.rs new file mode 100644 index 0000000..ddad4b3 --- /dev/null +++ b/3-toboggan_trajectory/src/main.rs @@ -0,0 +1,17 @@ +use toboggan_trajectory::*; + +fn main() { + let map_str = include_str!("../data/input.txt"); + // println!("{}", map_str); + let map: Map = Map::from_bytes(map_str.as_bytes()); + // println!("{:#?}", map); + eprintln!("First part solution = {}", map.solve((3,1))); + let sols: i64 = vec![ + (1, 1), + (3, 1), + (5, 1), + (7, 1), + (1, 2), + ].iter().map(|slope| map.solve(*slope)).product(); + println!("Second part solution = {}", sols); +} \ No newline at end of file diff --git a/3-toboggan_trajectory/src/tests.rs b/3-toboggan_trajectory/src/tests.rs new file mode 100644 index 0000000..7b38d93 --- /dev/null +++ b/3-toboggan_trajectory/src/tests.rs @@ -0,0 +1,54 @@ +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_vec2_from_tuple() { + // let v: Vec2 = (32, 75).into(); + let v = Vec2::from((32, 75)); + assert_eq!(v, Vec2 {x: 32, y: 75}) + } + #[test] + fn test_format_map() { + let m = Map{ + size: Vec2{x: 2, y:2}, + tiles: vec!(Terrain::Tree, Terrain::Plain, Terrain::Plain, Terrain::Plain) + }; + assert_eq!(format!("{:?}", m), "#.\n..\n") + } + + #[test] + fn test_normalize_pos() { + let m = Map::new((2, 2).into()); + assert_eq!(m.normalize_pos((0, 0).into()), Some((0, 0).into())); + assert_eq!(m.normalize_pos((1, 0).into()), Some((1, 0).into())); + assert_eq!(m.normalize_pos((2, 0).into()), Some((0, 0).into())); + assert_eq!(m.normalize_pos((-1, 0).into()), Some((1, 0).into())); + assert_eq!(m.normalize_pos((-2, 0).into()), Some((0, 0).into())); + assert_eq!(m.normalize_pos((0, -1).into()), None); + assert_eq!(m.normalize_pos((0, 2).into()), None); + } + + #[test] + fn test_index() { + let m = Map::new((3, 5).into()); + assert_eq!(m.index((0, 0).into()), Some(0)); + assert_eq!(m.index((2, 0).into()), Some(2)); + assert_eq!(m.index((0, 1).into()), Some(3)); + assert_eq!(m.index((2, 1).into()), Some(5)); + } + + #[test] + fn test_create_map() { + let mut map = Map::new(Vec2{x:5,y:5}); + let trees: Vec = vec![ + (1,2).into(), + (2,1).into(), + (3,3).into(), + (1,4).into(), + (5,1).into(), + ]; + trees.iter().for_each(|pos| map.set(*pos, Terrain::Tree)); + println!("{:?}", map) + } +} \ No newline at end of file diff --git a/4-passport_processing/.gitignore b/4-passport_processing/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/4-passport_processing/.gitignore @@ -0,0 +1 @@ +/target diff --git a/4-passport_processing/Cargo.lock b/4-passport_processing/Cargo.lock new file mode 100644 index 0000000..a048670 --- /dev/null +++ b/4-passport_processing/Cargo.lock @@ -0,0 +1,119 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "aho-corasick" +version = "0.7.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5" +dependencies = [ + "memchr", +] + +[[package]] +name = "anyhow" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68803225a7b13e47191bab76f2687382b60d259e8cf37f6e1893658b84bb9479" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "memchr" +version = "2.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" + +[[package]] +name = "passport_processing" +version = "0.1.0" +dependencies = [ + "anyhow", + "regex", + "thiserror", +] + +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", + "thread_local", +] + +[[package]] +name = "regex-syntax" +version = "0.6.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" + +[[package]] +name = "syn" +version = "1.0.54" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thiserror" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "thread_local" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" diff --git a/4-passport_processing/Cargo.toml b/4-passport_processing/Cargo.toml new file mode 100644 index 0000000..7878faa --- /dev/null +++ b/4-passport_processing/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "passport_processing" +version = "0.1.0" +authors = ["Guilhem MARION "] +edition = "2018" + +[dependencies] +anyhow = "1.0.36" +regex = "1.4.2" +thiserror = "1.0.22" diff --git a/4-passport_processing/data/input.txt b/4-passport_processing/data/input.txt new file mode 100644 index 0000000..0e247b0 --- /dev/null +++ b/4-passport_processing/data/input.txt @@ -0,0 +1,953 @@ +ecl:amb +pid:690616023 +byr:1994 iyr:2014 hgt:172cm hcl:#c0946f eyr:2022 + +eyr:1980 cid:97 +hcl:z ecl:#102145 iyr:2011 byr:1945 +pid:187cm hgt:179in + +ecl:amb +iyr:2011 +cid:113 +eyr:2021 hcl:#b6652a pid:004682943 byr:1940 +hgt:173cm + +iyr:2023 +cid:146 byr:2022 ecl:dne hgt:76in eyr:2040 hcl:z + +hcl:#f97e30 +cid:73 iyr:2013 byr:1929 hgt:157cm +eyr:2024 ecl:blu pid:673398662 + +hcl:5343fe +hgt:152 byr:2018 +eyr:1992 pid:85999926 iyr:1938 ecl:#15bd97 + +byr:1975 hcl:z eyr:1988 pid:#c36f52 +iyr:2018 +hgt:184cm + +byr:1954 eyr:2023 hgt:170cm iyr:2012 ecl:blu pid:299556897 hcl:#b6652a + +hgt:191cm ecl:oth hcl:#7d3b0c +iyr:2016 pid:187567535 +byr:1999 eyr:2023 + +pid:814358147 eyr:2022 iyr:2000 byr:2001 hcl:#18171d +ecl:blu +hgt:76in + +ecl:hzl +hgt:163cm byr:1955 iyr:2018 eyr:2024 hcl:#6b5442 pid:343362099 + +eyr:2020 pid:185090160 ecl:#21a5e6 +iyr:1928 byr:2006 hcl:a2ebbf hgt:104 + +hgt:153cm +hcl:#a97842 ecl:blu eyr:2028 byr:1969 iyr:2019 +pid:729700590 + +iyr:2019 byr:1981 hgt:150cm pid:606092356 hcl:#18171d eyr:2026 +ecl:grn + +pid:760899887 +eyr:2023 hcl:#866857 hgt:185cm iyr:2017 +byr:1976 ecl:gry + +byr:1965 eyr:2026 +hcl:#623a2f +ecl:blu pid:483363116 iyr:2010 hgt:178cm cid:204 + +ecl:oth eyr:2022 +pid:268557763 byr:1965 iyr:2015 hcl:#c0946f hgt:164cm + +ecl:gry hgt:168cm hcl:#623a2f eyr:2020 cid:163 pid:124082663 iyr:2016 byr:1996 + +hcl:4c44fb iyr:1957 eyr:2039 ecl:grt hgt:63cm byr:2012 cid:104 + +byr:2024 iyr:2023 +ecl:gry +eyr:2007 pid:170cm hgt:68 hcl:d57b67 cid:333 + +byr:1956 +hgt:169cm iyr:2013 pid:370491367 +ecl:gry hcl:#5bc41d + +eyr:2023 iyr:2028 byr:1969 ecl:lzr hcl:1989b1 hgt:71cm pid:#12c226 + +cid:304 pid:866132461 +byr:2022 +hcl:z hgt:191in ecl:lzr iyr:2029 eyr:1989 + +ecl:brn hcl:#9a45a7 +hgt:176cm +byr:1974 pid:758747330 iyr:2014 eyr:2020 + +cid:190 ecl:hzl iyr:2014 byr:1990 hgt:69in eyr:2037 pid:384015829 hcl:#ceb3a1 + +byr:1998 eyr:2022 iyr:2018 hgt:153cm +hcl:#733820 pid:424512443 +ecl:blu + +hcl:27c41f byr:1972 eyr:1994 pid:777840405 +ecl:gry +hgt:179cm +iyr:2021 + +hgt:166cm eyr:2032 ecl:gry byr:1936 +pid:41703652 + +hcl:#efcc98 iyr:2019 byr:1936 pid:985830958 eyr:2021 +hgt:175cm ecl:brn + +eyr:2025 pid:972163513 hgt:155cm ecl:brn cid:169 iyr:2015 +hcl:#6b5442 + +eyr:2026 +hgt:173cm +byr:1984 +cid:191 +pid:791209101 hcl:#341e13 iyr:2020 ecl:hzl + +hgt:64cm +iyr:2010 byr:1978 +pid:618891746 hcl:#d6ac23 eyr:2023 ecl:brn + +eyr:2021 hcl:#341e13 iyr:2018 pid:502081929 +ecl:blu + +ecl:amb +iyr:2018 pid:8933462515 +hgt:160cm hcl:e330f0 eyr:2030 byr:2007 + +ecl:gry byr:1980 hcl:#341e13 iyr:2015 pid:830724822 hgt:167cm cid:156 +eyr:2023 + +ecl:gry hcl:#c39b75 byr:1995 hgt:153cm +eyr:2029 pid:83056475 iyr:2013 + +byr:1965 cid:250 +ecl:oth iyr:2016 +pid:242792947 eyr:2025 hcl:#efcc98 + +byr:2011 ecl:#62fe2d hcl:#2b434a hgt:190cm +eyr:2031 iyr:1964 pid:7096872943 + +cid:258 hcl:#c0946f pid:698224453 eyr:2029 hgt:189cm iyr:2012 ecl:blu byr:1963 + +eyr:2028 byr:1942 hgt:156cm pid:836243052 iyr:2016 +hcl:#888785 cid:310 ecl:brn + +hcl:#a97842 pid:740164307 ecl:oth byr:1997 +hgt:166cm +iyr:2015 eyr:2026 + +hcl:4ee9da iyr:2020 +eyr:1933 hgt:136 ecl:#8dee29 pid:44266010 byr:1966 cid:82 + +ecl:amb byr:1921 hgt:182cm eyr:2026 +hcl:#c0946f iyr:2010 + +hgt:178cm cid:343 eyr:2023 pid:197119382 hcl:#623a2f iyr:2017 +ecl:brn byr:2002 + +eyr:2030 byr:1967 ecl:blu hgt:166cm iyr:2017 +pid:655602762 hcl:#6b5442 + +cid:143 hgt:152cm eyr:2026 iyr:2018 byr:1950 ecl:grn hcl:#866857 pid:067535973 + +byr:2019 ecl:#e3c288 iyr:1948 hgt:72cm hcl:7da71b eyr:1956 + +hcl:#cfa07d +pid:688405238 cid:200 byr:1950 +iyr:2020 ecl:hzl hgt:170cm + +eyr:2026 hgt:164cm iyr:2010 hcl:#b6652a pid:404835595 byr:1924 ecl:blu + +iyr:2016 hcl:#866857 +ecl:gry +eyr:2023 pid:986813245 cid:247 byr:1977 +hgt:173cm + +ecl:#a59335 eyr:2023 +hcl:033f22 byr:1947 hgt:152 +iyr:2029 pid:#1e686a cid:305 + +byr:2005 +ecl:amb hcl:#a97842 +iyr:1972 +eyr:1967 pid:274884869 + +eyr:2038 iyr:2018 +pid:181cm ecl:xry hgt:185in +hcl:109b28 cid:287 + +ecl:amb byr:1943 pid:002483342 hgt:178cm +hcl:#c0946f eyr:2030 +iyr:2014 + +iyr:2020 byr:1963 cid:131 hcl:#18171d hgt:181cm pid:146726616 eyr:2021 + +pid:062629370 byr:1931 hgt:188cm eyr:2021 ecl:gry +hcl:#166b3d + +pid:007028786 ecl:blu hgt:156cm byr:1981 hcl:#888785 cid:53 iyr:2019 + +iyr:2014 hcl:#623a2f +ecl:hzl eyr:2029 byr:1988 +pid:849096536 hgt:167cm cid:322 + +pid:160824363 +hcl:#19bed3 +eyr:2024 hgt:171cm +byr:1968 iyr:2019 + +eyr:2024 hcl:#dd66d0 +byr:1986 +cid:105 pid:816153574 ecl:hzl iyr:2013 +hgt:173cm + +hcl:#ceb3a1 hgt:62in ecl:gry +iyr:2017 cid:234 byr:1963 +eyr:2029 +pid:514406488 + +hcl:#fffffd ecl:blu +eyr:2020 iyr:2010 +pid:544347103 hgt:164cm byr:1939 + +eyr:2021 +pid:999479324 hgt:164in ecl:brn iyr:2016 +hcl:#a97842 byr:2020 + +pid:053149570 byr:1920 eyr:2027 hgt:190cm iyr:2011 hcl:#fffffd ecl:oth + +hgt:165cm +hcl:#cfa07d +ecl:oth +eyr:2023 +pid:186cm +byr:1937 iyr:2012 + +eyr:2026 hgt:64cm hcl:#ac426a byr:1969 +cid:345 iyr:1960 +pid:#df648a ecl:blu + +byr:1923 iyr:2017 +eyr:2027 pid:798497862 hgt:182cm +hcl:#ceb3a1 ecl:oth + +hgt:182cm eyr:1990 ecl:grn hcl:#efcc98 byr:1968 +pid:005962011 +iyr:2010 + +cid:74 eyr:2020 hgt:71in +iyr:2015 pid:487940408 byr:1952 +hcl:#733820 + +hgt:75cm cid:249 +ecl:hzl +hcl:#6b5442 pid:4860441 eyr:2020 + +ecl:hzl eyr:2025 hgt:183cm +iyr:2020 byr:1993 pid:572766871 hcl:#866857 + +hcl:#888785 pid:200125941 hgt:155cm byr:1923 +eyr:2021 iyr:2010 ecl:gry + +pid:502547835 iyr:2014 hcl:#b6652a +byr:1985 hgt:189cm eyr:2024 + +eyr:2024 hcl:#fffffd ecl:amb byr:1952 +pid:724639818 +iyr:2013 hgt:183cm + +byr:2023 +iyr:2026 ecl:gry eyr:2032 hcl:3e0fc4 pid:5620497552 +hgt:84 + +cid:79 +hgt:68cm +iyr:2021 +pid:#365b83 byr:1928 +ecl:#79a6b3 eyr:2027 hcl:54130e + +hgt:74cm byr:1953 +cid:263 iyr:2018 +ecl:zzz +hcl:#efcc98 +pid:154cm eyr:1951 + +cid:272 pid:0638528559 hcl:z hgt:63cm byr:2029 ecl:zzz +eyr:2033 + +iyr:2016 +hgt:193cm hcl:#6b5442 pid:715518898 ecl:brn cid:195 +eyr:2025 + +ecl:oth +eyr:2025 hgt:166cm byr:1944 +iyr:2017 pid:814141652 + +eyr:2025 cid:140 ecl:hzl hcl:#c0946f pid:824866056 iyr:2011 hgt:65in byr:1947 + +iyr:2016 +ecl:brn eyr:2021 +hgt:161cm +byr:1984 hcl:#602927 pid:821539320 + +hgt:175cm cid:190 hcl:#ceb3a1 ecl:brn byr:1927 iyr:2017 eyr:2029 pid:836598854 + +eyr:2026 ecl:brn hgt:157cm pid:038645205 byr:1995 +iyr:2019 cid:339 + +ecl:brn hgt:70in hcl:#c0946f +pid:535498918 cid:153 +iyr:2012 eyr:2030 + +byr:1995 +hcl:#efcc98 hgt:174cm eyr:2030 pid:180839761 +ecl:grn iyr:2010 + +hgt:59cm eyr:2035 byr:2021 iyr:2012 ecl:hzl pid:219328725 hcl:#888785 + +ecl:oth hgt:184cm byr:1984 iyr:2016 +hcl:#cfa07d + +iyr:1998 byr:2024 ecl:lzr hgt:187 hcl:z eyr:1935 pid:#789b56 + +iyr:1967 hcl:z pid:828930046 hgt:59in +cid:153 +byr:2021 +ecl:grn +eyr:1935 + +byr:1991 +hcl:#341e13 ecl:gry iyr:2018 +hgt:67in pid:157970631 eyr:2021 + +byr:1941 hgt:169cm pid:322510952 hcl:#cfa07d cid:75 ecl:oth +eyr:2021 iyr:2020 + +hcl:#7d3b0c iyr:2013 cid:78 hgt:167cm ecl:brn byr:1974 pid:237404828 + +pid:1567157833 +hcl:#7d3b0c iyr:2025 eyr:2023 +byr:2002 ecl:oth hgt:191cm + +ecl:amb iyr:2014 hgt:182cm pid:526612838 +cid:287 eyr:2025 byr:1988 +hcl:#866857 + +hcl:#866857 hgt:174cm byr:1992 eyr:2028 iyr:2015 + +eyr:2029 +hgt:190cm +hcl:#18171d +cid:245 +ecl:oth pid:3636033742 byr:2024 +iyr:2019 + +byr:1972 hgt:163cm eyr:2020 hcl:#b6652a +pid:360516396 iyr:2019 ecl:grn + +iyr:1997 ecl:#be02d2 +eyr:2020 cid:259 byr:1953 +hcl:#6b5442 +hgt:177cm pid:978155362 + +pid:377596476 cid:153 +eyr:2025 byr:2000 hgt:181cm iyr:2014 hcl:#abc5cb ecl:hzl + +cid:171 ecl:lzr iyr:2013 eyr:1973 byr:2004 +pid:#267099 hgt:101 + +hcl:#623a2f +pid:029193661 +hgt:183cm +ecl:hzl eyr:2029 iyr:2013 +byr:1977 + +ecl:amb eyr:2021 hgt:159cm byr:1970 cid:152 +hcl:#b6652a iyr:2020 pid:180512119 + +eyr:2025 +ecl:grn +hgt:60in iyr:2013 pid:697352361 +hcl:#18171d byr:1989 + +byr:1934 hgt:165cm pid:703537570 ecl:hzl iyr:2015 +hcl:#888785 + +ecl:gmt +hcl:6dd6a5 +byr:1951 +pid:#7ab761 cid:304 iyr:1924 eyr:1953 hgt:71in + +ecl:amb hcl:#733820 eyr:2030 hgt:178cm +pid:692422832 iyr:2019 +cid:276 + +iyr:2012 ecl:oth +pid:674969358 +eyr:2027 hgt:157cm cid:247 hcl:#a97842 + +byr:2017 eyr:2031 hgt:180cm hcl:#ceb3a1 pid:372071110 +iyr:2015 ecl:amb + +hgt:165cm iyr:2015 +eyr:2021 ecl:amb byr:2000 cid:235 + +eyr:2027 hcl:#623a2f pid:595874068 +ecl:amb +hgt:177cm iyr:2019 byr:1929 + +pid:8150929412 hgt:191in eyr:2031 cid:233 byr:2027 +iyr:2026 ecl:#e94348 hcl:z + +hgt:65 byr:2009 iyr:2029 hcl:#fffffd eyr:1950 pid:950012410 cid:212 ecl:#5a6042 + +ecl:#44c561 hgt:178cm eyr:2021 pid:753771724 +iyr:2014 +hcl:#70adb2 byr:1989 + +iyr:2018 pid:809109448 ecl:amb hcl:#b6652a hgt:63in byr:1976 cid:96 + +byr:2021 ecl:grn pid:9284377919 iyr:2011 hgt:75cm hcl:#18171d eyr:2026 + +ecl:oth +byr:1926 +hgt:63 iyr:1948 cid:61 hcl:a528d1 eyr:2034 + +byr:1978 pid:150503169 iyr:2015 ecl:grn hgt:172cm cid:70 eyr:2022 hcl:#7d3b0c + +byr:1957 hcl:#cfa07d iyr:2010 ecl:amb eyr:2025 pid:921901279 + +ecl:utc pid:154cm +byr:1964 eyr:1978 hgt:114 hcl:z + +byr:1929 ecl:amb eyr:2028 iyr:2013 +hcl:#fffffd pid:479814281 +cid:105 hgt:64in + +pid:949640425 +cid:205 hcl:#341e13 ecl:amb +hgt:171cm byr:1998 + +hgt:190cm cid:113 ecl:grn eyr:2037 +hcl:#ceb3a1 pid:7994792779 iyr:2011 + +hgt:152cm iyr:2010 +byr:1992 eyr:2020 +hcl:#602927 +cid:66 +pid:604149642 + +eyr:2028 +byr:1961 hgt:71in +iyr:2013 cid:135 +pid:534090716 hcl:#ceb3a1 ecl:oth + +iyr:1937 byr:1995 cid:200 +eyr:2037 pid:#daf9af +hcl:052017 ecl:zzz hgt:73cm + +ecl:amb +hcl:#a97842 +iyr:2018 +hgt:153cm +cid:149 eyr:2023 pid:533403632 + +cid:275 ecl:brn iyr:2017 pid:087665205 byr:1945 hcl:#7d3b0c +eyr:2025 + +eyr:2030 hgt:177cm hcl:#cfa07d iyr:2018 pid:734113761 +byr:1965 + +hgt:163cm byr:1924 ecl:blu cid:125 +eyr:2027 hcl:#fffffd pid:137238888 + +hgt:174cm hcl:#623a2f eyr:2023 ecl:gry pid:585758460 +iyr:2011 + +cid:183 +byr:1928 pid:471385060 +hgt:192cm +ecl:oth iyr:2010 hcl:#623a2f eyr:2020 + +hgt:177cm +cid:273 ecl:oth eyr:2020 +hcl:#efcc98 +iyr:2012 pid:246299733 +byr:1954 + +pid:052203766 cid:146 ecl:hzl byr:1974 hcl:#6b5442 +eyr:2030 hgt:173cm +iyr:2011 + +hgt:167cm +byr:1972 iyr:2010 +pid:783359411 ecl:hzl hcl:#9f8cc9 eyr:2028 + +iyr:2020 hcl:#18171d ecl:grn +byr:1992 +hgt:189cm +eyr:2023 pid:736882272 + +cid:230 ecl:utc iyr:2022 +pid:170cm +byr:2015 hcl:#c0946f +eyr:2031 + +cid:261 +byr:1922 hgt:170cm ecl:brn eyr:2021 +pid:593276915 hcl:#18171d +iyr:2017 + +hcl:#341e13 pid:038417039 hgt:61in eyr:2025 iyr:2017 +cid:117 + +iyr:2017 eyr:2026 pid:441484223 +hgt:155cm byr:1968 hcl:#ceb3a1 ecl:hzl + +eyr:2021 +hgt:64in +ecl:oth hcl:#b6652a byr:1954 pid:204959612 iyr:2016 + +hcl:z eyr:1969 +pid:162cm ecl:#944b0f +iyr:2030 byr:2029 + +hgt:114 eyr:2034 byr:2026 hcl:84fa1a +pid:47909473 +iyr:2028 +ecl:utc + +eyr:2025 ecl:blu hgt:157cm iyr:2014 hcl:#a97842 byr:1974 pid:702610675 cid:241 + +pid:732388109 +hcl:#6b5442 cid:272 eyr:2026 hgt:193cm +ecl:amb byr:1982 + +eyr:2030 byr:1994 +hgt:177in ecl:amb pid:1589147420 iyr:2011 hcl:#4bf920 +cid:252 + +ecl:oth eyr:2022 +byr:1948 +pid:177cm cid:90 hgt:102 hcl:z iyr:2028 + +hgt:157cm pid:233347213 +hcl:z +byr:2009 eyr:2027 cid:235 ecl:blu +iyr:1965 + +ecl:blu iyr:2030 eyr:2028 hcl:#18171d pid:322593908 byr:1954 +cid:215 hgt:63in + +hgt:72cm +cid:345 pid:911728732 eyr:2025 +byr:2004 ecl:#0c4af7 hcl:3bb675 + +pid:171714794 byr:2019 +hcl:#866857 +cid:290 hgt:183in ecl:#d0c30f eyr:2032 + +iyr:2016 pid:905945155 hcl:#ceb3a1 byr:1958 hgt:159cm eyr:2028 cid:180 ecl:oth + +hcl:efb614 +eyr:2022 hgt:177cm pid:46962273 +byr:1974 +ecl:#089bdd iyr:1988 + +pid:662993164 iyr:2011 eyr:2025 ecl:hzl +byr:1942 hcl:#fffffd +hgt:175cm + +hcl:#7d3b0c iyr:2016 hgt:175cm eyr:2022 pid:953132241 +byr:1963 cid:261 ecl:grn + +iyr:2013 hgt:180cm cid:318 +ecl:amb +byr:1985 pid:439097817 eyr:2029 hcl:#602927 + +hgt:162cm ecl:blu +pid:675749832 cid:73 +byr:1940 hcl:#888785 +eyr:2026 + +pid:275352007 iyr:2012 eyr:2020 +ecl:amb hcl:#623a2f hgt:175cm cid:317 byr:1988 + +hcl:z hgt:164in +iyr:2026 eyr:1961 ecl:#2df35e pid:#5c9ed5 cid:341 + +pid:848086119 ecl:oth eyr:2021 iyr:2011 hgt:180cm byr:1923 hcl:#93461b + +eyr:2028 +iyr:2014 +byr:1978 +hgt:184cm +pid:966277564 ecl:hzl +cid:176 + +hcl:#888785 ecl:amb cid:329 pid:835961958 byr:1927 eyr:2028 iyr:2016 + +pid:160cm eyr:2026 hcl:#08714b +ecl:hzl iyr:1961 +hgt:156cm byr:1984 + +ecl:gry cid:302 +byr:1965 +iyr:2019 hcl:#ceb3a1 eyr:2027 pid:458192010 hgt:156cm + +pid:058273969 byr:1942 eyr:2027 +hcl:#c0946f iyr:2013 hgt:179cm + +iyr:2019 hgt:193in pid:52144528 eyr:2036 +cid:169 ecl:grt hcl:7e7039 + +hgt:192cm ecl:blu iyr:2015 pid:544936486 eyr:2024 +byr:1972 hcl:#c0946f + +eyr:2000 +hcl:78de23 byr:2020 +hgt:171in pid:160cm cid:68 +iyr:1956 ecl:gmt + +hcl:#733820 ecl:grn iyr:2018 +byr:2001 pid:770957230 + +cid:103 ecl:grn iyr:2018 +pid:068344094 +eyr:2023 hgt:69in byr:1984 hcl:#6b5442 + +hgt:193cm eyr:2021 ecl:grn hcl:#602927 byr:1938 iyr:2011 + +iyr:1931 +hcl:c0a318 +pid:99195939 +byr:2028 ecl:grt hgt:164 eyr:2017 + +eyr:1980 +ecl:zzz +hgt:98 cid:161 +pid:#96fe01 hcl:z +iyr:1974 + +byr:1936 hgt:176cm pid:56797167 iyr:2015 +ecl:#07ad47 +hcl:z + +pid:48720181 hcl:270e76 +byr:2022 +hgt:180cm ecl:#dde399 +eyr:2035 iyr:2023 + +eyr:2030 byr:2022 iyr:2018 hgt:162in ecl:gry +hcl:#63e2ec pid:615812600 + +ecl:grn +cid:56 hcl:#623a2f eyr:2020 hgt:167cm byr:1971 iyr:2012 +pid:262692066 + +hgt:61 hcl:#efcc98 iyr:2011 eyr:2026 +byr:1938 +ecl:amb pid:385025739 + +pid:972423724 hcl:#602927 eyr:2027 ecl:oth iyr:2015 +hgt:158cm byr:1956 + +pid:530035096 +ecl:hzl +iyr:2017 +eyr:2024 hcl:#888785 byr:1962 hgt:64in + +byr:1935 eyr:2022 ecl:grn hcl:#7d3b0c pid:294714199 + +eyr:2029 +iyr:2013 +byr:1927 hgt:175cm pid:058261075 hcl:#cfa07d ecl:amb + +ecl:blu pid:188764763 hgt:155cm byr:1921 +iyr:2018 eyr:2029 hcl:#b6652a + +byr:1975 hcl:930e76 iyr:2019 +pid:169cm eyr:2009 hgt:191 +ecl:#d28c56 + +hcl:z +pid:3190617557 +hgt:160cm cid:80 ecl:oth iyr:2022 eyr:2008 +byr:2016 + +hcl:#888785 byr:1999 ecl:blu cid:238 iyr:2018 hgt:160cm +eyr:2028 pid:174517111 + +eyr:2035 +hcl:z byr:2020 +pid:262135957 cid:324 iyr:2016 hgt:161cm ecl:grn + +byr:1936 +ecl:grn +iyr:2013 hcl:#623a2f eyr:2029 hgt:166cm + +hcl:#cfa07d hgt:159cm eyr:2021 +ecl:hzl +iyr:2014 pid:816039817 byr:1935 + +pid:596634790 hgt:161cm +eyr:2036 iyr:2016 +hcl:#7d3b0c byr:2015 ecl:brn + +byr:1952 +hgt:157cm eyr:2024 cid:60 pid:876160626 +ecl:blu iyr:2011 hcl:z + +hgt:193cm iyr:2020 eyr:2026 +pid:0136642346 ecl:hzl hcl:#efcc98 byr:1995 + +byr:1934 hgt:177cm +pid:445993865 +ecl:brn iyr:2018 +eyr:2030 +hcl:#733820 + +eyr:2021 hgt:71in +pid:918630878 +hcl:#602927 iyr:2017 byr:1943 +ecl:gry + +ecl:#81de2c iyr:2021 hgt:176cm eyr:1947 hcl:#888785 pid:1370052400 + +ecl:amb +byr:1922 iyr:2012 eyr:2022 pid:098866466 hcl:#18171d hgt:63in + +eyr:2028 iyr:2010 hcl:184355 +byr:1968 pid:337089458 ecl:brn hgt:181cm + +hcl:#733820 pid:225958483 ecl:gry eyr:2030 hgt:62in iyr:2012 byr:1987 + +eyr:1955 +hcl:03199c +pid:#3e832e +byr:2014 ecl:#453931 hgt:70cm + +byr:1975 +ecl:blu hcl:#7d3b0c +cid:169 pid:582470437 hgt:151cm +iyr:2019 eyr:2027 + +iyr:2017 byr:1971 pid:343492418 hgt:150cm hcl:#fffffd eyr:2024 + +byr:1997 +eyr:2026 +cid:257 hcl:#7d3b0c ecl:blu hgt:166cm iyr:2016 pid:117625518 + +iyr:2014 cid:248 hgt:165cm hcl:#18171d pid:294270262 +byr:1925 ecl:amb +eyr:2028 + +hgt:167in ecl:dne pid:174cm iyr:2019 byr:2005 hcl:b29331 cid:86 + +hcl:#733820 pid:259969636 eyr:2023 +ecl:hzl cid:317 +hgt:185cm byr:2025 +iyr:2012 + +hcl:#cfa07d hgt:152cm pid:807755992 iyr:2020 +byr:1922 ecl:grn eyr:2025 cid:241 + +pid:997807107 byr:1958 ecl:dne iyr:2013 eyr:2023 hcl:#18171d +hgt:152cm + +ecl:blu hgt:170cm +byr:1932 +pid:775223495 eyr:2024 iyr:2015 + +iyr:2011 +ecl:grn hcl:#ceb3a1 pid:190577415 +hgt:63in +eyr:2021 +byr:1986 + +ecl:oth eyr:2025 hgt:180cm +pid:258195402 iyr:2017 +byr:1961 +cid:109 hcl:#888785 + +hgt:178cm byr:1952 eyr:2023 hcl:#733820 +pid:106939563 ecl:brn iyr:2012 + +hgt:188cm iyr:2012 hcl:#fffffd byr:1942 +ecl:brn pid:804371742 + +byr:1978 cid:120 +eyr:2026 pid:405714523 hgt:60in +hcl:#a97842 ecl:blu +iyr:2017 + +iyr:2015 byr:1958 ecl:grn +hcl:#b6652a pid:#9e8af3 +eyr:2026 hgt:167cm + +hgt:171cm hcl:#888785 +cid:274 +ecl:grn pid:919263460 eyr:2023 iyr:2020 + +pid:606726472 eyr:2022 +byr:2008 +ecl:zzz cid:72 hgt:173in + +eyr:2032 byr:2004 +hcl:z iyr:2011 ecl:hzl +pid:523494728 +hgt:70cm + +hgt:169cm pid:755822781 byr:1984 ecl:hzl hcl:#6b5442 iyr:2014 + +eyr:2020 +byr:1942 cid:85 +hgt:157cm pid:558287447 hcl:#efcc98 +ecl:hzl + +byr:1980 cid:225 pid:367501996 iyr:2016 ecl:grn hcl:#efcc98 +hgt:175cm eyr:2029 + +pid:264780775 hgt:182cm ecl:grn +hcl:#18171d +eyr:2024 +byr:1926 iyr:2013 + +byr:1969 iyr:2015 +eyr:2026 ecl:blu +hcl:#fffffd +pid:005695878 cid:273 + +ecl:brn byr:2006 hgt:152cm +hcl:#888785 +pid:171cm cid:249 iyr:2026 +eyr:2022 + +byr:2011 iyr:2020 ecl:zzz hcl:z pid:412624100 +eyr:2031 + +cid:111 hcl:df9bd0 +iyr:2022 ecl:#32fdf9 +byr:2017 eyr:2000 +hgt:166in pid:0654651026 + +eyr:2021 +ecl:gry pid:587324819 hgt:187cm byr:1951 hcl:#6b5442 + +iyr:2011 +pid:180780096 hcl:#623a2f ecl:amb hgt:160cm byr:1991 eyr:2026 + +byr:2022 hgt:152cm eyr:2023 cid:70 ecl:grn +hcl:e0a24e +iyr:1959 pid:77110462 + +pid:251982311 byr:1994 ecl:gry hgt:165cm eyr:2021 +hcl:#623a2f +iyr:2019 + +ecl:blu byr:1945 +cid:241 +pid:732768808 hcl:#efcc98 +hgt:171cm eyr:2020 iyr:2012 + +cid:243 eyr:2001 +hcl:01a022 +hgt:162 pid:507703455 +byr:2003 ecl:#c6a07b +iyr:1941 + +hcl:#733820 cid:150 +ecl:hzl pid:843607639 hgt:190cm +byr:1958 +eyr:2025 + +eyr:2030 +pid:489370607 iyr:2014 ecl:oth hcl:#cfa07d byr:1995 hgt:193cm + +hgt:68in +byr:1933 +iyr:2010 ecl:brn +pid:380075958 +hcl:#623a2f cid:279 +eyr:2025 + +iyr:2019 +byr:2001 +hcl:#cfa07d ecl:brn pid:349877352 +hgt:161cm eyr:2029 + +hgt:171cm +eyr:2040 ecl:dne hcl:#6b5442 iyr:2020 byr:1990 + +hcl:#fffffd +hgt:154cm +byr:1979 eyr:2020 iyr:2018 +pid:118713281 cid:174 + +hcl:#7d3b0c eyr:2030 ecl:brn iyr:2017 +cid:184 hgt:180cm pid:504181498 byr:1925 + +hgt:150cm +eyr:2020 byr:1999 hcl:#a97842 iyr:2011 ecl:grn pid:620166468 + +hcl:#602927 +iyr:2015 +byr:1928 +pid:083747352 +eyr:2027 hgt:193cm +ecl:hzl + +byr:1938 ecl:gry +pid:511669464 eyr:1973 hgt:70cm +cid:262 iyr:2015 hcl:#c0946f + +eyr:2029 +byr:1923 hgt:160cm hcl:#7d3b0c iyr:2013 pid:525837692 ecl:gry + +hcl:#602927 eyr:2025 +pid:232338168 hgt:174cm cid:322 iyr:2010 ecl:oth + +hgt:192in cid:126 hcl:#6b5442 +pid:101406211 byr:1922 ecl:hzl eyr:2022 iyr:2013 + +eyr:2026 ecl:amb +byr:1921 +cid:336 +iyr:2020 hgt:182cm pid:533626984 + +pid:411943955 ecl:amb eyr:2025 hgt:166cm byr:1964 hcl:#341e13 cid:285 +iyr:2010 + +ecl:grn byr:1933 eyr:2024 +hgt:153cm +hcl:#5cfb31 iyr:2019 pid:773885967 + +ecl:hzl pid:426060511 +hgt:159cm +byr:1922 hcl:#6ffd04 iyr:2017 + +byr:2025 pid:#097d1b iyr:2020 eyr:2029 hcl:73d113 hgt:69cm ecl:utc + +ecl:amb hgt:170cm eyr:2025 byr:1930 iyr:2018 hcl:#733820 +cid:262 + +iyr:2019 +eyr:2021 +cid:65 pid:258615618 +ecl:oth byr:1987 +hcl:#efcc98 +hgt:178cm + +hcl:z eyr:1980 ecl:#1c5fd1 hgt:65cm byr:2014 +cid:222 pid:#c69fd5 iyr:2020 + +cid:271 pid:#4b8380 hcl:80fab0 +byr:2024 ecl:#20e25f +iyr:1945 +eyr:1935 hgt:159cm diff --git a/4-passport_processing/src/main.rs b/4-passport_processing/src/main.rs new file mode 100644 index 0000000..4a6a42a --- /dev/null +++ b/4-passport_processing/src/main.rs @@ -0,0 +1,191 @@ +use std::{collections::HashMap, str::FromStr}; +use anyhow::Result; +use regex::Regex; + +#[derive(Debug,thiserror::Error)] +enum ParseError { + #[error("Expected {0}")] + Expected(String) +} + +#[derive(Debug,PartialEq, Eq, Hash)] +enum EntryType { + Byr, + Iyr, + Eyr, + Hgt, + Hcl, + Ecl, + Pid, + Cid, +} + +impl FromStr for EntryType { + type Err = ParseError; + + fn from_str(s: &str) -> Result { + match s { + "byr" => Ok(Self::Byr), + "iyr" => Ok(Self::Iyr), + "eyr" => Ok(Self::Eyr), + "hgt" => Ok(Self::Hgt), + "hcl" => Ok(Self::Hcl), + "ecl" => Ok(Self::Ecl), + "pid" => Ok(Self::Pid), + "cid" => Ok(Self::Cid), + _ => Err(ParseError::Expected(format!("byr, iyr, eyr, hgt, hcl, ecl, pid, cid, but got {}", s))) + } + } +} + +impl EntryType { + pub fn is_valid(&self, value: &Option<&str>) -> bool { + match (*value, self) { + (Some(value), EntryType::Byr) => { + // four digits; at least 1920 and at most 2002. + + match str::parse::(value) { + Ok(number) => { + (1920..=2002).contains(&number) + } + Err(_) => { false } + } + } + (Some(value), EntryType::Iyr) => { + // four digits; at least 2010 and at most 2020. + match str::parse::(value) { + Ok(number) => { + (2010..=2020).contains(&number) + } + Err(_) => { false } + } + } + (Some(value), EntryType::Eyr) => { + // four digits; at least 2020 and at most 2030. + match str::parse::(value) { + Ok(number) if (2020..=2030) + .contains(&number) => true, + _ => false + } + } + (Some(value), EntryType::Hgt) => { + // a number followed by either cm or in: + // if cm, the number must be at least 150 and at most 193. + // if in, the number must be at least 59 and at most 76. + let rex_cm = Regex::new(r"(\d*)cm").unwrap(); + let rex_in = Regex::new(r"(\d*)in").unwrap(); + if rex_cm.is_match(value) { + let m = rex_cm.captures(value); + // At least "None" fails the test + match str::parse::(m.unwrap().get(1).unwrap().as_str()) { + Ok(height) if (150..=193).contains(&height) => true, + _ => false + } + } else if rex_in.is_match(value) { + let m = rex_in.captures(value); + // At least "None" fails the test + match str::parse::(m.unwrap().get(1).unwrap().as_str()) { + Ok(height) if (59..=76).contains(&height) => true, + _ => false + } + } else { + false + } + } + (Some(value), EntryType::Hcl) => { + // a # followed by exactly six characters 0-9 or a-f. + //probably ok as long as we deal with ascii right ? + let rex = Regex::new(r"([a-z]|[0-9]){6}").unwrap(); + value.starts_with('#') && rex.is_match(&(value.chars().skip(1).collect::())) + } + (Some(value), EntryType::Ecl) => { + // exactly one of: amb blu brn gry grn hzl oth. + let valid_values = vec!["amb", "blu", "brn", "gry", "grn", "hzl", "oth"]; + valid_values.contains(&value) + } + (Some(value), EntryType::Pid) => { + // a nine-digit number, including leading zeroes. + // probably ok if we deal only with ascii right ? + value.as_bytes().len() == 9 && str::parse::(value).is_ok() + } + (_, EntryType::Cid) => { + // ignored, missing or not + true + } + _ => false + } + } +} + +#[derive(Debug)] +struct Passport<'a> { + fields: HashMap> +} + +impl<'a> Passport<'a> { + fn new() -> Self { + let mut res = Self { + fields: HashMap::new() + }; + res.fields.insert(EntryType::Byr, None); + res.fields.insert(EntryType::Iyr, None); + res.fields.insert(EntryType::Eyr, None); + res.fields.insert(EntryType::Hgt, None); + res.fields.insert(EntryType::Hcl, None); + res.fields.insert(EntryType::Ecl, None); + res.fields.insert(EntryType::Pid, None); + res.fields.insert(EntryType::Cid, None); + res + } + fn parse(&mut self, s: &'static str) { + for entry_s in s.split(&[' ', '\n'][..]) { + let mut tokens = entry_s.split(':'); + if let Ok(etype) = EntryType::from_str(tokens.next().unwrap()) { + self.fields.insert(etype, tokens.next()); + } + } + } + + fn is_valid_legacy(&self, mandatory_cid: bool) -> bool { + self.fields.iter().all(|(key, value)| { + (!mandatory_cid && *key == EntryType::Cid) || + *value != None + }) + } + + fn is_valid(&self) -> bool { + self.fields.iter().all(|(key, value)| { + key.is_valid(value) + }) + } +} + +fn main() { + let data = include_str!("../data/input.txt"); + // eprintln!("data = {}", data); + //eprintln!("data.split() = {:?}", data.split("\n\n").collect::>()); + let passports: Vec = data.split("\n\n").map(|pass_str| { + let mut res = Passport::new(); + res.parse(pass_str); + res + }).collect(); + // eprintln!("passports = {:#?}", passports); + // eprintln!("passports.size() = {:#?}", passports.len()); + let nb_valid = passports.iter().filter(|p| (*p).is_valid_legacy(false)).count(); + eprintln!("nb_valid = {:#?}", nb_valid); + let nb_valid_secondpass = passports.iter().filter(|p| p.is_valid()).count(); + eprintln!("nb_valid_secondpass = {:#?}", nb_valid_secondpass); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_validation() { + let mut pass = Passport::new(); + pass.parse("cid:271 pid:009457684 hcl:#80fab0\nbyr:1999 ecl:blu\niyr:2015\neyr:2029 hgt:159cm"); + eprintln!("pass = {:#?}", pass); + assert_eq!(pass.is_valid(), true) + } +} \ No newline at end of file diff --git a/5-binary_boarding/.gitignore b/5-binary_boarding/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/5-binary_boarding/.gitignore @@ -0,0 +1 @@ +/target diff --git a/5-binary_boarding/Cargo.lock b/5-binary_boarding/Cargo.lock new file mode 100644 index 0000000..c49676c --- /dev/null +++ b/5-binary_boarding/Cargo.lock @@ -0,0 +1,70 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "anyhow" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68803225a7b13e47191bab76f2687382b60d259e8cf37f6e1893658b84bb9479" + +[[package]] +name = "binary_boarding" +version = "0.1.0" +dependencies = [ + "anyhow", + "thiserror", +] + +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "1.0.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a571a711dddd09019ccc628e1b17fe87c59b09d513c06c026877aa708334f37a" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thiserror" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e9ae34b84616eedaaf1e9dd6026dbe00dcafa92aa0c8077cb69df1fcfe5e53e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ba20f23e85b10754cd195504aebf6a27e2e6cbe28c17778a0c930724628dd56" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" diff --git a/5-binary_boarding/Cargo.toml b/5-binary_boarding/Cargo.toml new file mode 100644 index 0000000..31c31c8 --- /dev/null +++ b/5-binary_boarding/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "binary_boarding" +version = "0.1.0" +authors = ["Guilhem MARION "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.36" +thiserror = "1.0.22" diff --git a/5-binary_boarding/data/input.txt b/5-binary_boarding/data/input.txt new file mode 100644 index 0000000..cfb1d3b --- /dev/null +++ b/5-binary_boarding/data/input.txt @@ -0,0 +1,932 @@ +FFBBFFFLRL +FFBBFBBRRL +FBBBFFBLRL +BBFBFFBLRR +BFBBBFFLLL +BFBBBBBLLR +FBFBFBFLLR +BFBFBBFLLR +FBBFBFBLLL +BBBFBFBRLL +BFBBBFBLRL +FBBFFFBLLR +BFFBFBFLRL +FBBBBFBRLR +FFBBBBBRRL +FBBFBFFLRL +FBBBBBBLLR +FBBFBBBRRL +FBBFFBFRLL +FBFBBBBRRR +BFFBFBFRRL +BFBFBBBLLR +FFFFBFBLRL +FBFFBFFLRL +FFBFBBBRRR +FFBFFFFLRR +FBBBFFFLLR +FFFFFBFLLL +BFFFFFFLRL +FBBBBBFRLR +BBBFFBBRRR +FFFFBBBRLL +FBFFBBBRLR +BFBBBFFRRL +BBFBBFBLRL +BFBFBFFRRR +BBFBFFFLLL +FBFBFBFRRR +BFBFBFFRRL +BBFBBFBRRL +FFBBFBFLRL +FBFFFFFRLR +FBBFFFBLLL +FBBBBFFRLL +FFBBBBBLLL +BFFBBFFRLR +FFFBBFBRRR +FBBBFFFRLL +FFFBFBFLRL +BFFBBFFLRL +BFBBBBBLRL +BFFFFFBRRR +FFFBBFBLRL +FBBBFBFRLL +FBBFBFBLRR +BBFBBFFLRR +FBFFBBFLLL +FFFFFBBRLL +FFBBFFBRLR +BBFFFFFLLL +BFFFFBFLRR +FBFBBFFRRL +BFBFFBBLLR +FBBBFBBRLR +BBBFBFFRLL +BBFFBBFRLR +FFBFFBBRLR +FFBBBFBRLR +BBBFFFBLRR +BBFBFBFLRR +BFBBBBBRLR +BFFFFFBLLR +FBFFBFFRLL +BBBFFBBRLR +FFBBBFBRRR +BFBBBFBRLR +FBFFFBBLRL +FFFBFFFRLL +BBFFBFFLLL +BFFBBFFRRR +FFBFBFBRRL +FFBBBFBRRL +FBBFFBBRLR +FBFFBBFRLR +BFBFFBBRRR +BBFBFBBRLR +FFBFFFFRRL +BBFFBFFLLR +FBBFBFBRRR +BFBFBBBRRL +FBFBFFBRRL +FFFBBFFRLL +BFBFFFFRRR +FBBFFBFLLR +FFBFBFFRLL +FBFFBFBLLL +FBFBFFFLRL +BBFFFFFRRR +FBFFBBFLRR +FBFFFBFLRL +FBBBFBBRRL +BFFBFFFRLR +FFBBBBFLLR +BFFFFBFLRL +BFFBFFBRRR +FFBFBFBLRL +BBFFFBBRLL +FFBFBBFRRR +FFFBFBFRRL +FBFFBFBRRR +FBBBBFBRRL +FBFFFFFLLR +FFBFFFFLLR +FBBBBFFRLR +BBBFFBBLRR +BBBFFBFLRR +FBBFBBBLRR +FBBFBBFRRL +FFFBFFBLLL +FBFFFFBLLL +BBFFFFBLLL +FBFFFBFLRR +FFBFBFFLRR +BBFBFFFRLL +FFFBBBFRLR +FFBFFBBRLL +BBBFBFFRRL +BFFBBBBLRR +BFFFFFFLLL +BBBFFFBLLL +FBBBBBFRLL +FBBFBBBLLR +BBFBFFFRRR +BBFFFBBLLL +FBBFFBFLRL +BBFBFFFLRR +BFBFFBFRLL +BFFFBFBLLR +BBBFBFBLLL +BBBFFBFRLR +FBFFBFBRLR +BFBBFFFLLL +BBFFFFBLRR +BBFFFBBRRL +BBBFBFFLLL +BFBFFBFLLL +FBBBBFFLLR +FFBFFFFRLR +FFBBBFBRLL +BFFFFFFRRL +BFBFFBBLRL +BBFBBBFRLL +BFFFBFFLLR +BBFBFFBRLL +BFBBFFFRLL +BBFBBFBRLR +FFFBBFBRLR +BFFFBBFLRL +FFBFFBFRLL +FFFBFFBLRL +BFBBBFFRLR +BBBFFBBLRL +BFFBBBBRRL +FFBBFFFRLL +BFBFFBFLRL +BFFBBBBRRR +BBFBFBFRRL +BBBFFBFRRL +BFFFBFBLRL +FFFBFBFRLR +FBFFBBBLRR +FFFFBBBLLL +BBBFBBFLLR +BFFBFBFRRR +BFBFFFBRRR +BBFBBBBLLR +FFBBBBBLRL +FFBFFBFLRR +FFBBBFBLRR +BBFBBFBRRR +FFFFFFBRRR +BFBFBFBRRL +BBFFBBBLRR +BBFBFFFRLR +FBBFBFBLLR +BFBBFFBRLL +FFFFBFBLLR +BFBFFBBRLR +FBFFFBFRRR +BFFBFFFRLL +FBBBFFFRRR +FFFBBBFLLL +FBBBBBBRRL +FBBFFBBLLR +BBBFBFFLRR +BFBBFBFLRR +FFFBBBBRRR +BFFFBBFRLR +FBFFBBFLLR +FBFFFFFRRL +BBBFBBFLLL +BBBFFFFRLR +FFFFBBBRRR +FBBBFBBLLL +BFFBFFBLLL +FBFBBFBRLR +FFBFFBBLLR +FFFFBFFLRR +FBBFFBFLLL +FBFBBFBRRR +BBBFBFBLLR +BBFFBFBLLL +FFBFFBFRLR +FBBBFBBLRR +BBFBBFBLLL +FFBFFBFRRR +FBBBBFFLRL +BFBBFBFLLR +FBFBBBFRLR +BFBBFFBLLR +FFFBBBFLLR +FFFBBBFRRL +BFFFBFBRLR +BBBFBBFLRR +BBFBBFFLLR +BBFBBBBRLR +FBBFFFFLRR +FBFBBFFRLL +FFBFFFFRRR +FFFBBFFRRL +FFFBBFBRRL +FFFBFBFLLR +FFBBBBFRRR +BFFFFBBRRL +BFFFFBFRRR +BFBBBFBLRR +FFBBFFFRRL +FBBBBBBRRR +BBFBFFBLLR +FBFFFFBRLL +BFBBFBFLLL +FBFFFBBRLL +FBBBFFBLLR +BBFBBBFRLR +FBFBBFBLRR +FFFFFBFLLR +FBFBBBFLRL +FFBFFFBRRR +FFFBBFFLRL +BBBFFFFLLR +BFBFFFFRRL +FBFBFBBLLR +FBBBFBFRRL +BBFBBBBRRL +BFBBFBFLRL +BFFBBFFLLR +BFBFFBBRLL +FBFFBFFRLR +FBFBFBFLRR +BFBFBBFRRR +FBBBBFBLRL +FFBBBFFRRR +FFBBFFBRLL +FFBBBBBRLL +FBFFFBFRRL +FFFBBBFLRL +BBBFBFFRRR +FFFBFFFRRR +FBFFBFFLLL +FFBBFFBRRL +BFFBFFBRRL +FFBBBFFRLR +BBBFFFFRRR +BBFBFBBRRR +FBFBBBBLRR +BFBFBFBLLL +FFBBFFBLLR +BFFFBBBRLR +BFBBFBBRLR +BFFFFBBLLR +FBFBFBBRLR +BFFBBBFLLR +FBFFBFBLRL +BFBFBBBRLL +BFBBBFFLRL +FFFBFFFLRR +BFFBBFBRLL +FFBBBBFRLL +BBFFFBBLLR +FBFBFBFRLR +BBBFFFBRLR +BFFFFFBRLR +BBBFFFFLLL +FFFBBFBRLL +BFFFFFBRRL +FBFFBBBRRL +FBFBFBBLLL +FBFBBFBRRL +FBBFBBBRRR +BFBFFBBRRL +FBBBBFBLLL +FBBBBBBRLR +BBFFFBFRRL +FFFFBFBLLL +FFFFBBFLRR +FFFFBFFLRL +BFFFBBFRLL +BBFFFFBRRR +BFBFFFFRLL +BFFFFBFLLR +BBBFFBBRRL +BBFBBFBLLR +BFFFFBFRLR +FBBBFBFLLR +FFFFFBBLRR +BFBFFFFLRR +FBFBBFFLRL +FBFFFBBRRR +BBFBBBFLRL +BFBBBFFLLR +BFBFBBFRRL +FBFFFFBLRL +FBBFBFFRLR +BFBFBBBLRR +BFBFBBFLRL +BBFFBFFRLL +FBFFBBBLRL +BFBFBFFLLR +FFFBFFBLLR +FFFBFBBRRR +BBFBFFFLLR +FBBBFBFRLR +FBFFBBBLLL +FFBFBBFLRR +FBFBFFFLLL +BBFFFFFLRL +FBFBBFBLRL +BBFFFBFLLR +BBFBBBBRRR +BFBBBFFRRR +FFFBFFBRLL +FBBBFFFRLR +BBBFBFBLRL +FBFFFFBRLR +BFFFFFBLLL +FBFFFFBLLR +BFBBFFBLRR +BFBFBBBRRR +BBBFBFBRRR +FFFBBFFRRR +FBBBFFFLRR +BBFBFFFRRL +BFBFBBFRLR +BFFFBFBRLL +FBFFFFFLLL +FFFBBBBLRL +FFFBBFFLLL +FBFFFFBRRR +FFBFBFBRLR +BFBFFFBLRR +BFFFBFBLLL +FBBFBFFRLL +FBFBFFFRLL +FBBBFFBRRR +FBBBFFBRLL +FFBBFBBLLL +FBBBBFBRRR +BFBBBFBLLR +FBBBBBFLLR +FFBBFBFLRR +BFFBBFBLLR +FBFFFFBLRR +BFFBFFFRRR +BFFFBBBRLL +FBFBBBFRLL +BFBBBFBRRL +FFBFFFBRRL +FBBFFFFRLR +BFBFBFFLLL +FFBFBFBLLL +FBFBBFBRLL +FBFBFFBRLR +BFFFFFBLRR +FBBBFFBRLR +BFBBFBBLLL +BBFFBFBRRR +FFFBFBBRRL +FFBBBFFRLL +BFFFFFFRLL +BFBFFFBRLL +FFFFFBFRLL +BBBFFFBRRL +FFBBBBFRRL +BFFFBBBLRL +FFFFFBBLLR +BFFFFBBLRR +BFBFFFBLLL +FFFFFBBRLR +BBFBFBFLLL +FBFBBBBRLR +FBBFBFBRRL +FFBFBFBRRR +FBBBBBFLRL +BBFBFFBLLL +BBFFFFBRLL +BBBFBFBRLR +BBFBFBBLLL +BFBBBBBLRR +BBFFFBFRRR +FFFBFBFRLL +BFFBBFBLLL +FBFFBBBRRR +FFFBFBFLLL +BBFFBBFLRL +BBFFFFBRLR +BFBFBBBRLR +BBBFBFFLLR +FFBBBBFRLR +BBFFBFFRRL +BBFBFFBRRR +BFBFFBFLLR +FBFFBBFRLL +BBFFFFBLLR +FBFBFFFRLR +FFBFBFBLLR +BFBBFFBRRL +FBBFFBBRRL +BBFFBFBRLR +FFFFBFBLRR +FFFFBBBLRR +FFBFBFFLLL +FFBBBFFRRL +BBFFFBFRLL +FBFBBBFLRR +FBBFBFFRRR +FBBFBFFLLR +BFFBBBFLRR +FBBFBBFRLR +BFFBBBFLLL +BBFBBFBRLL +BBBFFBBLLR +BBBFBFBRRL +FBFBBBFRRL +FBBFFFBRLR +BFBBFBBLRL +FFBBFFFRRR +BFBFFFFRLR +BBFFFFFLLR +BBFBFFBRLR +BBFBFBFLRL +FBFFFFFLRL +FFBBBFFLRL +FBFBFBBLRR +FFBFBBBRLL +FFBFBFFRLR +FBBBFBFLRR +FBFFBFFLRR +BBFFBFBRRL +FBBFFFFLRL +FFFFBBFLRL +FFBBFFBLRR +BFBFFFBLLR +BFBFBBFLRR +BFBFBFBLLR +BFBBFBFRLL +BFBBFFBRLR +FBFFFBBLLL +FFFBBBBRRL +FBBFBFFLLL +FBFFBFBRLL +BFFBFFFRRL +FBFBFFBLLR +BBFFBBFLLL +FFBBBFBLLR +BFBBFFFLLR +FBBBFBFRRR +FBBBFFBRRL +FFFFBBFRRR +FFBFFFFLRL +FBBFBBFLRR +FFBBBFBLLL +FBFFFBFRLR +FFBFFBBRRL +FFFFBBFRRL +BBBFFFFLRL +FBBFFFBLRL +FFBFBFBLRR +FFFFBFFRRR +FFFBFBFRRR +BBFBBBBLLL +FFBBFFBRRR +FBBFFBBLRR +FBBFBBFLLL +BBFBBBFRRL +FFFBBBBLLR +FFBFFBBLRR +BBFBBFFRLL +BFBBBBFRLL +BBFBFFBRRL +BFFFBBFRRL +FBBBBBBLLL +FFBBFFBLLL +FFBBFBBLRR +BFBFBFBLRR +FBBBFBBLLR +BBFBFBFRLL +FBBFBFFLRR +FBBBFBFLLL +FFBBFFFLRR +BFFBBBFRLL +FBBBBFBLLR +BFBFFFFLRL +FFBFBBBLLL +FFBFFFBLRR +BFBFBFBRLL +FBFBFBFRLL +BFBBBBBLLL +FFBFBFBRLL +BFBFFFFLLR +BFFBBBBLLL +FFBBFBBRLL +FFFFBFBRLR +FBFBBFFLLR +BFBFBBFRLL +FFBFFFFLLL +FBBFFBFLRR +FFBFFFBRLL +FFFFBBBLLR +BFBBBBBRLL +FBBFBBBLRL +FBFFBBBRLL +FBFFFBBLLR +FFBBBFBLRL +FFFFBFFRLL +BBFFFBBLRL +BFFFBFFRRL +BFFBFBFLLL +BBFFFBFLLL +FFFFFBFLRL +FBBFFFFRRR +FBBBBBFLRR +FFBFFFBRLR +FBBBFFFLLL +FFBFBBBLRL +FFBFFFBLLL +FBFFBBBLLR +BBBFBFFRLR +FFFBFFFRLR +BBFBBBFLLR +FFBBFFFRLR +FFFFFBFRLR +FBBFFFBRRL +BFFBBBBRLR +BFFBFFBRLL +BFBBBFBRLL +FBFFBBFRRR +FBFBBFFLLL +BBFBFBBLRL +BBBFBBFLRL +FBFBFFBLRR +FBFFFFFRLL +BFBBFBFRRR +BFBFBBBLLL +FFBBBFFLRR +BFBBFBBLLR +FBBBBFFRRR +BFFFBFFLRL +FFFFBFBRLL +BFFFFBBLLL +BFFBFBBLLL +BFFBFBBRRL +BBBFFFBLRL +BBBFFFBRRR +BFFFBBFLRR +FFBBFBFRLL +BFFBBFBRLR +FFBFFBFLLR +FBFBBBBLRL +BFFBBFFRRL +BBFFFBBRRR +FBBBFBBRRR +BFFFFBFRRL +FFBFBBBRRL +BFFFBBBRRR +BFBBBFBRRR +BFBFBFFRLR +FFFFFBBRRR +FBFBFBFLRL +FFBBBBBLRR +BBFFFFBLRL +FFFBFFFLLR +FFFBFFFRRL +FBBBFBBLRL +BBFFBBFLLR +BBFFBFFLRR +BFFFFFFRLR +FBBFBBFRLL +BFBBBBFRRR +FBFBBBBLLR +FFFBBFFRLR +FBBFBBBRLR +FBBFBFBRLR +FBBBFFFLRL +FFBBFBBRLR +BFFFBBBLLL +BBFBBFFRRR +FBFBFFFLRR +BBFFBBFRRR +FBBFBFFRRL +BFFFFBFLLL +BBBFFBBLLL +BFBBBBFRRL +FBBFFFBRRR +BFBBBBFLLL +FFFBFFBRRL +BFFBFFBLLR +FFBBFBFRRL +FBFFFBBRLR +BFFFBBBLRR +FFBFBFFRRR +FBFBFFBRLL +BFBBBBFLRL +BFBBFFFRRR +FBFBFBFRRL +BBFBBFFLRL +FBBFFFFLLL +BBBFFBBRLL +FBFFFBBRRL +FFBFBFFLRL +FBFFBBFLRL +BFFBFBFLRR +BFFFFBBLRL +BBFBBBBLRL +FFBFBBFRLL +FBFFFBFLLL +BFFBFFBLRL +FBBFFFBLRR +FFFFBFFRRL +FBBFFBFRLR +BFFFBFFRRR +FFFFBFBRRL +BBFFBFBLRL +FBBFBFBRLL +BFBBFFFLRL +FFFBBBFRRR +BFFFFFFLLR +FBFBBFFRRR +BFFFFFBRLL +FFFFBBBRRL +BFFBFBFLLR +FFFFBFFRLR +BFFBBBFRRL +BFBBFBBRLL +FFFFFBFRRL +FFBBBBFLRL +FFBBFBFLLR +BBFFBBBRLL +BFFBFFFLLR +BBFBBBBRLL +BFFBFBBRLR +FFBFBFFRRL +FBBFBBFLRL +FFBFFBBLRL +BFBFFFBRLR +BFFBFFFLRR +BFFBBBBLRL +FFFBFBBRLR +FBBBBBFRRR +BFBFBFFLRL +BFBFFFBLRL +FBBBFBBRLL +FBFBFBFLLL +FBBFFBFRRR +FFFBFBBLRR +FFFBFFFLRL +BFBFBFBRRR +BFFBBFFLLL +BFFBFBBRRR +FFBFFBFRRL +FBFFFBFRLL +FFBFBBFLLL +FFBBFFBLRL +FBFBBBBRRL +BFFBBFBRRL +FBFBFBBLRL +BBFBFBFRLR +FBFFFFFLRR +BBBFFBFRLL +BFBFBFFRLL +FBBFFBBLRL +FBFBFBBRRL +FFBBBBBRLR +FBBFBBFLLR +FFFBFBBRLL +BBFFFFBRRL +BFBFBFBLRL +FBFBBFBLLR +BBBFBFBLRR +FFFFBBFRLL +FFBBBBBRRR +BFBBFFBRRR +BFFFBBBLLR +FBBBBBBRLL +FFBFBBFRLR +BBFFBBFRLL +BFFBFFFLRL +FFBBFFFLLL +BFFBFBBLRL +BBBFFFFRLL +BBFBBBFRRR +FBFFBFFRRR +FBBFFFFRLL +BFFFBBBRRL +FBFBBBFLLL +FFFFBBFLLR +FBBFBBFRRR +BBFFBBBRLR +BBFBBFBLRR +BFFFBFFLLL +BBFBFBFRRR +FFBFFFBLRL +BBFFFBBRLR +FBFBFBBRRR +BFBBFFBLRL +BFFFFBFRLL +BBFBFBBRLL +BFFFFBBRLL +FFFFBFFLLR +FFBBBBFLRR +FBFBFFFRRR +FFFBBFBLLR +FFBBFBFRRR +BFBBFBBRRR +FFBFBBBLLR +FFBFFBFLLL +FFFFBBBLRL +FFBFBFFLLR +BFBBBFFLRR +FBBFFFFLLR +FBFFFFBRRL +BFFBBFFLRR +FFBBFBBRRR +FFFFBFBRRR +BFBBBBFLLR +FBBFFBBRRR +BBFBFBBLRR +FFFBBBBLRR +FBFFFBBLRR +BFFBFBFRLR +BFBFFBFRLR +BFBBFFFRLR +FFBBFFFLLR +FFFFFBFLRR +BFFBBFBLRR +FFFFBBFRLR +BFFFBBFLLR +FBFBFFBRRR +BBFBFBBRRL +FBFBBFFLRR +BFBFFBFLRR +BBFFFBBLRR +FBFFBBFRRL +FBBBBBBLRL +FBBFFBBLLL +BFBFBBBLRL +BBBFFFBLLR +BFFFBFFLRR +BBFFBBFRRL +BFBFBBFLLL +FFBBBFFLLR +BFBBFBFRRL +FBFFBFFRRL +BFFFBFBLRR +BFBBFBBRRL +BBFBFFBLRL +BFFBBBFRRR +FBFBBFBLLL +BBFFBFFRRR +BBFFBFBRLL +BBBFFBFLLR +FFFBBFBLLL +FBBBFFFRRL +BFFBFFBLRR +BBFBFBBLLR +FFBBFBFRLR +BBFFFFFRLR +FBFFBFBLRR +BFFFFFFRRR +FFBBFBFLLL +BFBBFBBLRR +BBFFFBFRLR +BBBFFBFRRR +FFFFBBFLLL +BBFFBFBLRR +BFFBFBBRLL +FBFFFBFLLR +BFFFBBFRRR +FFBFBBFRRL +BFBFFBBLRR +FBBFFBFRRL +FFBBBBBLLR +BFBFFBBLLL +BFBBBBFLRR +FFFFBBBRLR +BFFBBBBLLR +BFFFFFFLRR +BFFFFBBRLR +FFFBBBBRLL +BFBBFFFLRR +BFFBBBFRLR +BFFBBFFRLL +FBFBBBBLLL +BFBFBFBRLR +BBFBBFFLLL +BBFBBBBLRR +FFBBFBBLLR +FBBFFFBRLL +FBBBBFFRRL +FFFBBFBLRR +FFFBFBBLLR +FFFFFBBRRL +FBFBBBFRRR +BBFFFBFLRL +FBFBFFBLLL +FBFBFFFRRL +BFBFFFBRRL +BBFFBFFRLR +BBFFBFBLLR +FFFBFBFLRR +BBFBBBFLLL +BFBBBFFRLL +BFFFBFBRRL +FFFFBFFLLL +FBBBBBFRRL +FBFBFFBLRL +FBBBBBBLRR +FFFBBBBRLR +BFFBFBBLLR +BBFFBBFLRR +BFFFFFBLRL +FFBBBBFLLL +BFFBFBBLRR +FFFBBBFLRR +FFBFBBFLRL +FBBFBFBLRL +BBBFFFFRRL +BBFBFBFLLR +BFBBBFBLLL +FFBFBBBLRR +BFFBFFBRLR +FFFBBBBLLL +BFFFBFFRLR +BFFFBBFLLL +FBBBBFBLRR +FBBFBBBRLL +BFBFFBFRRL +BFFFFBBRRR +BBFFBBBLRL +FBBBBFBRLL +BFBBFFFRRL +BBBFFBFLLL +BFBFFBFRRR +FFBFFBBRRR +FFBFBBBRLR +FBBBBFFLRR +BFBFBFFLRR +BFBBBBFRLR +FFFFFBFRRR +BFFBBFBRRR +BFBBBBBRRL +BFFBBFBLRL +FFFBFBBLRL +FFFBFBBLLL +FFBBFBBLRL +BBBFFFFLRR +FFFFFBBLRL +FBFFBFBLLR +FBFBBBBRLL +BFFBFBFRLL +BFFFBFFRLL +BFFFBFBRRR +BBBFBFFLRL +BFFBFFFLLL +BBFFFFFRRL +FBFBFFFLLR +FFBFFBBLLL +BBFFBFFLRL +BBFFBBBLLL +FFFFFBBLLL +BFBBFFBLLL +FFFBFFBRLR +FBBFFBBRLL +FBFBFBBRLL +BFFBBBFLRL +FFFBFFBLRR +FBFBBFFRLR +FFFBBFFLLR +FBFBBBFLLR +FBBFFFFRRL +BBFBBBFLRR +BFBBFBFRLR +FFBFFFBLLR +FFBFFBFLRL +BBFFBBBRRR +BBFFFFFLRR +FBFFBFBRRL +FBFFBFFLLR +FBBBFFBLLL +FBBBFFBLRR +BFBBBBBRRR +BBBFFFBRLL +FBFFFFFRRR +BBFBBFFRLR +BBFFBBBLLR +BBBFFBFLRL +BBFFFBFLRR +FFFBFFFLLL +FFBFBBFLLR +BBFFFFFRLL +BBFBBFFRRL +FBBFBBBLLL +FFFBFFBRRR +FBBBBFFLLL +FFFBBFFLRR +BBFFBBBRRL +FFBBBFFLLL +FBBBFBFLRL +BBFBFFFLRL +FFBFFFFRLL +FFFBBBFRLL +FBBBBBFLLL +BFBFFFFLLL diff --git a/5-binary_boarding/src/main.rs b/5-binary_boarding/src/main.rs new file mode 100644 index 0000000..d065d2d --- /dev/null +++ b/5-binary_boarding/src/main.rs @@ -0,0 +1,82 @@ +use std::convert::TryFrom; +use std::str::FromStr; +use anyhow::Result; + +struct Plane { + cols: usize, + rows: usize, +} +const my_plane: Plane = Plane { cols: 8, rows: 128}; + +#[derive(Debug, thiserror::Error, PartialEq)] +enum ParseError { + #[error("Expected {0}")] + Expected(&'static str), +} + +#[derive(Debug, PartialEq)] +struct Seat { + col: usize, + row: usize, +} + +impl FromStr for Seat { + type Err = ParseError; + + fn from_str(s: &str) -> Result { + if s.len() != 10 { return Err(ParseError::Expected("10-char string")) } + + // split_at not supposed to fail as we are only working with ASCII chars here + let s_bit = s + .replace("F", "0") + .replace("B", "1") + .replace("R","1") + .replace("L", "0") + .chars() + .collect::(); + let (rowcode, colcode) = s_bit.split_at(7); + Ok(Self { + row: usize::from_str_radix(&rowcode, 2).unwrap(), + col: usize::from_str_radix(&colcode, 2).unwrap(), + }) + } +} + +impl Seat { + fn seat_id(&self) -> usize { + 8 * self.row + self.col + } +} + +fn main() { + let input = include_str!("../data/input.txt"); + let mut seat_ids: Vec = input.lines().map(|l| Seat::from_str(l).unwrap().seat_id()).collect(); + seat_ids.sort(); + println!("Max seat id: {:?}", seat_ids.iter().max()); + let banana = seat_ids + .windows(2) + .flat_map(<&[usize;2]>::try_from) // Because windows() makes no promise on slice size + .find(|[a, b]| *b == *a + 2); + eprintln!("banana = {:#?}", banana); +} + +#[cfg(test)] +mod tests { + use super::*; + const AOC_INPUT: &str = "FBFBBFFRLR"; + #[test] + fn test_build_seat() { + assert_eq!( + Seat::from_str(AOC_INPUT), + Ok(Seat { row: 44, col: 5 }) + ); + } + + #[test] + fn test_seat_id() { + assert_eq!( + Seat::from_str(AOC_INPUT).unwrap().seat_id(), + 357 + ); + } +} \ No newline at end of file diff --git a/6-custom_customs/.gitignore b/6-custom_customs/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/6-custom_customs/.gitignore @@ -0,0 +1 @@ +/target diff --git a/6-custom_customs/Cargo.lock b/6-custom_customs/Cargo.lock new file mode 100644 index 0000000..174b177 --- /dev/null +++ b/6-custom_customs/Cargo.lock @@ -0,0 +1,23 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "custom_customs" +version = "0.1.0" +dependencies = [ + "itertools", +] + +[[package]] +name = "either" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457" + +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] diff --git a/6-custom_customs/Cargo.toml b/6-custom_customs/Cargo.toml new file mode 100644 index 0000000..be6f05a --- /dev/null +++ b/6-custom_customs/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "custom_customs" +version = "0.1.0" +authors = ["Guilhem MARION "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +itertools = "0.9.0" diff --git a/6-custom_customs/data/input.txt b/6-custom_customs/data/input.txt new file mode 100644 index 0000000..1784e14 --- /dev/null +++ b/6-custom_customs/data/input.txt @@ -0,0 +1,2199 @@ +zvxc +dv +vh +xv +jvem + +mxfhdeyikljnz +vwzbjmsrgq + +vbtjnh +vhejnbti +vthnjb +tsbhjnv + +cbjemdvp +jdvuylp +ofpjaqgsrxvdn +dzvpbj +vbktpdj + +knyvdhsemu +sdyumkgvh +muyvdskh +syhkuvmd +dvmykshu + +rmantzovbsuxiljkchfgdqew +vficzosgwlmrdtqkueajbnxh +davqlntibxhojesrkugpzmwfc + +ifdmgrcve +bkqal +gxcwvt + +xeiokblasch +toxjlsbnciha +sovycihlabx +ximhylocabs +hixsolabc + +iyfkvmpolta +thpqodzifxc + +iexunoyhwv +ovweiyuhxn +uhojnvyxeiw + +vbncamhzojtqrlpse +wujapcidzx +zxjiuacwkgfdp + +bygewhzsnqvxaoc +sngqvepohyzdwxcab +yoxwzmgvesbqhcua +cqtbwehiavofzsgylx + +rxanvifdup +xuvpnfria +rfnpvixua +npiuxfarv +vnifuxpra + +ysrktfhc +trfkcysh +ktfycrsh +rhckstyf + +nq +kqin +nq +qn +nq + +yorbujt +evqkmscp + +fitkprweso +fszkmoretwpi +ptyoswrekim +iuwbrsgeockpajt +yewksitpro + +gtyaemflvc +fyvlecgmati +vgfyclemta + +k +tj +uebpy +vyma +ibdy + +p +p +p + +r +r +lya +b +r + +cht +hct +cth +tch +hct + +qdxpas +dpxsha +parlyekqsx +sxuotvpwaz +jqxspymae + +ngycrw +wgnv +sngw + +psb +us +s +s +s + +xnodk +dxok +tkxdo + +n +n +n + +tysg +gtys +syg +eghslqry +gyts + +qliwfgatpbdcy +aqwflpdygtcb +ypdcglqtwabf +dwgcytlbapqf + +nwvlqbusparkf +jhfbvnsqpr +nprqbzfevs +nvrqhboexmspfy + +tgr +rgt +gtr + +jokfqv +jqk +qjk + +fuv +mvuf +vfu + +mfw +mwf +fmw +fmw + +kt +jp + +fklnagsztb +znmtsfalpj + +o +qb + +h +peqyon +az + +n +n + +eagyvpmjqxs +qghjsapny +jayrqsgp +qasygjp + +yctzugn +ytzcgu +cuytgz + +bsfxcygptnlk +xrgocylkifuen + +os +wakdftzgh +losn +pn +yp + +pie +ei + +zpsxeb +tgynfiw +zomvqu +ludk + +s +s + +wuon +ngw +wn +nw +wn + +omrdjkzeb +ncdjuzborkm +zkebrdajmo + +tjwaxm +iztwvod +wqt +txwr +wt + +lpcbfwiksnvdhrqjut +punidbscqtrwjvkfhl +vrcqukphwjsdbtflin +dvkwlgnhutsrcjbqipf + +spzlowvtxdkjinfc +indjlksczxfptvo +czmaxkqnfpbvyshjdliot + +aqspmnkxie +trjhfclyogd +zwavixpbeu + +mozewqhxkduajgy +mogjekqnfuywzhxda +ozhkaxegyumwqdj +ajdzogmehwqrkyux + +qemykxdwipjfa +wdxaplmeyfkiqj +xmqplaekifdwzj +mjixwqzaedkfp +ofpmwxkqjeadi + +gpjydb +jpystgkd +gzjdpy +jpgyd +pgjydxh + +drockgqe +evanghozbi + +kfg +lmfwig +gf +fgsj + +zjfnabowyrtmxcgl +ycrjxazgfowbitlnm +hrlwegxokbqzatcnjfmy +jcobagxflzntymwr +grzotfxcymlwavbunj + +iamdhcgfynqzos +gyszifcnavdolhqm +qmnwziuropsacdgyh + +mwlgcedjtknxsuy +estmwlxuydjkci +hctlyawmxkjseud +jutsxdycwlkmie +mtwqyskbflxjzvcdeuo + +sdfwjm +wdsm +ygmqsxdei + +u +u +u + +dutb +dubt +dutb +tdu +idtu + +sqpfzwlvcjtx +haiv +dveyohgb +kuvhm +vik + +myzxofuacqsgi +kcamifojuybgqs + +mthngfuvykwci +numzktjydcxwio + +aspdgtikq +qpkgdtisa +qsgkdptia +pqtuakzdigxs +pdkqtiasg + +fityomxdwlscjazhkqp +pmzrcjhvntsobfq +shztqgmrjofcp +jmcngqhoputzefs + +whjgxi +wxjoihg +gxjwih + +hirpefgxsa +gahfytkz +qdjlzvwfahg +hbaofwgvc + +dhcnfgy +fyhdgc +gyctdhf + +hbmconewlqgsdzk +jqflbowkdsgc +hwkobvdcsqeilgn +lkcogsaypdwxbq + +enzrdgqyu +gvqrtoihlaj +qrgs +qpeurgzkxn + +grjdenycstpfbihqo +bfkhlgjrpeysomtvidqc + +fxmqujr +wmvghur +dpaeyko + +untpyr +urtpyn +apnutry +uptyrn +nustyrepg + +ofualjwvq +jeyoqru +yuxqioj +ushtogmdpqjcknb + +txeyfwrhl +xrhfytelw + +nu +niu + +rbmuneiz +neibzurm +mnerbizu + +mvtkp +vmpkzt +mpvkt + +vakc +erq +b +ijftomxy +zsg + +yptu +tpayoub + +zsqvdfw +zdswvfq +qzwsfdv +qwzdfsv + +pbwvzadgyturskqoefncxhmjl +thazxruyscfqndvpjklbgomwe + +xnomrqyzpe +ieudmxroqvbnz + +cldqr +ecdqr +ercqd +cdwrq + +kwzqcagfxvhjromti +hfsjcqxibokgravztmw +atkrogwjcxvfmzhiq +gwhztkxacfvrimqoj + +ztbqli +lobdrhgt +rbltoyh + +wfh +fh +hf +fh + +rnxkztpmi +umzigxnh +zyxilqnsm + +iox +oi + +ovugqjpxkshczewmr +smpgxuqzlehkwrvaocj +civspxkmhjwuzegoqr +jergszqvhkxucpomw + +mzsrlcfqpuaex +rtxaqnsjczvf +rxsuiazqcdf + +zvmltjegwxyfihnsaouq +tmwlgxyhoendfiaq +nrgptwaxleoqfihmyk +tlqhiawmnoyfegx +nhlwfcagqyotxmei + +dfoyublxhzajwktrv +olrfzuyphd +fynohuiqemlszr + +nmwedzq +qewzdn +zqnedw +qnzwedp +dqezwn + +lvugjzmsec +mgnlqsjzudvw + +yasmrkxvnpch +yxabnvhpskrdmcl +hvnkarsyxpmc +myhvconkpaxrs + +pfelbgs +a +vriu + +vfy +oj +izagebph +ck +mv + +hn +h +bjhtr +h +h + +saixpwbhqdverzcyfnktluo +kuqtfhewypnrbgvcdliozxs +deiyptgkwrzqlohbvxfucsn +bynqihpjwecotlfvzusdrkx + +yxvfnlwz +ecvwlfbgnz +rfphonqviwlz +nezbwvufl + +i +i +i +i +i + +hvbatqdzu +zvaqtumldb + +hqxbn +hqbn +hqbn + +ymikcgxdph +kmduhyxqenpil +kphygxmid +hidfkzxypm + +gve +eygv + +chds +hsdc +dcsh +hcsd + +pgakuncrze +rpackxegnz + +nhypde +ncepyd +ndpey +ydenp +yecndp + +qgjpeu +dfma +uwnfvsja +ohxcltz + +emgqlacpfvjhux +iudjrhwvfsxplmge + +fmwbpeyxna +wxdnafyeuibkj + +rqhzeaojuigyvp +ovtixs +ixov + +ms +m + +u +v +u +u + +yo +yo +yo + +rhnmlxbvdteckzpsjaw +cwzdraljthpnkxmeibvs +wavdlhjezskmbrnpcxt +pqadwkrmjbecxlnsthzv +zkpbawrdhnclsmtexvj + +djecv +jewcd +dejcb +dvjce +ecdj + +adiotklhj +oakyljdthi +laticokjdh +cialdtykjhfo +kadoequjtlih + +xcrfloupby +lufciypr +hrpcuyxfl + +fwngabh +njfgbwha +hgafbwn +bnhgawf +fbamhngw + +fwqe +qfmvup +fqa +fqe + +us +us +su +su + +lobh +b +bezjmi +iblz +sxbtav + +tjkdlfwm +klwmjfdt +lcwfvjmdktq +wlkfdtjm +kmdwltfj + +ngrzftbhoevylpiscd +rhvsfbliwkndcaxzoejyp +pfizbnldechsryov +csnrdfibyvpolzeh + +bhszfutjkrdxyeic +iscrkhbjwdlyxzefp + +rncodaythzpgelbu +udcnathrbsogelzy +yuhwglzreancitojbd +yhelzuodacnrbtg + +rv +fwla + +cuqsfzalw +caqzwlfus +wvcuflszaq +saqlcuzfw +uwscqaflz + +hnp +pnh + +y +y +ergy +y +y + +bmexpongud +pgktrwhbneqaxov +uiocxdgnebps + +vxtckwno +uenb + +xgomqzsuivnab +xusnvoqimgbza +vqizsuxbnamgo +zumvgxansqboi + +s +tsy +lf +rczxhvaopjew +ltm + +ipvefjzuhs +hiecsvzu +egykiushqbzdmovx +izhvesau +virsuhez + +ld +lg + +xnvszluechwptgm +uczsgowtpvlnmx +zmwglrpscuvtxyn +xmcstnvldzpguaw +miwblxuzgcptjvksnq + +ftwx +zcritxpbo +txsf + +buzcyxlmoknsvqrdpwta +iseplfgmrnjbwyvhtxk + +cmjpkingdflra +pcinrfladmkug +icrmngljadkpf + +saehfjb +dtuheqwbgxyonksjlc +ehvmjsb + +fcty +qopy +hyfv + +djkcm +jklmbd +mhrdkji + +xaropbcylemuh +benjalhducrpy +ecypvsklubhtirwfa +azrynhepulcb + +xe +xe +xe +ex + +os +os +asob +so + +omtnjhdvcw +ujotewxndvkfb + +svqlbwrctd +qfcbltsh + +eof +ebosn +owfe +xmyoe +rvmoew + +lmaus +ulam +auml + +ky +e +f +o +e + +figyhsul +fguyhlsi +lyhfigsu +yuglfshi + +myc +cmyd +myc +mcy + +dpnbhltm +mp +pmua +opxm +kvpgmuf + +hk +prv +rh +ixm + +umlcksxonaqft +bednjkpgirm + +tj +fxjtl +tcmj +tgzbvoprkqwu +ist + +bzats +haosb +abqsk +abgs +wvbfeuxasn + +knwbzryjvde +jdebkvryzcn +djbzykenv +euyfnkavdzbxmj + +srgkpw +apqbxusc +tpmwq +injolypfd + +onxflkzsqwetmdrayupbijv +blkorzdvyxiuawgnqpmstef +fsnpxiueltmzovwrabyqdk +bfxsyekrnvdqzoutwpiagmhl + +jahltpfywcnobux +hcwfadpkyzms +oglqhpifavcwyx + +migjhyvpnf +ufjyqv + +txoci +z +izvugb +rpydhl +xbm + +ajlfb +bfl +jslof +fzrnmlqek +ofdl + +crbuzmjlnsoixgyatf +gkbasourfjcimlxtnv +ndmwxstgfoubrcljia +qmfoxlhnrubetgjsaci + +msr +ir + +ypv +vp +vp +rpv +pv + +jquxr +hngqptklaeuimrw +frbdvoucq +drusqy +xqdzur + +ifnuymdhesgzpjkroqwc +nqshkiwoyfcupmjgrezd +cpqmjwreogdyhuznfkis +pzijugdfykreocnqhswm + +wletxi +twlxe +tjewrlmx +sflciwxet + +cqmtspovlhxzwknijgdbya +jktgvsnfmobiwxplqzyc +oniglefctyxvbzpsqkmjw + +aqbujkmecp +jcakubpeqm + +ms +s +g +d +s + +ymb +bmy +tbym +zmby +zymb + +zmajf +afd + +saqutcgmzpvrx +qzumvpcraxgts +zcmgpquxnrsavt +uxztgakmcqsypvr +xmvqurazcptsg + +xgcnvwikzmh +jualdmfogexcp +vrixcgqmbt +gcxms + +hlf +jzeubrawvgonf +yqxcpkhf + +wpkbqaver +kwenvqrpbd +pswekvrqb +vbepwrqk +rkweqpvb + +r +ef +eqh +e + +nvzfi +znmev +ohnlvzk +vnezjc + +whkjfmbtausedyvqx +tmqxhkfsydevuwba +srvfbdkymwtqxiehcupa +lsatxumedbwfkvyhq + +aligpe +glpaie +aliepg +eilagp + +xvigpscledkfwjbztn +sgejnlvxdtbzfckpiwh +vlcwftebgjsndpzixk +swkzngbdcexifltvjp + +zrethjknvsdwf +qldrsgybijfhz + +tlhogxqens +habqtneudxljgks +xqtsnelhmgo +qlnteghxs + +bhc +ec +ch +jgiyc + +xzfioelc +ozilcexf +zfeoxcli +clefxioz + +uqjkybfsehwxzlptrni +caryzpjnukwlxesgtbhf +jzwkubtlsypqhneforx +xlrwkspjyufnzebht + +tvzuoab +bv +bgv +bv + +ltujriwpmyna +jtrmpw +mwtspjr +tmorwjp + +tyjsqfripxz +rpzxytjqsif +xtyrspijzfq +ctixjyfzrsqp + +ycjihklnd +ezvuqn + +chtgvuilo +uvgticloh + +hmgyx +yghlx + +oejuvpaigsrqh +pijsveugqroha +eviqopasurjgh +iroqaphsuevjg +qauzoirjghsevp + +gumpokcdtinjberaxqfz +xdounkjezmrpfbicqgt +pzfgicekuymqnrxodbjt + +npy +nyp +ypn +ynp +ypn + +xfhucsdlpveoir +mnzobifxtkr + +hy +yh + +iumnsyqgw +wgyismd +rdmgwiyhfs +xzgywmis + +dwfplygjx +vuhewxszq +bxnrmocki +xtyea + +ouyqrtczxwj +xqtyujwocrzb +qjxuyrotkwcz + +qjtcyaoexnvl +nxtaqkjloce +tzcongqajpxle + +olubpxmfdayik +leqomjitfbay + +lygezhjmbi +clvphtkud + +vp +pv +pvkfw +pmv + +rpsclgeuhmkja +mcgypeuswakhio + +ajdpyugzbcswtei +pcadiemunsbgw +ludvapgecqsfbwi +elsugdcfnhbipwa + +vfzoqrbgjycuenwlxdts +fgdnclwtoyxqvuesjrzb +ejatdrohipbxucyvnwzfsqgl +utsloejxznvwybdrfgcq + +vwkaomqupbitzrh +pvawbkoztumqhr + +ijbcxau +cijuoea +cjifuyqa +cubtxaji +jxcaiu + +zsankwocrhb +dchzrbkmaswon + +jdcfne +nfedjc +qeczfjn +fcejqn +jnefvc + +vpzmjnb +zbvjqdys +zbxpdjmial +ktouerbjgwz +jsbzhc + +zbsi +zisb + +txvngrdas +vadsrgtx + +qgnvriol + +a +a +a +f + +mvuywsiaqcl +nqavfwhsicz + +yuomdcgnvwhakel +auwkhgoycmlevn + +icagyksq +crsahngi + +vb +ftlgxroupjyis +cvh + +vcimkpuafwqbryogjxdt +mxyftdriubhawgjcvpkq +rybptdfhaoxkgvmjuciqw +idxrkpygcwvltaefmbqju +trmjbiqpnyhvscwxafukgd + +esbdajqhvl +jdqlszev +foedswyvlunq +ixevsdtblmq +rvetlqsdk + +islfcy +yif +bify +ioymf + +hrcqst +pecr + +gwd +wdg +dgw +dgw + +ksyqndmahzgxejfp +sexhgkfzdapyqmjn +dejzykngpamhfqxs + +fmohepc +pucg +cp + +xvdmorgbsnawjlecztykpif +rsmwdvfplkencbzaotgjix + +wjhkg +gbkh +dklegsrmhy +hukgw + +flwu +lnzckx +vetd +myj +xwcp + +vjhnftpyr +nfhjvyrpt + +lne +nel +nle + +hgqjcse +chfja +jqcus +kozlctmiy + +h +h +h +h +h + +lwco +wloc +tlkuwco +lwoc + +egzxalry +zyxaklpge +zlwergaxy + +nghrpie +nqz +au +ytcdsfw +lbj + +jkcetobxnsyqwfdzuglv +gsnwvmzjxiteryacp +njcshegytvzxw + +qtsf +st +ts +ts +tps + +ckmnriay +sytrcng +ncywrg +ncygr + +rcnyivhla +ebgfdotjuks + +tfjcihobxywuvpezarkg +hckgoruvbxzenjipaywft +fwhtyrvebajgpkcuxoiz +oaruytpwzikbfhjxevgc + +oaxzdr +dopg +opzak +woqg +notveuy + +l +l +l +qn +m + +dvjuhlfmectponaxwyib +yfaltvohpnquirmzjdcxsb + +ib +bil +ib +bi + +sd +lo + +s +wsvef +va +jwvf +rdho + +or +lor +kro + +ze +e +e + +teh +ef +ek +fe + +dfbzgqpsk +pzgfaydsuxq +pgfqdsz +kzrfgqsdwp + +rxqgndcawfb +loyuzbmejivkhs + +jilybertvwkqcma +nuelmho +ledhomnuz +esfml +gxzpelm + +mikrjtbophlqduwsexvcy +mbrqlycjvskdwithuopex +qlwrcduykbmxsovijthep +xevmqplwtjyckbouirhds +bmytdrsxvupciloewqjkh + +wrnkojbmtzvchulxaisepyfdq +xicryqvwkumtozjdhsflegpabn + +yjxpwakhd +klhj +kjih +nshrgujk +skjhm + +fasz +aef +gmqipcfanvt +hsafl + +m +m +m +m + +ksyargzucfq +lyvjrmapbhqwt + +b +b +by +b + +d +dx + +lqdmrovwifbhpkg +dqvofhgzwipkmlsrbn +ihmvkdqbroflgpw +bghqvfipwodlkrm + +qzuabnldjsf +nabfzldjq + +ihkpj +skhj +khj + +pfhzgidaoumyclqwjb +oubaqdmhlzgjfcwyip +maqwihopcbdlzyfujg +aydlupjizwhofcbgmq + +dcifuhzpj +udizhcfj +uzcrijdhmf +uhfdcjize +dxbjhzaifuc + +mijthslvq +vslmjqhi + +yilmjrbsaugeqv +sokhewyczmgufabjv +maxbtsguvyejdlp + +bdysxeouwcn +otszxpnm +wbsxonkr + +btwjys +bjy +jby +bjy + +elobcuyqvps +ubeloqvyspc +elvcypobusq +qbcsuyeplov + +zshbqdmcxntwokevlpjugr +lubzdvwrksnhqcptmgyexjo + +csmyezwqxdpfh +zexmdwhcqsyfp +fdqeysphczxwm + +wx +x +x + +hmudcwtoix +duitheoxcmw +xeomwhtiucd +xmthuoiwdfc + +qgh +xburedysok +izaqc +vac + +c +xd +y + +bcqxzv +czxvb +xcdv + +rstdhfvyupaqnilgkx +thmdrvqkgyxpcewlafu +xkvfgpdtahinlsyquzr + +ionzfdqwacl +aliwfzcnodq +ysdoijcnpqalfwuzr +dialwcqofezn +lqwfncaoeizd + +vjnzhsyokprdwqt +slufncexiadgw + +lmanxbzrvkgju +cotlneyfp + +ehcxwrapivns +nvewjcaspixr +ecpdkqxvastmn + +okgbcwvytiznshexu +kwyszldpbuthoxnj +kotjwysnuzxhb +juzbwshqatknxomy +krzthuxqynfoswb + +rjfbkgapzqiwnecoh +ohjnfzrabwcgqipek +bgmzawokijpnqhfcre +vwherzicopkqbanjufg + +qrwxpijsu +apuwbfirqjs + +rgynxak +uaxpirf + +sf +f +uf +ihxfzdy + +dvcrwsbpziytjqhnuoa +ehgudqsyzkbrnpt +sptdxznyeuhrqb +uqzbhfynsrtdp +srpymhztqbdunl + +rqly +dlaxpwrji +rbljwh + +grascdfzlpxoeqvtyn +xcnfwvryspeukbodzlatg + +oqlucpvdizwh +trakqib +agitjq + +yslaopvredmzcjnighqtfk +ohgqmkatyrledjnifspzc + +xwliz +czvfiqxw +gyswmhb + +fpndrua +aurfp +rpuaf +raufp + +eukjozdbqcxpyl +qyfmkxzboulcpejd +zlquxdybcepjko + +dlgxuchpnmosfr +dxcoshzfguykpvm +awgdpubxiefsohqj + +abop +abvpo +napobc +vapob + +wryqzk +kwqyc +wyzqkr +ykwqzo +ywkqr + +jbk +tkbj +bjkcn +bjk +jkb + +fagxpiolshctke +xtiochpabflsk + +fqdteprviumho +meitwhforpduqv +utfrhempwodviq +nehmyipftrqdlucov + +anqedwylpuv +edoqpufvwzx +tiuqvjhcrpewkmd +psvudgeqw +gdwulbpvqze + +znugjimbptvefqhxr +suxktycoplwe + +qtludyrb +yqrludv +lqdyur +ldqryu +lurkzqyvad + +cwmikuhtgole +tzghimclkue +igtxkcpsmlydhe +khtglcqmuie +imhwecgltk + +pschkw +schnwpultqk +iwzohyej + +dwxbfsq +dswfbqx + +tpby +ptq +qpt +tp + +nqtocmfdjpskriev +agvctwbfxkyj + +kqdewilc +qweluikd + +qbyv +vb + +k +jmp + +lvnqfrdctwzk +xtljgevz +tusihlzv + +vrtojs +rvtzosj +jrcqvsutohwl +zvpsjtgoar + +wkh +wh +hbtl +qh + +jzcdykoafitepbxlqvmns +yqcpzvksoinjlebfdatxm + +rvmjscznedib +smineqdwcjvrz +duejsmrncviz +idrmvcsezlnjf + +qognsitfwkcmvd +qbonaiuktrc +ctkiyqnou +iptrcqjkhzoaxn + +msjqvb +wxfpej + +zgdmaphfuiols +oemgjuxavhcsfzdilp +gopdafmiulshz +zaphsolgumftid +fdgmahupzsoil + +svdmfou +uofmsdv +fuvsodm +uvmodfs +vsoumdf + +pn +gn +np +hsnc +nem + +ondycsxijkhztmb +sdtmkibxjyu + +cfdbyz +dbcfyz +ocfbzyd +bfzdyc +fcbydz + +rycjvanzo +qzecro +zrqoc + +iytqmcheg +gyiectmh + +idcpxfhmwbutsogkazl +iwoydxlchsezubtkgpma +fcwtdoulsphxmibkazg +woshuclmdzibaxpgkt + +lvpfdtgw +jysqnxkozermwc +aywockbuh + +hlgrnxofckptmqvaebsdwi +lhqtonswkdmvrcibfxape +wqimranhsepdotcfbxlvk +ksxwcidfaoqlbrvenhtpm +dncheprotawksmxflvbiq + +mkcyzpfseqg +yqgmkczvt +zbiqoynxkrjd + +qalxdcz +wuchrlszbepm + +tisl +tjoycs + +uixno +zicsuorn +xuqiokn + +qadwnkvfzltpib +ctehovpradslgxujwnmbfiq + +lnbzhdvqucg +udvzgqlcbhn +zcvhlqndgub + +dnkeso +enskdo +sneokd +oknsde +dekson + +aqxyozpubvjgcr +ybpjqrcoagxuzv +yrajbvpogcuqzx +ubarxgvqyjpzoc +xqupgyrovzcjba + +galcpxukjvdfz +jcvgulafdxpzk +gchxzuajvlkpdf + +pds +euwsvd +dsf + +phvzus +rhlztp +phzdla + +rfpbcyd +rbdycpf + +brwpvt +spvtrjb +vytpbr +tbsrvwp +rvtpb + +efmkb +bemkf +bekmf +temfkb + +jyzinpl +efxqapwo +rzup +dpcr + +bawpqhnvmtuxsflizck +avqcthmkpifswzlnxu +slmqcpnxivzahkutwf + +zsakf +skfeza + +neqbzcajpw +onzqsaxhcbwljdm + +do +do +od +od + +rieubqwd +cqrupedvitb +edbqirun + +hvrpjfwud +zpauyi +kbxmeupq +uptwfhgzaj + +vkqf +fhnpyx +gawucsozmdi +tbrpnlekj + +neriadovyhuzkqgc +rqflhpywekobzstjumcn + +bvzumtnorcqhyilgwe +tvnioyzlwmerhgbuq +wylinhomzvetrbuqgdc +ghbltunyeopfrqizmwavx + +jvrieqgfklch +pjndlghruvif + +xbwvzikjtnhfayp +tgcadrqjxuel + +lbxsjvamqwdfutrck +bwrxdaqzuftlmvk +zbtmakqxdfpruwlv + +jrisgax +gries +rigts +girjspe +pasieghr + +reqwbsjzlghkv +gkmvstdcaroqbzjp +qhrvngfjzsblku + +vtilu +i +i + +cmizk +kmcdwi +tokljcmiv + +gcmxdqoysrjhzvunkbtpwfi +rsvhxmjgbdupqotnywkcifz +byczhwkrnmujqoidfpstxgv +romdtyjgwbcpihafslznxqkvu + +kcx +wfsoxa +rcxk +xecl + +xhljmt +lheratmxj +fhmxtcwlb +xhlmaritg +thxmalo + +usfhzlidpmxvonr +luvxhfdcmrpn +xpfldmuhvrn +lumvrnedxfphk +lpvdnfurmxhk + +ukqco +bg +d +x + +wshkqpojltbyexrvfcmaiugd +ptxsveguqfjdimboarwclhky +figabshrwotdqjepmlxkyvcu +imgseacrdxfkyptwhvoblujq +wflyahpcgbrsmvkitejxoqud + +cdfihsmoy +smieho +mhsoi +oenshami +ozlhswmi + +pefjcrt +vdfzpwrtc +ptegcbfr + +uet +uet +eut + +ubyk +ukygtrole +jukzxqhvy +eumldfkyos +knaiuywrm + +ncjzgqof +qafcjnzog +zojngqfc + +uxkryjwflco +psolcaquvwkdnizre + +linoudwypsgbvmx +wugpsidobmnryv +udynmoswgb +kydhcbnozusmegwt +sygbrmudwnafo + +sfkatdxbyqezirv +skvtiarxeybzf +viyzrlampbxtskfe +vyqazixrftsebk + +bjwqhkryuz +zmwkyuqhjrb +qjuwrzhybsk +hyzwujqbkr + +wjahb +jywahb +jbawh +jwhba + +aetucrzpvn +esznbtkoy +eztdn +zonte + +dkpu +mpqcixu +pwu +psu +pudkhyv + +ydtaink +atndubyk +ocytkdain +wnvgzytadkps + +mtne +mten +netm +netm + +l +lz +l +l +l + +wfu +wfu +uwf +uwf + +wcxsiaokerlumjnqyfvhtbgd +abrlxsfzqjuwnotehgmdkcyv + +kate +aekt +akte +teak + +spxqizdhbuokw +pwdxibkuzsqohr +qkszwvaulbpdthoig +ouwqdkzypbhis + +xlskunagot +onxagbulsem +olnsagux + +mhrst +hm +hm +hknuimeg + +pzwtsrfhcmqidnaeybgxkluvoj +keugsjaimzwbxqcvndytfhlpor + +gezfhs +nsyftgje +csifykhegj +fdrgmqvse + +eqagibxdlst +gdisebqlxat +eogtidqaslbx +tdbqslaigxe +eltabiqxsdg + +hopcmlyfka +zleytsfdpcgbn + +iq +qm +ajngr + +jgnh +pdqzyblwuh +tovghj + +jsztoebhflkrncuygi +epzghnfcoljutisryk +ugnysrzftjieholckm +kyeuglztrshjnbfico + +q +q +q +q + +zch +zhc +ch +cdgh +hcw + +nubdmx +xunbd +dxunb +wbxund +udnbex + +dfcauy +afdcuy +dfcuya +uafcdyn +fudyac + +cdgkzushqaevntrop +ndhzqxgksrpotcaev +qetkhzodnsrcgvap +epcvrnokadgzhstq +nozqsrhcegpavdkt + +wbpaec +jmfyir + +wozuxcnegrjikhy +eritoghwxluynkjzc +okrecihjuwxznbgy +nuwirjxkezyghoc + +g +q +r + +jdr +rj +rj + +ogs +szgo +osyugw +sogj +ogs + +ixnlzuvyar +ryznvumlqfexi +icylvxzrnu +lurxhyvzni +nixylzvrut + +xv +xs +x +kfwax +hxu + +dkjohmvtxscaqpyzbie +bdvtjzyhoaecmxpiqks +eyhsxtdoazqvcbpmikj +oevbpqstmxchykizdja +mbvjkyzihcsqepadxot + +vkqgipbhsmczdaery +ckomvhixysdq +cvixystlohmkqd +noyqmhdfuvkcis + +jeqcx +xjqec +jceqx +qcjex + +okncyha +kha +wdqkamrhi + +uajtdcwglpxf +ldxgwjauscp +avciwljdyxupg +lgctupaxwjd +zjblqcxwkrgdanup + +ogpcjvltkizyrubnshf +xrpukdzmcsqlnofejigtvbh +nhvztyfbsuicjlrkopg + +rklv +lnvr +vrsle + +tdoeb +toebz +jbot + +ahntqkrwvxc +htray +tehar + +xbis +q +p + +y +y +y +y + +svpnoi +vsnroip + +rkdetpah +hpdmjrekao +ybzcrhkguew + +ha +qkj +vzcjq + +ubjqtpfxalnv +uftvrxjqpbnla +tbunjpvqfxalh + +izesvwkmyohlqr +jhtqnmyiawpskz + +jdoqhwbftxpavygze +zydthexqgwpkaovnfj +cdsvzfxwtigjamryhqep + +srvdcubotnwkx +dmhpqyzikcslargnj + +tcmoi +ptqeci +buvtic + +kisteoqyjapdrcgfx +sqdxjckrfoytap +ztrdcxsayfkqjop +rjxfkpdaqysozctm +fyctdxsrkaojqpu + +chtzwxr +ozcrsthux + +oqahrvuinct +uavtnforke +ounartv +akunvrot +uonvftmar + +hveqfbrwkdosnay +zofutwkxmpgnljic + +sexkhbfwvagzjq +hryamtnf +phacfo + +yzdbglajf +lybfajgzid +ldjagfbyz +djlyzfbga +lgyjzfabd + +mk +km +mk +mk + +vupse +utvf +veu +noubvi +vslpu + +gxcz +xgcz +zxgc +cgxz + +xsgkotfqldj +ltwmgjofxdsk + +sptmvzkdoxwqrefgn +zwa +ybwjzuchl + +jqdxzbhsctn +ocsat +tokewcs +usktc + +hqctliu +ilchptqu +quchitlj +lcuqtih +ipbqctulh + +wgihvaqrxpczsmflydjuket +mclinzpejdgtsfwqhyxkrvua + +sdgycjfmukezpx +bvwzqrmnti + +xoizphtv +mfzxhitopvag +hzipoxtv +rdtxiopvhz +hnvopxzti + +nluidsozya +sxcqziol + +vf +vf +fv +fv +vf + +x +x +mdtxr + +cspzldibokwq +bnktcpxzwlmeijqvd +pqkcyzhwbild + +zmdrvaxgtiq +jydtqgcm +dqgtxlm +fnxtegsmqrad +gkqmdtv + +zwulxhevg +jtwpxvdczlsh +znxlvhw +laozqhwrvgx +xmlvhfizw + +ixjseyvhfcupkz +jifehpsczxyvu +ixhvyweujozsmpfc +wpfskxljyceiuzhv +gydqfcphztjesirxuv + +bdolgwcua +cogbawu +ugabwco +obtcwagu +wcbuoga + +txjldzfwhbqcspemvgkiyn +kmdswhijztqfyclebvnpgx +szydcbewfnmvpxhijtqklg + +jfxehga +aoxhj +vuaozhjqxi +hxjqvia + +cyknepoazhsml +dhoecksznaylp +uktqnwrhivasbcxlepy +yshcfelankp + +mgbwxcvkrl +tzoauif +qpjntdoysueh + +n +n + +briatspxkzdwue +abdgifsljzuo + +vklpca +lkavpc + +lfxguyd +dzfuex + +zqxod +qxd +qdx +xhqude + +ovigcernldjwzy +idegzjvrwlyn + +cb +bc +rbcxdh +bc + +givtqeysrcjfzumod +isrgtyjavfwcoekdzmuq +zdgtmescqrvyiujfo +ogumbvzcdejyrtsiqf +qdfjsoetuvrymzcig + +fwruktphdzan +zkfpnrthwaud +unrhpzwtdafk + +odlubiyrqzfevnjpakwtgmx +lrsdjkauwbvztfymqginoxpe +omeqnvadjubzwkxritgyplf +fjzywpmkeaotldvguqbnixr + +emayzjxi +axzreyckm + +lduhiqwpjrnkto +ntcrjqdkwphloi +thjdwnklqirpo +tqpdwjilhoknr + +vi +iv +vir + +xoetdfmrbvl +dfebtomilx +fbltmdexo + +hmcuklq +lusqkch +iqjpulckh +suchkql + +gu +gu +gu +ugn +gu + +lvtfiecgrzxhm +tircajhne + +fm +if + +subio +buosi +boisu +busoi + +uwkhxabg +hofrviyqz +wkuhs + +zoswictnpdvjegqymbfura +cmrnqyupavzbfjegidtso +xpycanfhjrulqzvmtdbsegoi +iqdrfstyjgabzenpvckomu + +kzardg +dkzgura +zdagrk +gdrakz diff --git a/6-custom_customs/element b/6-custom_customs/element new file mode 100644 index 0000000..4823e2f --- /dev/null +++ b/6-custom_customs/element @@ -0,0 +1 @@ +E: You must give at least one search pattern diff --git a/6-custom_customs/riot b/6-custom_customs/riot new file mode 100644 index 0000000..4823e2f --- /dev/null +++ b/6-custom_customs/riot @@ -0,0 +1 @@ +E: You must give at least one search pattern diff --git a/6-custom_customs/src/main.rs b/6-custom_customs/src/main.rs new file mode 100644 index 0000000..684a14d --- /dev/null +++ b/6-custom_customs/src/main.rs @@ -0,0 +1,81 @@ +use std::{collections::HashSet, todo}; + +use itertools::Itertools; + +fn count_scores(input: &str) -> Vec { + input + .split("\n\n") + .map(|l| l.chars() + .unique() + .filter(|&c| c != '\n') + .count()) + .collect() +} + +fn count_scores_v2(input: &str) -> Vec { + input + .split("\n\n") + .map(|group| { + group + .lines() + .map(|l| l.chars().collect::>()) + .fold1(|acc: HashSet, hset| { + acc.intersection(&hset).cloned().collect() + }) + .unwrap() + .len() + }) + .collect() +} + +fn main() { + let input = include_str!("../data/input.txt"); + let scores = count_scores(input); + println!("Sum of scores : {}", scores.iter().sum::()); + println!("Sum of scores v2 : {}", count_scores_v2(input).iter().sum::()) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_count_scores() { + let input = r#"abc + +a +b +c + +ab +ac + +a +a +a +a + +b"#; + assert_eq!(count_scores(input).iter().sum::(), 11) + } + + #[test] + fn test_count_scores_v2() { + let input = r#"abc + +a +b +c + +ab +ac + +a +a +a +a + +b"#; + assert_eq!(count_scores_v2(input).iter().sum::(), 6); + } +} \ No newline at end of file diff --git a/7-handy_haversacs/.gitignore b/7-handy_haversacs/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/7-handy_haversacs/.gitignore @@ -0,0 +1 @@ +/target diff --git a/7-handy_haversacs/Cargo.lock b/7-handy_haversacs/Cargo.lock new file mode 100644 index 0000000..e126dee --- /dev/null +++ b/7-handy_haversacs/Cargo.lock @@ -0,0 +1,75 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "handy_haversacs" +version = "0.1.0" +dependencies = [ + "multimap", + "peg", +] + +[[package]] +name = "multimap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1255076139a83bb467426e7f8d0134968a8118844faa755985e077cf31850333" +dependencies = [ + "serde", +] + +[[package]] +name = "peg" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f76678828272f177ac33b7e2ac2e3e73cc6c1cd1e3e387928aa69562fa51367" +dependencies = [ + "peg-macros", + "peg-runtime", +] + +[[package]] +name = "peg-macros" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "636d60acf97633e48d266d7415a9355d4389cea327a193f87df395d88cd2b14d" +dependencies = [ + "peg-runtime", + "proc-macro2", + "quote", +] + +[[package]] +name = "peg-runtime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9555b1514d2d99d78150d3c799d4c357a3e2c2a8062cd108e93a06d9057629c5" + +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.118" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800" + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" diff --git a/7-handy_haversacs/Cargo.toml b/7-handy_haversacs/Cargo.toml new file mode 100644 index 0000000..5b8f39f --- /dev/null +++ b/7-handy_haversacs/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "handy_haversacs" +version = "0.1.0" +authors = ["Guilhem MARION "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +multimap = "0.8.2" +peg = "0.6.3" diff --git a/7-handy_haversacs/data/input b/7-handy_haversacs/data/input new file mode 100644 index 0000000..b83432f --- /dev/null +++ b/7-handy_haversacs/data/input @@ -0,0 +1,594 @@ +plaid fuchsia bags contain 5 light violet bags, 1 light yellow bag. +striped aqua bags contain 2 striped teal bags. +clear coral bags contain 2 plaid green bags, 5 mirrored gold bags. +dull tan bags contain 4 faded blue bags, 3 faded olive bags, 5 dull salmon bags. +plaid green bags contain 3 faded green bags. +light tomato bags contain 1 drab chartreuse bag, 1 dotted tomato bag, 3 striped red bags, 2 vibrant violet bags. +dim tomato bags contain 4 striped gold bags, 5 bright lavender bags, 1 pale beige bag, 4 pale tan bags. +vibrant green bags contain 4 faded teal bags. +shiny crimson bags contain 2 dull green bags. +vibrant black bags contain 5 dark beige bags, 3 dark bronze bags. +light tan bags contain 1 striped tomato bag. +vibrant teal bags contain 1 shiny silver bag. +pale chartreuse bags contain 2 dotted plum bags. +plaid coral bags contain 2 pale green bags, 2 faded tomato bags, 2 dark salmon bags, 1 vibrant magenta bag. +dull gray bags contain 1 dark tan bag, 3 dotted tan bags. +muted gray bags contain 5 bright indigo bags, 5 dotted purple bags. +vibrant red bags contain 4 bright tomato bags, 4 shiny orange bags. +faded tan bags contain 1 dull crimson bag, 5 faded red bags. +pale magenta bags contain 3 posh chartreuse bags, 4 vibrant purple bags. +shiny gray bags contain 2 wavy purple bags. +light crimson bags contain 5 clear teal bags. +striped turquoise bags contain 3 pale tomato bags, 2 posh teal bags. +striped purple bags contain 4 dark silver bags, 4 vibrant gray bags, 2 dim bronze bags, 2 clear aqua bags. +muted magenta bags contain 4 striped tomato bags. +light teal bags contain 2 faded brown bags, 2 posh purple bags, 1 faded olive bag. +clear cyan bags contain 1 clear coral bag, 5 clear aqua bags. +dull cyan bags contain 5 wavy crimson bags, 1 pale orange bag. +shiny tan bags contain 2 bright red bags, 4 plaid cyan bags. +light brown bags contain 3 dim yellow bags, 4 dull orange bags, 1 vibrant yellow bag. +pale tan bags contain 2 striped orange bags, 5 dull plum bags. +wavy salmon bags contain 2 dark blue bags, 5 dim plum bags. +mirrored cyan bags contain 2 plaid turquoise bags, 5 dull plum bags, 3 muted indigo bags, 2 plaid white bags. +dark aqua bags contain 3 bright red bags, 2 wavy purple bags, 2 plaid tan bags. +wavy purple bags contain 5 wavy brown bags. +clear magenta bags contain 4 muted green bags, 3 dull cyan bags, 4 striped teal bags, 2 faded blue bags. +bright red bags contain 5 vibrant tomato bags, 2 dull orange bags. +pale purple bags contain 3 plaid turquoise bags, 4 light tan bags, 1 faded black bag, 5 light yellow bags. +bright orange bags contain 1 mirrored orange bag, 2 faded bronze bags, 1 wavy turquoise bag, 1 bright yellow bag. +faded lavender bags contain 1 plaid brown bag. +dark salmon bags contain 3 dotted crimson bags, 1 posh bronze bag. +mirrored coral bags contain 3 dark red bags, 1 dull fuchsia bag, 2 drab magenta bags, 4 dull indigo bags. +clear black bags contain 5 mirrored salmon bags, 3 drab gold bags, 3 muted fuchsia bags. +faded fuchsia bags contain 1 shiny silver bag, 2 posh orange bags, 5 plaid bronze bags. +dotted red bags contain 4 faded yellow bags, 5 dull brown bags, 3 clear red bags. +light purple bags contain 2 plaid magenta bags, 3 vibrant coral bags, 2 wavy black bags. +faded beige bags contain no other bags. +dull fuchsia bags contain 3 dim lavender bags, 1 dull aqua bag, 2 pale fuchsia bags. +wavy olive bags contain 5 dotted cyan bags, 1 dull lime bag. +dim teal bags contain 1 dull green bag. +dull orange bags contain 5 striped tomato bags, 5 drab blue bags, 5 faded blue bags, 2 pale brown bags. +muted brown bags contain 3 dotted orange bags, 1 bright tan bag. +vibrant coral bags contain 2 wavy turquoise bags. +clear aqua bags contain 5 posh bronze bags, 5 dim orange bags, 5 posh chartreuse bags. +dull plum bags contain 4 drab tan bags. +wavy tomato bags contain 4 wavy cyan bags, 1 bright silver bag, 3 dotted gray bags, 1 dark tomato bag. +shiny fuchsia bags contain 1 dotted silver bag, 5 dull lime bags, 3 drab teal bags. +pale fuchsia bags contain 3 pale beige bags. +plaid plum bags contain 4 dotted plum bags, 1 mirrored brown bag, 3 dim yellow bags, 2 vibrant bronze bags. +posh green bags contain 5 plaid indigo bags, 1 wavy red bag, 5 dim indigo bags, 4 wavy indigo bags. +muted aqua bags contain 3 bright tan bags, 3 dull yellow bags, 1 faded blue bag. +mirrored white bags contain 5 dark coral bags, 1 plaid red bag, 4 dull violet bags, 5 clear gray bags. +dotted aqua bags contain 4 drab aqua bags, 3 faded tomato bags. +bright indigo bags contain 4 faded tan bags, 3 clear turquoise bags, 1 plaid indigo bag, 4 bright gray bags. +posh silver bags contain 5 striped red bags, 3 faded blue bags, 3 dim plum bags, 3 vibrant beige bags. +bright olive bags contain 3 dull silver bags, 5 drab tomato bags. +muted beige bags contain 1 drab crimson bag. +shiny beige bags contain 3 clear blue bags. +wavy brown bags contain 2 striped coral bags, 2 light purple bags. +wavy black bags contain 4 faded beige bags, 2 striped red bags, 2 pale brown bags, 3 dull yellow bags. +faded salmon bags contain 1 light indigo bag, 5 plaid cyan bags, 2 pale salmon bags. +dark gold bags contain 1 mirrored plum bag, 2 dark tomato bags, 5 dull green bags, 2 light lime bags. +mirrored lavender bags contain 5 muted brown bags, 1 shiny blue bag, 5 dull blue bags, 3 wavy indigo bags. +wavy beige bags contain 3 mirrored purple bags, 3 posh yellow bags, 4 plaid green bags. +striped fuchsia bags contain 5 drab bronze bags, 4 posh tomato bags, 1 drab maroon bag, 1 dim beige bag. +faded blue bags contain 1 striped tomato bag, 3 dark olive bags, 2 drab tan bags. +drab gray bags contain 1 posh teal bag. +dim cyan bags contain 4 dark fuchsia bags, 3 wavy maroon bags, 5 posh silver bags, 4 posh chartreuse bags. +dotted purple bags contain 3 wavy white bags. +shiny brown bags contain 5 light silver bags, 4 light turquoise bags, 4 posh bronze bags. +vibrant tomato bags contain 3 dotted cyan bags, 3 posh teal bags, 1 clear magenta bag, 5 dull lime bags. +dark bronze bags contain 2 vibrant maroon bags, 2 mirrored olive bags. +wavy silver bags contain 4 striped magenta bags, 3 dim fuchsia bags. +striped yellow bags contain 5 faded black bags, 5 light beige bags, 1 vibrant beige bag, 2 mirrored beige bags. +faded chartreuse bags contain 4 clear gray bags, 5 dotted gray bags. +faded tomato bags contain 5 faded gray bags, 4 faded fuchsia bags, 3 drab teal bags. +dull gold bags contain 1 dark plum bag, 4 striped black bags. +muted turquoise bags contain 1 mirrored bronze bag, 5 shiny aqua bags, 1 clear plum bag. +dotted lime bags contain 1 dark black bag, 5 pale brown bags. +vibrant violet bags contain 5 faded lime bags, 1 pale fuchsia bag, 5 dull plum bags. +faded black bags contain 2 striped teal bags, 5 faded beige bags, 4 wavy black bags, 1 striped lavender bag. +drab teal bags contain 1 clear gold bag, 4 muted crimson bags, 1 light teal bag. +dull purple bags contain 1 posh crimson bag, 2 clear blue bags. +dotted teal bags contain 2 dark tan bags. +dark red bags contain 3 dotted cyan bags, 3 posh red bags, 2 bright red bags, 3 faded magenta bags. +light black bags contain 5 dull yellow bags. +light salmon bags contain 3 faded beige bags. +dull brown bags contain 1 light indigo bag, 4 mirrored yellow bags, 5 faded silver bags. +dark black bags contain 5 dull yellow bags, 3 dull lime bags, 5 posh aqua bags. +faded crimson bags contain 3 light fuchsia bags, 5 muted chartreuse bags. +drab yellow bags contain 5 drab indigo bags, 2 shiny brown bags, 4 muted lime bags. +muted tomato bags contain 3 posh salmon bags, 2 plaid indigo bags, 5 striped aqua bags. +pale teal bags contain 2 muted red bags, 5 mirrored brown bags, 4 mirrored tan bags. +posh violet bags contain 4 posh tomato bags. +dim plum bags contain 1 faded magenta bag, 5 drab silver bags, 1 pale brown bag. +light fuchsia bags contain 2 dotted silver bags, 3 dotted lavender bags, 3 shiny gold bags, 5 clear magenta bags. +vibrant orange bags contain 5 shiny blue bags, 5 dull maroon bags. +shiny white bags contain 5 mirrored yellow bags, 2 pale fuchsia bags, 4 shiny turquoise bags. +drab green bags contain 1 mirrored lavender bag, 3 posh tan bags. +faded silver bags contain 5 vibrant coral bags, 3 striped lavender bags, 4 dotted cyan bags, 5 plaid turquoise bags. +faded gold bags contain 4 faded magenta bags. +dark coral bags contain 3 light maroon bags, 1 drab silver bag. +striped olive bags contain 4 dotted maroon bags, 3 wavy brown bags, 1 wavy crimson bag, 5 shiny silver bags. +wavy lavender bags contain 3 mirrored yellow bags, 5 shiny crimson bags, 4 dark indigo bags. +bright fuchsia bags contain 2 vibrant green bags, 5 drab blue bags. +dotted turquoise bags contain 3 striped red bags. +drab black bags contain 1 faded tan bag. +pale silver bags contain 1 faded yellow bag, 1 drab tan bag, 5 muted salmon bags, 3 shiny white bags. +striped magenta bags contain 4 dark turquoise bags, 4 shiny blue bags, 3 shiny crimson bags. +dotted beige bags contain 2 mirrored black bags, 2 faded brown bags, 1 bright red bag, 2 clear coral bags. +clear maroon bags contain 5 bright bronze bags. +shiny olive bags contain 2 dull blue bags. +pale violet bags contain 1 light purple bag, 1 pale tomato bag, 4 plaid aqua bags, 4 light magenta bags. +dotted white bags contain 3 bright purple bags, 4 dull orange bags, 2 plaid salmon bags. +plaid blue bags contain 5 faded blue bags, 4 muted green bags, 4 bright bronze bags. +mirrored lime bags contain 1 faded green bag, 4 striped black bags, 1 mirrored purple bag. +wavy violet bags contain 1 muted bronze bag. +light silver bags contain 2 dull cyan bags, 1 drab tan bag. +dark tomato bags contain 1 vibrant tomato bag, 1 striped tomato bag. +wavy teal bags contain 5 wavy red bags, 2 drab brown bags, 1 posh olive bag. +dim green bags contain 2 striped teal bags, 1 drab blue bag. +wavy crimson bags contain no other bags. +mirrored aqua bags contain 3 posh tan bags, 5 muted teal bags, 3 light violet bags. +light cyan bags contain 4 vibrant chartreuse bags, 1 faded lime bag, 2 drab purple bags, 2 shiny white bags. +shiny gold bags contain 4 drab blue bags, 4 posh purple bags, 2 drab silver bags, 4 wavy turquoise bags. +plaid chartreuse bags contain 5 mirrored olive bags, 2 vibrant orange bags, 2 shiny purple bags. +dim yellow bags contain 1 faded green bag, 4 wavy fuchsia bags. +pale turquoise bags contain 1 drab turquoise bag. +clear red bags contain 1 pale bronze bag, 4 drab tan bags. +shiny teal bags contain 3 bright aqua bags. +dotted tomato bags contain 3 dotted orange bags, 5 light silver bags, 2 dull green bags, 5 wavy chartreuse bags. +striped tan bags contain 1 light turquoise bag, 2 dotted salmon bags, 4 shiny orange bags, 2 clear red bags. +dim bronze bags contain 1 wavy gold bag. +posh crimson bags contain 4 posh aqua bags. +plaid salmon bags contain 2 dull tan bags. +mirrored salmon bags contain 2 muted aqua bags, 5 muted salmon bags. +striped blue bags contain 3 wavy white bags, 4 drab blue bags, 1 drab chartreuse bag, 4 dull orange bags. +pale red bags contain 1 striped red bag. +muted black bags contain 4 faded gold bags. +clear orange bags contain 2 faded red bags. +mirrored maroon bags contain 2 plaid tan bags. +dull aqua bags contain 4 pale gold bags. +posh coral bags contain 3 striped gold bags. +posh purple bags contain 4 pale orange bags, 5 dull salmon bags, 2 striped teal bags. +muted tan bags contain 3 clear coral bags, 4 pale salmon bags. +mirrored orange bags contain 5 pale bronze bags. +striped teal bags contain no other bags. +dark blue bags contain no other bags. +clear bronze bags contain 4 vibrant gray bags. +light magenta bags contain 4 dim green bags. +drab coral bags contain 5 dotted chartreuse bags, 4 vibrant crimson bags, 2 muted green bags. +drab brown bags contain 2 dull tomato bags, 5 vibrant bronze bags. +bright coral bags contain 1 posh plum bag, 1 wavy gold bag, 2 drab lavender bags, 2 muted lavender bags. +dim white bags contain 4 shiny aqua bags. +plaid bronze bags contain 4 drab tan bags, 3 plaid salmon bags, 4 striped coral bags. +faded teal bags contain 1 vibrant white bag, 5 wavy purple bags. +drab turquoise bags contain 3 pale tomato bags, 1 bright indigo bag. +muted white bags contain 3 striped brown bags, 1 light blue bag. +clear crimson bags contain 1 dark magenta bag. +shiny magenta bags contain 4 wavy tomato bags, 4 shiny bronze bags, 4 vibrant coral bags, 5 bright lime bags. +bright magenta bags contain 3 wavy brown bags. +bright tomato bags contain 4 vibrant fuchsia bags, 1 clear aqua bag. +wavy coral bags contain 4 striped gold bags, 1 light purple bag, 4 vibrant purple bags. +muted indigo bags contain 2 posh purple bags, 2 light gold bags, 3 striped lavender bags. +clear violet bags contain 2 wavy cyan bags, 5 pale brown bags, 4 faded magenta bags, 2 bright purple bags. +dull white bags contain 4 wavy olive bags, 3 mirrored olive bags, 3 faded magenta bags, 4 dull green bags. +dull magenta bags contain 4 dim beige bags. +dotted blue bags contain 4 posh beige bags, 1 pale purple bag, 4 shiny red bags. +dotted lavender bags contain 3 posh purple bags. +light white bags contain 4 striped lavender bags. +dark turquoise bags contain 5 light teal bags. +faded turquoise bags contain 5 striped violet bags, 4 dull crimson bags, 2 dim purple bags, 1 light silver bag. +striped chartreuse bags contain 3 pale white bags, 3 dim fuchsia bags. +pale gold bags contain 2 clear teal bags, 3 wavy turquoise bags, 5 light gold bags. +posh blue bags contain 4 muted yellow bags, 1 dull crimson bag, 3 wavy violet bags, 5 mirrored fuchsia bags. +dotted gray bags contain 3 wavy fuchsia bags. +plaid magenta bags contain 3 plaid black bags. +pale beige bags contain 1 pale white bag, 2 dim salmon bags, 5 mirrored gold bags. +striped bronze bags contain 2 dull yellow bags, 2 dark blue bags. +dark lime bags contain 2 pale magenta bags, 4 clear cyan bags. +bright turquoise bags contain 2 light white bags, 3 plaid salmon bags, 2 clear aqua bags, 5 dull silver bags. +posh salmon bags contain 1 drab turquoise bag. +muted bronze bags contain 1 pale bronze bag, 3 clear maroon bags. +faded coral bags contain 1 clear gray bag, 5 plaid gray bags, 3 bright silver bags, 4 posh yellow bags. +mirrored gray bags contain 1 dark coral bag, 2 plaid blue bags, 4 mirrored coral bags, 1 mirrored olive bag. +vibrant olive bags contain 5 pale chartreuse bags, 4 plaid green bags, 4 dark coral bags. +dotted magenta bags contain 4 light chartreuse bags, 3 plaid indigo bags, 2 dull tan bags. +light violet bags contain 2 muted green bags. +dim fuchsia bags contain 5 dim tan bags, 5 faded black bags, 1 drab white bag. +dotted black bags contain 3 bright gold bags, 2 faded gold bags. +striped indigo bags contain 3 posh aqua bags. +posh cyan bags contain 5 dull fuchsia bags. +vibrant turquoise bags contain 2 muted chartreuse bags, 2 clear magenta bags, 5 drab chartreuse bags. +mirrored magenta bags contain 1 dull lime bag. +mirrored violet bags contain 2 posh magenta bags, 1 plaid white bag, 4 wavy turquoise bags, 5 dull salmon bags. +pale tomato bags contain 4 wavy maroon bags, 3 clear aqua bags, 2 striped lavender bags. +clear fuchsia bags contain 5 dark cyan bags, 1 plaid cyan bag. +drab orange bags contain 3 mirrored purple bags, 1 striped orange bag. +bright blue bags contain 1 bright cyan bag, 4 plaid green bags. +muted chartreuse bags contain 4 faded beige bags, 3 faded green bags. +plaid teal bags contain 2 mirrored orange bags, 5 plaid plum bags. +light blue bags contain 4 faded silver bags, 3 light turquoise bags, 2 dim aqua bags, 5 posh silver bags. +bright tan bags contain 4 striped coral bags, 1 dark fuchsia bag. +shiny black bags contain 1 light green bag. +plaid violet bags contain 1 faded magenta bag, 1 shiny bronze bag, 2 vibrant tomato bags. +posh bronze bags contain 4 shiny gold bags, 1 bright yellow bag, 1 dull cyan bag. +light red bags contain 3 dotted black bags, 5 pale coral bags. +striped red bags contain no other bags. +clear tan bags contain 2 faded brown bags, 1 bright brown bag, 2 bright gold bags. +dull turquoise bags contain 5 mirrored yellow bags, 3 wavy red bags, 5 faded purple bags, 4 clear green bags. +plaid yellow bags contain 4 dark red bags, 3 dull tomato bags, 5 faded violet bags. +dotted gold bags contain 2 dotted lime bags, 2 faded gray bags, 3 clear coral bags. +dull bronze bags contain 2 pale red bags, 3 dim indigo bags. +shiny green bags contain 2 pale red bags, 1 mirrored silver bag, 4 bright lime bags, 5 pale indigo bags. +bright black bags contain 2 striped plum bags, 1 clear black bag, 4 clear olive bags. +bright gold bags contain 3 wavy cyan bags, 1 dotted magenta bag, 1 muted salmon bag, 4 light maroon bags. +muted violet bags contain 5 wavy cyan bags, 4 dim tan bags, 1 posh gray bag, 5 vibrant brown bags. +dim turquoise bags contain 1 pale tomato bag, 2 dotted silver bags, 5 mirrored coral bags. +drab lime bags contain 5 shiny gold bags. +wavy bronze bags contain 1 shiny red bag, 4 dotted cyan bags. +vibrant purple bags contain 4 drab chartreuse bags, 4 dotted yellow bags. +plaid purple bags contain 2 drab beige bags, 3 pale aqua bags, 3 muted magenta bags. +faded brown bags contain 3 faded beige bags, 1 light chartreuse bag, 4 mirrored gold bags. +pale lavender bags contain 1 mirrored tomato bag, 5 wavy maroon bags, 4 wavy lime bags. +posh fuchsia bags contain 5 posh orange bags. +drab fuchsia bags contain 1 dim plum bag, 1 dark coral bag, 3 dark red bags. +striped crimson bags contain 5 pale orange bags, 5 faded beige bags, 5 faded brown bags. +wavy lime bags contain 5 dull crimson bags. +vibrant fuchsia bags contain 2 wavy white bags. +vibrant plum bags contain 4 dim salmon bags, 2 plaid tan bags, 3 dull blue bags. +muted cyan bags contain 3 striped beige bags. +clear teal bags contain 2 wavy aqua bags, 3 dotted plum bags. +dark maroon bags contain 1 light violet bag, 3 clear plum bags, 5 dotted fuchsia bags, 2 vibrant tomato bags. +dull black bags contain 5 muted olive bags. +light yellow bags contain 1 dull white bag, 5 dark aqua bags, 3 light purple bags, 4 dim green bags. +pale bronze bags contain 1 wavy aqua bag. +plaid red bags contain 5 pale plum bags, 2 muted brown bags, 2 dull bronze bags. +dim gray bags contain 2 muted lavender bags. +plaid gray bags contain 5 muted aqua bags. +vibrant blue bags contain 4 light tomato bags, 1 plaid beige bag. +clear blue bags contain 5 clear plum bags, 5 drab chartreuse bags. +dotted green bags contain 5 plaid white bags, 5 vibrant turquoise bags, 1 drab silver bag. +dull crimson bags contain 3 mirrored yellow bags, 3 posh red bags, 3 faded brown bags. +striped maroon bags contain 1 shiny magenta bag, 2 light brown bags, 4 dull green bags. +dark yellow bags contain 4 faded silver bags, 5 shiny lavender bags, 4 dim crimson bags, 2 plaid bronze bags. +pale indigo bags contain 4 plaid salmon bags, 3 striped purple bags, 5 pale magenta bags, 1 dotted lime bag. +faded maroon bags contain 5 light silver bags, 5 dim bronze bags, 4 faded tan bags, 5 striped crimson bags. +pale green bags contain 4 vibrant white bags. +muted maroon bags contain 2 light black bags, 2 mirrored fuchsia bags. +pale yellow bags contain 2 dull bronze bags, 4 bright maroon bags, 5 wavy cyan bags, 4 dotted lavender bags. +posh white bags contain 3 mirrored turquoise bags, 3 shiny aqua bags, 2 striped blue bags, 4 faded coral bags. +wavy orange bags contain 4 wavy crimson bags, 2 bright brown bags, 3 bright magenta bags, 1 dotted gold bag. +dark beige bags contain 3 muted white bags. +dotted salmon bags contain 5 dim bronze bags, 5 striped orange bags. +dotted fuchsia bags contain 1 striped red bag, 4 bright purple bags. +pale cyan bags contain 1 dull blue bag. +mirrored purple bags contain 5 light turquoise bags, 2 faded silver bags. +drab violet bags contain 1 vibrant turquoise bag, 2 muted chartreuse bags, 5 pale bronze bags. +wavy gray bags contain 1 dark purple bag, 4 muted green bags. +wavy magenta bags contain 5 dark white bags, 4 vibrant black bags, 4 muted coral bags. +pale plum bags contain 5 mirrored brown bags, 2 pale red bags. +light plum bags contain 4 dark tomato bags, 4 wavy gold bags. +pale aqua bags contain 1 striped red bag, 2 dim crimson bags, 3 mirrored orange bags. +muted green bags contain 1 mirrored yellow bag. +bright purple bags contain 5 light violet bags, 5 clear magenta bags, 1 faded lime bag. +dark green bags contain 2 shiny aqua bags. +dark orange bags contain 3 striped coral bags. +dotted chartreuse bags contain 1 bright lime bag, 1 light olive bag, 4 muted red bags, 1 posh chartreuse bag. +shiny chartreuse bags contain 1 bright salmon bag, 1 plaid indigo bag. +clear gold bags contain 5 dull lime bags, 4 shiny brown bags, 1 dull plum bag, 4 dull salmon bags. +shiny salmon bags contain 2 muted salmon bags, 2 dotted lavender bags. +striped cyan bags contain 3 drab tan bags, 5 dotted cyan bags, 1 posh aqua bag, 1 plaid magenta bag. +dark plum bags contain 1 clear orange bag, 2 striped black bags. +vibrant magenta bags contain 1 plaid tan bag, 3 muted bronze bags, 3 bright chartreuse bags. +clear beige bags contain 4 muted tan bags, 1 clear turquoise bag, 4 mirrored turquoise bags, 2 bright silver bags. +drab lavender bags contain 1 dotted cyan bag, 4 clear plum bags. +shiny coral bags contain 2 drab beige bags. +light bronze bags contain 2 mirrored plum bags, 2 light black bags. +vibrant yellow bags contain 4 vibrant coral bags, 5 mirrored olive bags, 1 light lime bag, 2 muted crimson bags. +vibrant salmon bags contain 4 faded beige bags, 2 faded olive bags, 1 pale brown bag. +dim tan bags contain 3 faded beige bags, 4 light tan bags. +vibrant silver bags contain 1 dark tomato bag. +striped salmon bags contain 5 faded brown bags. +shiny purple bags contain 1 pale lavender bag, 3 plaid black bags, 1 drab indigo bag. +light turquoise bags contain 4 dark silver bags. +dark chartreuse bags contain 5 dark silver bags. +mirrored indigo bags contain 5 mirrored gold bags, 1 dotted white bag. +faded olive bags contain 1 pale brown bag, 3 faded beige bags, 2 light chartreuse bags. +mirrored black bags contain 5 posh purple bags. +clear green bags contain 2 dark magenta bags, 5 faded gold bags, 4 striped teal bags, 4 dark purple bags. +bright beige bags contain 3 light olive bags, 3 wavy orange bags, 4 dotted lavender bags. +plaid brown bags contain 4 dull lavender bags, 3 drab gold bags. +vibrant chartreuse bags contain 1 bright bronze bag, 5 wavy crimson bags. +posh aqua bags contain 5 muted green bags, 2 dim green bags, 1 dim crimson bag, 1 posh red bag. +vibrant gold bags contain 5 wavy chartreuse bags, 3 drab gold bags, 2 striped blue bags, 3 posh yellow bags. +posh tan bags contain 1 shiny chartreuse bag, 2 drab bronze bags. +bright violet bags contain 1 pale lavender bag, 5 mirrored olive bags, 1 posh turquoise bag. +faded lime bags contain 5 pale brown bags, 4 faded black bags, 1 faded beige bag. +vibrant gray bags contain 3 vibrant chartreuse bags, 3 bright purple bags. +dull silver bags contain 5 pale tomato bags, 5 shiny turquoise bags, 2 mirrored yellow bags. +pale maroon bags contain 3 posh red bags, 1 plaid bronze bag, 5 striped red bags. +dull lavender bags contain 4 vibrant violet bags, 1 bright yellow bag, 3 bright aqua bags. +light aqua bags contain 5 vibrant turquoise bags. +striped violet bags contain 4 drab silver bags, 3 posh magenta bags, 3 wavy turquoise bags. +bright green bags contain 3 drab teal bags. +light coral bags contain 5 dotted violet bags, 4 pale chartreuse bags. +muted salmon bags contain 4 vibrant turquoise bags, 5 clear chartreuse bags, 1 dark fuchsia bag, 5 bright bronze bags. +wavy cyan bags contain 4 dim orange bags, 1 dull orange bag, 4 plaid indigo bags, 4 dim salmon bags. +shiny red bags contain 1 dim blue bag, 4 clear plum bags. +vibrant beige bags contain 3 posh red bags. +shiny maroon bags contain 3 striped tomato bags, 2 faded lime bags. +shiny aqua bags contain 3 bright yellow bags. +bright aqua bags contain 5 wavy lavender bags, 4 striped coral bags, 5 dotted cyan bags, 3 drab cyan bags. +dim olive bags contain 2 posh blue bags, 5 vibrant violet bags, 3 drab brown bags, 1 dull purple bag. +shiny silver bags contain 5 dim green bags, 4 dull cyan bags. +dim brown bags contain 1 wavy brown bag, 3 drab black bags. +dotted brown bags contain 3 drab crimson bags, 1 shiny red bag. +striped coral bags contain 4 striped red bags, 1 dotted cyan bag. +dotted plum bags contain 3 faded lime bags, 2 striped lavender bags, 2 wavy crimson bags, 2 faded brown bags. +light gold bags contain 1 light silver bag, 3 posh teal bags, 3 dark orange bags, 4 bright bronze bags. +dark tan bags contain 5 drab black bags, 2 plaid cyan bags, 3 faded yellow bags, 1 dim blue bag. +posh olive bags contain 4 drab olive bags, 5 dull tan bags, 1 wavy chartreuse bag, 5 muted magenta bags. +dull red bags contain 1 vibrant teal bag, 4 dim salmon bags, 1 bright violet bag, 1 dark lavender bag. +plaid turquoise bags contain 3 faded green bags, 5 wavy crimson bags. +plaid cyan bags contain 2 dull yellow bags, 2 dotted cyan bags, 1 light chartreuse bag, 2 faded green bags. +dull indigo bags contain 2 faded silver bags. +pale brown bags contain no other bags. +striped plum bags contain 5 dull lime bags, 2 muted white bags, 3 striped teal bags. +dotted coral bags contain 4 faded silver bags, 2 wavy aqua bags, 2 light chartreuse bags, 5 posh indigo bags. +mirrored beige bags contain 1 plaid black bag, 2 plaid tan bags, 2 pale bronze bags. +vibrant cyan bags contain 4 wavy beige bags, 1 shiny orange bag. +wavy fuchsia bags contain 5 pale maroon bags, 3 drab violet bags, 2 shiny orange bags. +drab silver bags contain 2 dark blue bags, 3 light chartreuse bags, 3 mirrored gold bags. +wavy turquoise bags contain 5 posh red bags, 4 striped teal bags. +bright cyan bags contain 4 bright silver bags, 1 muted gray bag, 5 faded aqua bags, 3 wavy aqua bags. +wavy green bags contain 4 clear violet bags, 4 dark olive bags, 2 clear magenta bags, 1 mirrored black bag. +mirrored gold bags contain 2 dark olive bags. +wavy gold bags contain 4 plaid indigo bags. +dotted yellow bags contain 3 dull orange bags, 2 faded green bags. +light beige bags contain 4 dull cyan bags. +bright crimson bags contain 1 faded tan bag, 1 faded chartreuse bag, 5 vibrant brown bags. +dotted bronze bags contain 5 striped white bags. +mirrored yellow bags contain 3 wavy crimson bags, 4 dark olive bags, 5 drab tan bags. +plaid lavender bags contain 1 light tomato bag, 5 dull blue bags, 2 wavy indigo bags, 3 bright gray bags. +drab purple bags contain 3 dotted plum bags, 5 drab olive bags, 1 drab tan bag, 3 dark black bags. +shiny lime bags contain 2 plaid bronze bags, 1 shiny gold bag. +drab chartreuse bags contain 2 bright bronze bags, 4 light teal bags, 1 mirrored yellow bag. +bright plum bags contain 3 drab turquoise bags. +light orange bags contain 1 shiny lavender bag, 2 dark fuchsia bags, 1 muted olive bag, 4 wavy olive bags. +striped beige bags contain 4 dull crimson bags, 5 dotted fuchsia bags. +wavy chartreuse bags contain 2 bright salmon bags, 5 faded green bags, 1 mirrored black bag. +striped tomato bags contain no other bags. +plaid aqua bags contain 1 light magenta bag, 3 pale white bags, 3 clear blue bags, 4 dull crimson bags. +plaid tan bags contain 3 dull green bags, 1 light silver bag, 5 dim orange bags, 1 dark blue bag. +dotted cyan bags contain 2 wavy black bags, 3 striped teal bags. +dull green bags contain 1 plaid magenta bag, 3 dull plum bags, 4 dim green bags. +faded purple bags contain 5 mirrored cyan bags, 1 dull beige bag, 4 vibrant purple bags. +dotted maroon bags contain 1 vibrant beige bag, 3 plaid magenta bags. +faded aqua bags contain 4 plaid gold bags, 1 plaid yellow bag, 2 bright lime bags. +pale lime bags contain 1 light blue bag. +dark indigo bags contain 1 light gold bag. +shiny orange bags contain 2 plaid black bags, 2 faded brown bags, 4 plaid indigo bags. +muted olive bags contain 1 wavy chartreuse bag. +muted purple bags contain 4 dotted silver bags. +plaid black bags contain 3 drab silver bags. +striped lavender bags contain 5 wavy crimson bags. +posh chartreuse bags contain 5 drab chartreuse bags. +clear purple bags contain 3 faded green bags, 2 bright gold bags. +dark crimson bags contain 4 plaid teal bags, 4 muted cyan bags. +clear silver bags contain 3 pale beige bags, 2 mirrored tomato bags. +dotted indigo bags contain 2 dark plum bags, 2 clear magenta bags, 3 light olive bags. +dull chartreuse bags contain 2 light turquoise bags, 3 drab brown bags. +bright brown bags contain 4 light purple bags, 1 vibrant coral bag. +dim salmon bags contain 2 dull salmon bags. +muted lime bags contain 4 muted violet bags, 5 shiny white bags. +vibrant lime bags contain 2 mirrored bronze bags, 1 dotted crimson bag, 5 dim yellow bags, 2 mirrored gold bags. +muted silver bags contain 1 striped orange bag, 3 drab purple bags. +mirrored bronze bags contain 4 dull bronze bags. +light olive bags contain 4 mirrored olive bags, 2 dim lime bags, 1 clear magenta bag. +vibrant tan bags contain 2 shiny teal bags. +posh red bags contain 2 bright bronze bags, 5 striped teal bags, 5 faded beige bags, 4 faded olive bags. +faded red bags contain 4 striped lavender bags, 4 posh red bags. +mirrored brown bags contain 3 dim salmon bags, 4 drab chartreuse bags, 1 wavy tomato bag. +dark gray bags contain 1 muted tan bag, 4 faded blue bags, 2 dim chartreuse bags. +dark white bags contain 4 vibrant lime bags, 4 pale olive bags. +striped silver bags contain 4 dim cyan bags. +clear salmon bags contain 5 pale magenta bags, 1 mirrored salmon bag. +pale white bags contain 5 wavy crimson bags, 4 plaid indigo bags, 5 striped crimson bags, 3 drab violet bags. +vibrant indigo bags contain 1 mirrored gold bag, 1 striped turquoise bag, 3 posh beige bags. +drab aqua bags contain 5 faded crimson bags, 3 wavy gold bags, 3 striped tomato bags. +clear brown bags contain 5 bright lavender bags. +posh indigo bags contain 5 mirrored red bags, 5 clear coral bags. +posh black bags contain 4 dim fuchsia bags, 5 muted olive bags, 3 mirrored red bags. +shiny lavender bags contain 2 muted aqua bags, 3 striped black bags, 3 wavy salmon bags, 3 mirrored purple bags. +vibrant bronze bags contain 1 bright tan bag, 5 faded beige bags, 5 pale red bags, 1 plaid cyan bag. +clear chartreuse bags contain 2 shiny gold bags, 1 wavy turquoise bag, 2 muted crimson bags. +drab tan bags contain no other bags. +posh gold bags contain 5 dotted beige bags, 1 striped crimson bag, 5 drab purple bags, 1 bright gray bag. +clear olive bags contain 3 dark tomato bags. +dim aqua bags contain 4 wavy black bags, 5 clear chartreuse bags, 5 clear aqua bags. +pale coral bags contain 2 shiny orange bags, 5 dark black bags, 3 vibrant coral bags. +drab blue bags contain 5 dull salmon bags. +vibrant white bags contain 2 mirrored yellow bags. +faded indigo bags contain 5 clear aqua bags. +posh turquoise bags contain 1 light purple bag, 4 mirrored salmon bags. +dotted orange bags contain 5 dark blue bags, 1 shiny lavender bag, 2 dim plum bags, 3 clear violet bags. +muted crimson bags contain 4 wavy crimson bags, 1 light magenta bag, 3 clear plum bags. +dim coral bags contain 1 vibrant red bag, 2 vibrant magenta bags. +mirrored plum bags contain 5 light olive bags. +dull violet bags contain 2 dim aqua bags. +faded violet bags contain 5 clear violet bags, 5 muted indigo bags, 3 clear red bags, 1 posh tan bag. +vibrant crimson bags contain 1 shiny crimson bag. +muted plum bags contain 3 drab beige bags, 4 posh maroon bags. +dim orange bags contain 5 bright salmon bags. +dim blue bags contain 1 mirrored black bag, 3 faded blue bags. +mirrored tan bags contain 5 plaid plum bags. +pale crimson bags contain 4 dim green bags, 2 pale fuchsia bags. +bright white bags contain 2 drab gold bags, 2 shiny maroon bags, 5 mirrored lime bags. +dim indigo bags contain 1 mirrored cyan bag, 1 wavy purple bag, 1 drab brown bag. +dotted violet bags contain 4 bright teal bags, 2 vibrant plum bags. +wavy indigo bags contain 2 drab silver bags, 1 muted chartreuse bag, 1 drab aqua bag, 3 mirrored teal bags. +dark cyan bags contain 1 muted magenta bag, 3 vibrant violet bags, 4 mirrored aqua bags, 5 drab violet bags. +posh maroon bags contain 5 muted chartreuse bags, 4 dark olive bags. +drab tomato bags contain 2 plaid tan bags, 2 posh purple bags, 2 posh beige bags. +wavy tan bags contain 5 light cyan bags, 5 muted brown bags, 5 mirrored coral bags, 5 light chartreuse bags. +faded bronze bags contain 4 dotted magenta bags. +pale blue bags contain 5 pale purple bags. +dim magenta bags contain 5 posh aqua bags, 5 dim crimson bags, 4 wavy gold bags, 2 shiny orange bags. +dark fuchsia bags contain 2 drab silver bags. +wavy white bags contain 4 vibrant turquoise bags, 2 clear violet bags, 1 dull salmon bag. +drab maroon bags contain 3 pale tomato bags, 2 dim chartreuse bags, 5 mirrored orange bags, 4 drab violet bags. +muted fuchsia bags contain 4 muted bronze bags, 4 plaid brown bags, 1 faded white bag. +plaid gold bags contain 3 vibrant bronze bags, 5 striped chartreuse bags. +faded green bags contain 2 dull cyan bags, 5 posh purple bags. +light indigo bags contain 5 mirrored tomato bags. +striped white bags contain 5 clear plum bags. +posh magenta bags contain 5 wavy crimson bags, 3 striped coral bags. +drab olive bags contain 4 striped orange bags. +plaid indigo bags contain 1 plaid turquoise bag. +dark brown bags contain 2 faded tan bags, 5 wavy green bags. +faded cyan bags contain 2 bright violet bags, 3 mirrored salmon bags. +dim lavender bags contain 2 mirrored fuchsia bags, 3 pale magenta bags, 2 dotted tan bags, 4 posh bronze bags. +dull maroon bags contain 3 dark silver bags, 5 dim plum bags. +dull teal bags contain 3 pale green bags. +shiny yellow bags contain 4 dotted fuchsia bags. +mirrored crimson bags contain 5 dotted plum bags. +drab beige bags contain 3 faded orange bags, 3 dark orange bags, 4 clear orange bags. +dull olive bags contain 2 vibrant bronze bags, 4 shiny chartreuse bags. +wavy red bags contain 2 wavy brown bags, 1 wavy olive bag, 3 striped cyan bags. +light gray bags contain 1 pale salmon bag, 2 plaid bronze bags, 5 dull yellow bags. +faded gray bags contain 4 muted green bags, 5 faded red bags, 3 muted magenta bags, 5 bright magenta bags. +drab indigo bags contain 1 posh gold bag, 2 dull lime bags, 1 pale orange bag. +bright yellow bags contain 4 posh red bags, 4 shiny gold bags. +drab bronze bags contain 4 dark indigo bags. +striped gold bags contain 3 faded yellow bags, 2 mirrored tomato bags, 1 bright lime bag. +muted gold bags contain 4 dim violet bags. +plaid olive bags contain 3 wavy fuchsia bags. +bright gray bags contain 4 bright bronze bags, 1 plaid white bag, 1 pale bronze bag. +clear turquoise bags contain 2 mirrored purple bags, 2 light gold bags, 4 dim cyan bags, 5 wavy olive bags. +wavy plum bags contain 4 bright yellow bags. +dull blue bags contain 4 dotted lavender bags. +posh gray bags contain 4 faded blue bags, 2 dull brown bags, 1 clear cyan bag. +pale black bags contain 5 dim cyan bags, 4 bright white bags. +wavy blue bags contain 3 faded olive bags, 5 bright lavender bags, 1 wavy black bag, 2 posh magenta bags. +posh beige bags contain 2 light cyan bags, 1 wavy violet bag, 1 muted olive bag. +clear plum bags contain 3 dull cyan bags. +drab cyan bags contain 5 plaid green bags. +vibrant aqua bags contain 5 posh maroon bags. +dim silver bags contain 5 shiny gold bags, 5 posh magenta bags, 1 light white bag. +posh brown bags contain 4 plaid salmon bags, 2 vibrant blue bags, 2 posh olive bags. +dark teal bags contain 1 faded brown bag. +clear white bags contain 5 vibrant tan bags, 5 light purple bags, 3 posh tan bags, 4 faded beige bags. +dim maroon bags contain 2 plaid chartreuse bags, 1 dim gray bag, 2 drab gold bags, 5 light white bags. +dull salmon bags contain 5 striped teal bags, 3 dark blue bags, 3 drab tan bags, 5 wavy crimson bags. +dull coral bags contain 1 faded red bag, 2 shiny teal bags, 3 bright gray bags, 1 pale brown bag. +dark violet bags contain 1 clear cyan bag, 4 mirrored beige bags, 2 vibrant turquoise bags. +vibrant maroon bags contain 1 muted magenta bag, 3 muted olive bags, 2 shiny turquoise bags. +posh orange bags contain 5 dark black bags, 3 pale maroon bags, 5 dull plum bags. +clear indigo bags contain 4 faded tan bags, 3 clear orange bags, 1 vibrant aqua bag. +clear gray bags contain 4 dull salmon bags, 5 dark magenta bags. +shiny turquoise bags contain 4 muted green bags, 4 vibrant beige bags, 5 mirrored cyan bags, 4 striped blue bags. +pale salmon bags contain 1 dark silver bag, 4 dim green bags. +striped gray bags contain 3 dark lavender bags. +dull yellow bags contain 2 dark blue bags, 4 striped tomato bags, 2 striped red bags, 3 pale brown bags. +posh yellow bags contain 1 dull green bag, 1 dull plum bag. +plaid white bags contain 3 plaid turquoise bags, 4 dotted cyan bags, 3 shiny gold bags, 5 clear plum bags. +faded orange bags contain 1 dull silver bag, 4 clear gray bags, 1 posh tomato bag, 2 wavy yellow bags. +dim violet bags contain 4 drab silver bags, 1 dull yellow bag, 3 faded blue bags. +light green bags contain 3 drab gold bags, 4 wavy purple bags. +dark magenta bags contain 2 light gold bags, 5 drab violet bags. +dark purple bags contain 5 plaid beige bags. +mirrored blue bags contain 2 plaid tan bags. +dim lime bags contain 1 dotted beige bag, 2 striped white bags, 5 dim blue bags, 5 wavy blue bags. +bright chartreuse bags contain 3 clear orange bags. +vibrant brown bags contain 3 mirrored violet bags, 5 dull green bags, 2 pale magenta bags. +drab salmon bags contain 4 muted magenta bags. +muted teal bags contain 5 dark black bags, 5 light gold bags. +striped lime bags contain 1 dim orange bag. +plaid crimson bags contain 4 dim teal bags, 3 dull salmon bags. +posh plum bags contain 5 pale gray bags. +light maroon bags contain 4 drab violet bags, 2 faded brown bags, 2 striped black bags, 3 striped coral bags. +pale gray bags contain 1 dark aqua bag, 3 mirrored tomato bags. +light chartreuse bags contain no other bags. +dim crimson bags contain 5 faded blue bags, 1 dark blue bag, 2 striped teal bags. +dim beige bags contain 5 wavy silver bags, 1 wavy orange bag, 1 dim lime bag, 2 mirrored lime bags. +bright teal bags contain 1 dull violet bag, 1 faded beige bag, 3 faded orange bags. +striped green bags contain 2 drab gold bags, 5 posh olive bags, 4 light indigo bags, 1 clear yellow bag. +striped black bags contain 4 striped crimson bags, 1 pale red bag. +plaid beige bags contain 3 pale tomato bags. +drab plum bags contain 4 striped coral bags, 3 dotted crimson bags. +plaid orange bags contain 4 bright aqua bags. +wavy maroon bags contain 1 dim orange bag, 1 dim violet bag, 4 posh chartreuse bags, 5 plaid tan bags. +dim purple bags contain 1 mirrored black bag, 1 plaid plum bag, 4 striped teal bags, 1 posh aqua bag. +mirrored red bags contain 2 shiny salmon bags, 3 bright salmon bags, 1 vibrant salmon bag. +striped brown bags contain 3 light lime bags, 1 drab black bag, 2 dull white bags, 5 drab lavender bags. +dim red bags contain 2 mirrored black bags. +clear lavender bags contain 5 pale fuchsia bags. +bright bronze bags contain 2 striped teal bags, 4 clear plum bags, 3 dim crimson bags, 5 faded black bags. +shiny violet bags contain 2 dark gold bags, 3 posh maroon bags. +bright lime bags contain 2 clear magenta bags, 3 dark blue bags, 4 striped lavender bags, 1 dull crimson bag. +mirrored silver bags contain 1 vibrant tomato bag, 4 dull salmon bags, 5 plaid green bags, 4 wavy brown bags. +dotted olive bags contain 5 faded beige bags. +posh tomato bags contain 2 faded purple bags. +posh teal bags contain 2 drab tan bags, 3 striped red bags, 3 dull salmon bags, 1 striped lavender bag. +shiny tomato bags contain 3 posh indigo bags. +dotted crimson bags contain 1 pale gray bag. +shiny indigo bags contain 1 pale beige bag. +plaid lime bags contain 1 light maroon bag. +mirrored turquoise bags contain 5 faded bronze bags. +drab crimson bags contain 1 vibrant plum bag. +dim black bags contain 3 muted tan bags, 3 drab silver bags, 4 dull white bags. +faded yellow bags contain 5 faded black bags. +faded white bags contain 2 wavy lavender bags, 1 shiny orange bag. +plaid tomato bags contain 2 shiny brown bags, 3 clear red bags. +drab white bags contain 5 dark yellow bags. +mirrored tomato bags contain 2 light gold bags, 1 mirrored gold bag, 4 dim plum bags. +plaid maroon bags contain 2 mirrored lime bags, 3 plaid salmon bags, 2 shiny chartreuse bags. +drab gold bags contain 1 dim plum bag, 2 mirrored violet bags. +muted orange bags contain 3 mirrored lime bags, 1 muted maroon bag, 5 drab violet bags, 2 posh green bags. +mirrored fuchsia bags contain 3 dim plum bags, 2 muted olive bags, 2 wavy white bags, 1 dotted cyan bag. +plaid silver bags contain 3 pale violet bags, 5 striped purple bags, 5 dull purple bags. +dotted silver bags contain 2 vibrant coral bags. +shiny cyan bags contain 4 mirrored teal bags, 4 faded magenta bags, 4 bright lime bags, 1 vibrant teal bag. +clear yellow bags contain 1 muted brown bag, 5 wavy lime bags. +muted red bags contain 5 muted coral bags, 2 light violet bags, 2 muted indigo bags, 4 dotted tan bags. +dull beige bags contain 5 plaid black bags, 2 pale white bags, 2 light violet bags, 1 pale crimson bag. +vibrant lavender bags contain 3 dark chartreuse bags, 4 bright lavender bags. +posh lime bags contain 1 shiny cyan bag, 4 dotted blue bags, 3 mirrored chartreuse bags. +shiny blue bags contain 1 dotted magenta bag. +muted yellow bags contain 4 plaid salmon bags, 4 dull tomato bags. +muted blue bags contain 5 wavy magenta bags, 3 vibrant gray bags. +dotted tan bags contain 1 wavy green bag, 1 dim plum bag. +drab red bags contain 2 dark olive bags, 5 mirrored tan bags, 3 dull coral bags, 4 plaid yellow bags. +dull tomato bags contain 2 clear aqua bags, 2 dark fuchsia bags, 2 light teal bags. +bright salmon bags contain 5 dark blue bags. +pale olive bags contain 1 light violet bag, 3 shiny bronze bags, 2 dotted magenta bags, 4 posh silver bags. +mirrored teal bags contain 4 posh chartreuse bags, 5 vibrant bronze bags. +mirrored chartreuse bags contain 3 striped olive bags, 3 mirrored maroon bags, 5 faded black bags, 3 pale plum bags. +pale orange bags contain 4 mirrored gold bags, 3 faded brown bags, 2 dark olive bags. +dark olive bags contain no other bags. +faded plum bags contain 5 bright green bags, 5 shiny beige bags, 2 vibrant indigo bags, 1 mirrored orange bag. +drab magenta bags contain 5 dark fuchsia bags, 5 striped salmon bags. +dark lavender bags contain 5 mirrored red bags, 4 vibrant aqua bags, 2 dotted tan bags. +shiny bronze bags contain 2 clear aqua bags, 2 dull salmon bags, 1 plaid turquoise bag, 3 plaid bronze bags. +faded magenta bags contain 2 mirrored gold bags, 5 dim orange bags. +light lavender bags contain 3 striped magenta bags, 5 light yellow bags. +clear tomato bags contain 3 dark bronze bags, 5 plaid aqua bags, 2 faded lime bags, 2 bright salmon bags. +clear lime bags contain 1 mirrored lavender bag, 3 bright silver bags, 3 pale teal bags. +light lime bags contain 4 dim crimson bags, 2 vibrant tomato bags, 4 posh red bags. +wavy yellow bags contain 3 muted chartreuse bags, 3 drab teal bags, 4 striped tomato bags. +dark silver bags contain 5 posh magenta bags, 1 plaid black bag, 3 faded brown bags. +bright maroon bags contain 5 dotted turquoise bags, 3 wavy silver bags, 2 dotted lime bags. +striped orange bags contain 5 striped coral bags, 3 posh teal bags. +bright silver bags contain 3 mirrored violet bags, 5 striped gold bags, 1 striped white bag, 4 clear chartreuse bags. +mirrored olive bags contain 4 light silver bags, 1 muted crimson bag. +dim gold bags contain 3 clear magenta bags. +shiny plum bags contain 5 muted olive bags, 5 dark turquoise bags, 2 dull green bags, 1 plaid magenta bag. +mirrored green bags contain 5 striped magenta bags, 1 light lime bag, 2 dim cyan bags. +wavy aqua bags contain 4 dull tan bags, 5 vibrant beige bags. +posh lavender bags contain 4 muted black bags. +dull lime bags contain 2 plaid black bags. +dim chartreuse bags contain 4 bright red bags. +muted lavender bags contain 5 faded red bags, 5 drab brown bags, 5 clear bronze bags. +muted coral bags contain 4 clear red bags, 3 vibrant maroon bags. +bright lavender bags contain 4 striped blue bags. diff --git a/7-handy_haversacs/src/main.rs b/7-handy_haversacs/src/main.rs new file mode 100644 index 0000000..fcbd21e --- /dev/null +++ b/7-handy_haversacs/src/main.rs @@ -0,0 +1,138 @@ +use std::fmt; + +use multimap::MultiMap; + +fn main() { + let input = include_str!("../data/input"); + let rules = parse_rules(input); + print!("{}", FmtRules(rules.clone())); + + let mut reverted_rules: Rules = Default::default(); + rules.iter_all().for_each(|(container, contained)| { + for c in contained { + reverted_rules.insert(c.1, (1, *container)); + } + }); + // dbg!(reverted_rules.clone()); + + let shiny_gold_spec = ("shiny", "gold"); + let mut shiny_gold_containers = find_containers( + &reverted_rules, + &shiny_gold_spec + ); + shiny_gold_containers.0.sort(); + shiny_gold_containers.0.dedup(); + // shiny_gold_containers also contain shiny_gold sadly... + dbg!(&shiny_gold_containers); + println!("Number of bags that can contain shiny gold ones : {}", shiny_gold_containers.0.len()-1); + + + //////// PART 2 ///////// + let shiny_gold_contained = find_containers(&rules, &shiny_gold_spec); + // Remove 1 because the shiny gold bag actually doesn't contain itself ;) + println!("Number of bags contained by shiny gold bags : {}", shiny_gold_contained.1 - 1); +} + +type BagSpec<'a> = (&'a str, &'a str); + +type Rules<'a> = MultiMap, (usize, BagSpec<'a>)>; +// Needed as you cannot implement a trait for an abstract type if not in current mod... +struct FmtRules<'a>(Rules<'a>); + +impl<'a> fmt::Display for FmtRules<'a> { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + for ((adjective,colour), rules) in self.0.iter_all() { + write!(f, "{} {} bags contain ", adjective, colour)?; + if rules.is_empty() { + write!(f, "no other bags.")?; + } else { + for (idx, (nb, (adj, colour))) in rules.iter().enumerate() { + if idx > 0 { write!(f, ", ")? } + write!(f, "{} {} {} {}", nb, adj, colour, if *nb > 1 { "bags" } else { "bag" })?; + } + writeln!(f, ".")?; + } + } + Ok(()) + } +} + +fn parse_rules(input: &str) -> Rules<'_> { + let mut rules: Rules = Default::default(); + + peg::parser! { + pub(crate) grammar parser() for str { + pub(crate) rule root(r: &mut Rules<'input>) + = (line(r) "." whitespace()*)* ![_] + + rule line(r: &mut Rules<'input>) + = bag:bag_spec() " contain " rules:rules() { + if let Some(rules) = rules { + for rule in rules { + r.insert(bag, rule); + } + } + } + + rule bag_spec() -> BagSpec<'input> + = adjective:name() " " colour:name() " bag" "s"? { + (adjective, colour) + } + + rule rules() -> Option)>> + = rules:rules1()+ {Some(rules)} + / "no other bags" { None } + + rule rules1() -> (usize, BagSpec<'input>) + = n:number() " " bag:bag_spec() ", "? { + (n, bag) + } + + rule name() -> &'input str + = $((!whitespace()[_])+) + + rule number() -> usize + = n:$(['0'..='9']+) { n.parse().unwrap() } + + rule whitespace() = quiet!{[' ' | '\n' | '\t']+} + } + } + + parser::root(input, &mut rules).unwrap(); + rules +} + +fn find_containers<'a>(rr: &'a Rules, start: &'a BagSpec) + -> (Vec>, usize) { + let mut res = vec![*start]; + let mut count = 0; + let containers = rr.get_vec(start); + + // for c in containers.iter().flat_map(|&v|v) { + for c in containers.into_iter().flatten().collect::>() { + let mut b = find_containers(rr, &(c.1)); + res.append(&mut b.0); + count += c.0 * b.1; + } + (res, count + 1) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_phase2() { + let input = r"shiny gold bags contain 2 dark red bags. +dark red bags contain 2 dark orange bags. +dark orange bags contain 2 dark yellow bags. +dark yellow bags contain 2 dark green bags. +dark green bags contain 2 dark blue bags. +dark blue bags contain 2 dark violet bags. +dark violet bags contain no other bags."; + let rules = parse_rules(input); + let shiny_gold_spec = ("shiny", "gold"); + let shiny_gold_contained = find_containers(&rules, &shiny_gold_spec); + assert_eq!(shiny_gold_contained.1 - 1, 126); + } +} \ No newline at end of file diff --git a/8-handheld_halting/.gitignore b/8-handheld_halting/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/8-handheld_halting/.gitignore @@ -0,0 +1 @@ +/target diff --git a/8-handheld_halting/Cargo.lock b/8-handheld_halting/Cargo.lock new file mode 100644 index 0000000..ebf266f --- /dev/null +++ b/8-handheld_halting/Cargo.lock @@ -0,0 +1,70 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "anyhow" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee67c11feeac938fae061b232e38e0b6d94f97a9df10e6271319325ac4c56a86" + +[[package]] +name = "handheld_halting" +version = "0.1.0" +dependencies = [ + "anyhow", + "thiserror", +] + +[[package]] +name = "proc-macro2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "991431c3519a3f36861882da93630ce66b52918dcf1b8e2fd66b397fc96f28df" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4211ce9909eb971f111059df92c45640aad50a619cf55cd76476be803c4c68e6" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "thiserror" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76cc616c6abf8c8928e2fdcc0dbfab37175edd8fb49a4641066ad1364fdab146" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9be73a2caec27583d0046ef3796c3794f868a5bc813db689eed00c7631275cd1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" diff --git a/8-handheld_halting/Cargo.toml b/8-handheld_halting/Cargo.toml new file mode 100644 index 0000000..4a1d48c --- /dev/null +++ b/8-handheld_halting/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "handheld_halting" +version = "0.1.0" +authors = ["Guilhem MARION "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0.37" +thiserror = "1.0.23" diff --git a/8-handheld_halting/data/input b/8-handheld_halting/data/input new file mode 100644 index 0000000..952208c --- /dev/null +++ b/8-handheld_halting/data/input @@ -0,0 +1,623 @@ +acc -17 +nop +318 +jmp +1 +acc -10 +jmp +394 +acc +43 +acc +47 +nop +570 +jmp +176 +acc -9 +jmp +322 +jmp +73 +acc +4 +acc -4 +jmp +460 +jmp +228 +acc +25 +acc +39 +jmp +50 +acc -12 +acc -14 +nop +275 +jmp +489 +acc -11 +jmp +338 +acc +21 +acc +10 +jmp +1 +acc +20 +jmp +445 +acc +7 +jmp +419 +acc -8 +acc +32 +jmp +181 +acc +19 +acc +5 +acc +46 +jmp +417 +acc +28 +acc +23 +acc +16 +jmp +225 +jmp +317 +jmp +309 +jmp +69 +acc -6 +acc -6 +jmp +127 +acc +49 +nop -38 +jmp +467 +acc +0 +acc -12 +acc -14 +jmp -46 +acc +14 +acc +2 +acc +2 +jmp +311 +acc +33 +jmp +364 +nop +234 +acc +24 +acc +37 +acc +18 +jmp +22 +jmp +303 +jmp +414 +jmp +318 +acc +22 +acc +27 +jmp +1 +jmp +150 +acc +34 +acc +15 +nop +200 +acc +6 +jmp +320 +nop +534 +acc +29 +jmp +147 +nop -20 +jmp +255 +jmp +10 +acc -15 +acc +3 +jmp +338 +nop +362 +acc -4 +jmp +1 +jmp +286 +acc -1 +jmp +497 +acc -4 +acc +23 +acc +4 +jmp +400 +acc +35 +acc +50 +jmp +133 +acc -17 +jmp -90 +jmp +7 +acc -17 +jmp +472 +acc +20 +jmp +280 +jmp +133 +jmp -15 +jmp +16 +acc -19 +acc -2 +jmp -64 +acc -17 +jmp +1 +jmp +385 +acc -5 +acc +34 +jmp +382 +acc +24 +acc -17 +acc +0 +acc +15 +jmp +466 +jmp +300 +acc +16 +jmp +302 +nop +479 +acc +16 +jmp +71 +acc +23 +jmp +1 +acc +8 +jmp +154 +jmp +410 +acc -8 +jmp +402 +acc +48 +acc +42 +acc +22 +acc +35 +jmp +50 +jmp -7 +acc -13 +acc +37 +acc +24 +jmp +243 +jmp +410 +acc -3 +acc +45 +jmp +416 +acc +2 +acc +25 +jmp -109 +jmp -41 +jmp +318 +acc -8 +acc -12 +jmp +169 +nop +393 +acc +7 +acc -12 +acc +35 +jmp +381 +acc +41 +nop -98 +acc +15 +acc -19 +jmp +218 +acc +24 +acc +47 +jmp +65 +acc +29 +jmp -129 +acc +23 +acc -13 +nop +60 +jmp -26 +nop -4 +acc -5 +acc +13 +nop -12 +jmp -13 +jmp -53 +acc +21 +jmp +276 +nop -27 +jmp +165 +acc +42 +nop +43 +jmp +1 +acc +26 +acc +22 +acc -3 +jmp +405 +acc +29 +nop -118 +acc +21 +nop -190 +jmp +217 +acc -1 +nop +223 +acc -8 +acc +45 +jmp +49 +acc +8 +acc +22 +jmp +209 +acc +44 +jmp +66 +acc +7 +acc -7 +acc +48 +jmp +318 +nop +398 +acc +2 +jmp +16 +nop +207 +nop +358 +acc +45 +acc +48 +jmp +267 +nop +248 +acc +26 +jmp +307 +acc +27 +jmp -197 +jmp -68 +acc +34 +acc +25 +acc -13 +jmp +133 +jmp -77 +acc -13 +acc +10 +jmp -193 +jmp -62 +acc +4 +acc -14 +jmp +261 +jmp +151 +jmp +208 +acc -10 +jmp +40 +acc +31 +jmp -216 +acc +23 +acc +34 +jmp +364 +nop +205 +acc -3 +acc +14 +jmp +59 +nop +359 +acc -4 +jmp +1 +jmp -248 +acc +47 +acc +35 +jmp +184 +acc +16 +nop -92 +acc -12 +jmp +354 +acc +27 +jmp -152 +acc -14 +acc -16 +acc +43 +jmp +147 +acc +45 +acc +24 +acc +6 +nop -46 +jmp +21 +acc +26 +jmp +1 +jmp +293 +acc -8 +acc +12 +acc -19 +acc -9 +jmp +94 +jmp +299 +acc +10 +acc -2 +jmp +75 +acc -7 +acc +3 +acc +47 +jmp +171 +acc +16 +acc +44 +acc -3 +jmp +14 +acc +30 +acc +34 +jmp -178 +acc +35 +nop -238 +acc +39 +jmp +1 +jmp -133 +acc +34 +acc -6 +jmp -276 +acc +1 +jmp -207 +acc +10 +jmp -43 +jmp -302 +acc -1 +nop -29 +jmp +1 +acc +17 +jmp -281 +acc +17 +jmp -109 +jmp +1 +acc +13 +nop -9 +jmp +245 +acc +5 +nop -15 +acc +3 +acc +7 +jmp +65 +acc -11 +jmp -313 +acc +47 +jmp +29 +jmp -289 +acc +18 +acc -17 +nop +73 +acc -12 +jmp +80 +acc +32 +acc -4 +acc +3 +jmp -126 +acc +16 +jmp -275 +nop -188 +acc -3 +acc +14 +jmp -155 +acc +33 +acc -19 +nop -166 +acc +20 +jmp +30 +nop -169 +acc +49 +nop +168 +jmp -24 +nop -345 +acc +34 +jmp -40 +jmp -56 +jmp +29 +jmp +191 +acc +24 +jmp +219 +acc +34 +acc +27 +acc +11 +jmp -260 +jmp -339 +acc +15 +nop +16 +jmp +1 +jmp +138 +jmp +1 +jmp +1 +jmp +14 +acc -11 +acc +45 +jmp -19 +acc +0 +jmp +27 +acc +0 +nop +128 +jmp -65 +nop -23 +jmp -318 +jmp -325 +jmp +1 +jmp -229 +jmp -270 +jmp -137 +acc +34 +acc +7 +jmp +1 +jmp -346 +acc +18 +jmp +37 +acc +40 +acc -16 +nop -146 +acc +35 +jmp -12 +acc +1 +acc +27 +acc +44 +acc +8 +jmp -276 +acc +16 +acc +42 +nop -342 +acc +13 +jmp -165 +acc -11 +acc -17 +acc -10 +jmp -26 +acc +10 +acc +43 +jmp -276 +acc +5 +acc +34 +acc +17 +acc -9 +jmp +99 +acc +29 +jmp -370 +acc -11 +jmp -412 +acc +47 +acc +21 +acc -12 +jmp -136 +jmp -124 +acc +12 +acc +0 +acc +25 +acc +27 +jmp -290 +acc +5 +acc +49 +acc +32 +nop +29 +jmp -202 +nop -296 +acc -12 +acc +9 +acc +21 +jmp +23 +jmp -345 +acc +26 +nop -123 +jmp -373 +nop +118 +jmp +43 +acc -15 +jmp -386 +jmp +1 +nop -370 +acc +47 +nop -141 +jmp -426 +acc +42 +acc +12 +acc +4 +nop -103 +jmp -122 +acc +23 +acc -4 +acc +11 +jmp -314 +jmp -73 +nop -1 +jmp -411 +acc +13 +acc +9 +nop -372 +jmp -293 +acc +46 +acc +3 +acc -1 +jmp +86 +acc +36 +jmp +100 +acc +27 +acc +49 +nop -4 +acc +47 +jmp -445 +acc +31 +acc +47 +acc -11 +acc +14 +jmp -181 +nop -438 +acc +31 +jmp -428 +nop -115 +nop -244 +jmp -464 +jmp -29 +nop -240 +jmp -241 +acc -12 +jmp -329 +nop +78 +acc +6 +jmp +1 +acc +49 +jmp -322 +jmp -133 +acc +20 +nop -83 +acc +35 +acc +29 +jmp -41 +acc +15 +jmp -46 +jmp -29 +acc +45 +acc -14 +acc +21 +jmp -366 +nop +84 +acc -6 +acc +25 +acc -17 +jmp -326 +acc -5 +nop -159 +acc +5 +jmp -171 +acc +42 +jmp -28 +acc +42 +acc -11 +acc +45 +acc +19 +jmp -305 +acc +38 +acc -13 +acc -16 +jmp -134 +acc +45 +jmp -256 +acc -15 +acc -18 +acc +28 +jmp -114 +acc -11 +acc +47 +nop -420 +jmp -90 +nop -330 +jmp +13 +acc -15 +acc +9 +jmp -159 +acc -12 +acc +0 +acc +0 +jmp -538 +acc +31 +acc +24 +acc +32 +acc -16 +jmp -95 +jmp -466 +acc +19 +acc +2 +jmp -172 +acc -12 +jmp -207 +acc +39 +acc +18 +acc +5 +jmp -211 +nop -507 +jmp +1 +jmp -197 +nop -227 +acc +28 +jmp -494 +acc +22 +acc +2 +acc -14 +jmp -377 +acc +8 +acc +29 +jmp -573 +acc -17 +acc +14 +acc +29 +acc +11 +jmp -351 +acc +9 +nop -540 +acc +30 +nop -344 +jmp -564 +acc -4 +nop -465 +jmp -293 +acc -18 +acc +5 +acc +29 +jmp -302 +acc -17 +acc +14 +acc +2 +acc -11 +jmp -527 +jmp -563 +acc +14 +acc +10 +jmp -505 +acc +43 +jmp -188 +nop -448 +acc +44 +acc +3 +acc +16 +jmp +1 diff --git a/8-handheld_halting/src/main.rs b/8-handheld_halting/src/main.rs new file mode 100644 index 0000000..a27d082 --- /dev/null +++ b/8-handheld_halting/src/main.rs @@ -0,0 +1,246 @@ +use std::str::FromStr; +use anyhow::Result; + +#[derive(Debug, Clone, PartialEq)] +enum ISet { + Acc, + Jmp, + Nop, +} + +#[derive(Debug, Clone)] +struct Instruction { + execd: bool, + instr: ISet, + arg: i64 +} + +#[derive(Debug, thiserror::Error)] +enum ParseError { + #[error("Expected {0}")] + Expected(&'static str) +} + + +impl FromStr for Instruction { + type Err = ParseError; + + fn from_str(s: &str) -> Result { + let mut tokens = s.lines() + .next() + .ok_or(ParseError::Expected("one line"))? + .split_whitespace(); + match tokens.next().ok_or(ParseError::Expected("instruction"))? { + "acc" => { + let arg = tokens + .next() + .ok_or(ParseError::Expected("acc argument"))? + .parse() + .unwrap(); + Ok(Instruction { + execd: false, + instr: ISet::Acc, + arg, + + }) + }, + "nop" => { + let arg = tokens + .next() + .ok_or(ParseError::Expected("acc argument"))? + .parse() + .unwrap(); + Ok(Instruction { + execd: false, + instr: ISet::Nop, + arg, // For part 1 at least NOP args are useless + }) + }, + "jmp" => { + let arg = tokens + .next() + .ok_or(ParseError::Expected("acc argument"))? + .parse() + .unwrap(); + Ok(Instruction { + execd: false, + instr: ISet::Jmp, + arg, + }) + }, + _ => Err(ParseError::Expected("acc, nop or jmp instruction")) + } + } +} + +impl Instruction { + fn exec(&mut self, pc: &mut usize, acc: &mut i64) { + self.execd = true; + match self.instr { + ISet::Acc => { + *acc += self.arg; + *pc += 1; + } + ISet::Jmp => { + // Expect this to panic hard if you underflow :3 + *pc = ((*pc as i64) + self.arg) as usize; + } + ISet::Nop => { + *pc += 1; + } + } + } +} + +#[derive(Debug, Clone)] +struct Program { + prog: Vec, + pc: usize, + acc: i64, +} + +impl Program { + fn load(s: &str) -> Result { + let loaded_program: Vec = s + .lines() + .map(|l| Instruction::from_str(l)) + .collect::, ParseError>>()?; + Ok( + Self { + prog: loaded_program, + pc: 0, + acc: 0, + } + ) + } + + fn reset(&mut self) { + self.pc = 0; + self.acc = 0; + for mut i in self.prog.iter_mut() { + i.execd = false; + } + } + + /// Returns whether execution finished : + /// Normally (true) - executing one instruction after the last one + /// Or abnormalaly (false) - looping forever or executing random + /// instructions + fn exec_until_loop(&mut self) -> bool { + let pc_stop = self.prog.len(); + loop { + // Terminate on infinite loop + if self.prog[self.pc].execd { + println!("Infinite loop !"); + return false; + } + + self.prog[self.pc].exec(&mut self.pc, &mut self.acc); + + // Terminate on success + if self.pc == pc_stop { + println!("Good pc !"); + return true; + } + // Terminate on corrupted pc + else if !(0..=pc_stop).contains(&(self.pc)) { + println!("Corrupted pc !"); + return false; + } + } + } + + fn find_corrupted_instruction(&mut self) -> Option { + // Test jmps -> nops + self.reset(); + for j in (0..self.prog.len()) + .filter(|&i| self.prog[i].instr == ISet::Jmp) + { + println!("Switch jmp-nop at pos {}", j); + let mut pclone = self.clone(); + pclone.prog[j].instr = ISet::Nop; + if pclone.exec_until_loop() { + return Some(pclone.acc); + } + } + // Test nops -> jmps + for n in (0..self.prog.len()) + .filter(|&i| self.prog[i].instr == ISet::Nop) + { + println!("Switch nop-jmp at pos {}", n); + let mut pclone = self.clone(); + pclone.prog[n].instr = ISet::Jmp; + if pclone.exec_until_loop() { + return Some(pclone.acc); + } + } + None + } +} + +fn main() { + let input = include_str!("../data/input"); + let mut prog = Program::load(input).unwrap(); + prog.exec_until_loop(); + println!("Acc before program gets into second loop : {}", prog.acc); + println!("Acc after the program is set to terminate : {}", prog.find_corrupted_instruction().unwrap()); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_nop() { + let input = r"nop +0"; + let mut prog = Program::load(input).unwrap(); + prog.exec_until_loop(); + assert_eq!(prog.acc, 0) + } + + #[test] + fn test_acc() { + let input = r"acc +5"; + let mut prog = Program::load(input).unwrap(); + prog.exec_until_loop(); + assert_eq!(prog.acc, 5) + } + + #[test] + fn test_jmp() { + let input = r"jmp +2 +acc +1 +acc +1"; + let mut prog = Program::load(input).unwrap(); + prog.exec_until_loop(); + assert_eq!(prog.acc, 1) + } + + #[test] + fn test_short_loop() { + let input = r"acc +1 +jmp +2 +acc +1 +acc +1 +jmp -4"; + let mut prog = Program::load(input).unwrap(); + prog.exec_until_loop(); + assert_eq!(prog.acc, 2) + } + + #[test] + fn test_exec() { + let input = r"nop +0 +acc +1 +jmp +4 +acc +3 +jmp -3 +acc -99 +acc +1 +jmp -4 +acc +6"; + let mut prog = Program::load(input).unwrap(); + prog.exec_until_loop(); + assert_eq!(prog.acc, 5) + } +} \ No newline at end of file diff --git a/9-encoding_error/.gitignore b/9-encoding_error/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/9-encoding_error/.gitignore @@ -0,0 +1 @@ +/target diff --git a/9-encoding_error/Cargo.toml b/9-encoding_error/Cargo.toml new file mode 100644 index 0000000..2c72f9a --- /dev/null +++ b/9-encoding_error/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "encoding_error" +version = "0.1.0" +authors = ["Guilhem MARION "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/9-encoding_error/data/input b/9-encoding_error/data/input new file mode 100644 index 0000000..20f8901 --- /dev/null +++ b/9-encoding_error/data/input @@ -0,0 +1,1000 @@ +16 +19 +41 +7 +20 +3 +45 +40 +37 +25 +5 +22 +43 +48 +4 +23 +18 +47 +28 +11 +10 +42 +35 +6 +34 +21 +8 +9 +12 +7 +13 +38 +14 +15 +16 +17 +20 +19 +60 +22 +24 +27 +46 +44 +28 +18 +70 +23 +42 +25 +26 +21 +29 +30 +91 +34 +31 +32 +33 +35 +43 +41 +45 +47 +65 +39 +48 +49 +46 +44 +50 +51 +52 +63 +53 +54 +89 +59 +61 +64 +66 +105 +87 +68 +74 +92 +93 +124 +83 +154 +97 +217 +176 +120 +94 +122 +111 +106 +107 +246 +127 +123 +173 +125 +199 +142 +210 +151 +293 +185 +175 +207 +177 +299 +201 +383 +232 +200 +219 +450 +394 +213 +229 +234 +296 +401 +372 +267 +324 +530 +317 +328 +854 +352 +730 +518 +586 +377 +414 +560 +932 +432 +541 +453 +759 +447 +442 +463 +619 +749 +584 +591 +729 +641 +1049 +645 +947 +766 +784 +994 +877 +1307 +824 +846 +1661 +874 +1094 +1374 +889 +905 +1689 +1026 +1340 +1175 +1225 +1229 +1375 +2049 +2532 +1411 +2064 +1640 +1550 +1608 +1670 +2196 +1713 +2221 +2279 +2255 +2845 +1794 +1915 +1931 +4328 +2201 +2366 +2400 +2404 +3051 +2899 +3045 +3402 +3968 +2961 +3158 +3190 +3220 +5333 +6241 +3507 +3914 +5120 +3709 +4186 +4194 +3725 +3846 +7760 +4567 +5421 +7524 +8645 +5365 +6363 +11492 +6006 +6697 +6378 +6119 +6348 +8641 +11438 +7216 +10087 +7232 +7434 +7555 +10686 +13797 +9211 +7571 +11799 +17642 +13351 +15861 +11371 +11484 +11713 +12125 +12354 +12384 +23283 +12467 +15559 +13564 +14448 +21336 +21571 +24509 +14666 +23755 +15126 +19284 +25064 +27358 +18942 +22855 +28026 +25918 +23084 +43793 +24097 +23838 +46367 +24738 +24851 +26915 +26031 +50015 +28012 +29114 +52869 +29792 +47310 +47935 +38226 +34068 +44006 +41797 +42026 +42780 +46693 +46922 +48576 +47181 +74607 +48835 +48689 +52946 +89732 +54043 +54927 +63860 +116729 +57126 +76295 +68018 +71589 +81006 +206461 +82644 +85803 +83823 +88978 +113615 +95757 +166027 +143775 +95870 +102732 +97524 +103762 +103616 +126516 +108970 +135933 +165273 +120986 +125144 +184622 +162098 +139607 +152595 +163650 +166467 +264830 +169626 +221014 +198602 +384664 +204840 +193394 +199486 +493634 +324229 +201140 +207378 +229956 +278596 +234114 +414408 +246130 +294770 +264751 +292202 +301705 +476824 +420500 +330117 +428392 +368228 +493372 +391996 +392880 +464237 +400772 +394534 +441492 +408518 +431096 +575606 +437334 +464070 +480244 +498865 +716113 +771594 +918316 +556953 +593907 +820388 +825630 +1346708 +762762 +1012940 +760224 +823976 +784876 +839614 +803052 +795306 +878826 +1244544 +845852 +868430 +901404 +1826952 +944314 +979109 +1055818 +1150860 +1739620 +1317177 +1957222 +1378783 +1586738 +2882770 +1522986 +2903915 +1545100 +1555530 +1580182 +2737598 +2424390 +1671482 +1641158 +1714282 +1747256 +1769834 +1812744 +2218581 +1923423 +3078516 +3350016 +2206678 +2468037 +3969490 +2695960 +2901769 +4142004 +7319506 +3100630 +3103168 +3186258 +3125282 +3135712 +3221340 +3932863 +3953934 +3312640 +4714513 +3461538 +5321749 +3582578 +3736167 +4825192 +4902638 +4674715 +5108447 +5668216 +8793498 +6214409 +5799128 +6002399 +9260666 +8668447 +6203798 +9822960 +6260994 +6346622 +6357052 +6533980 +6774178 +9463937 +16238115 +8485216 +11117047 +11208695 +7318745 +15015069 +11021337 +12427192 +9783162 +11467344 +11670615 +12737778 +11801527 +12002926 +12263393 +12464792 +12550420 +12703674 +16169582 +24740704 +12880602 +12891032 +19693911 +14092923 +15803961 +18268378 +17101907 +18340082 +18527440 +24097807 +20804499 +29896884 +21250506 +22674194 +25441452 +23472142 +23804453 +35735535 +37205496 +36695485 +26983955 +25254094 +25584276 +34697022 +34331401 +25771634 +28694993 +42331893 +31194830 +32905868 +35370285 +55135900 +36867522 +39331939 +46772001 +66315894 +43924700 +46504600 +47928288 +47276595 +48726236 +49388729 +50838370 +80792222 +51025728 +52755589 +51355910 +72237807 +86103940 +54466627 +56966464 +59889823 +83372122 +70526769 +68276153 +103738465 +76199461 +83256639 +85836539 +100683877 +90429300 +116162507 +95893329 +95204883 +98114965 +100227099 +100414457 +123263535 +108322374 +102381638 +104111499 +200641556 +168503252 +111433091 +114356450 +171210646 +138802922 +144475614 +170941226 +151532792 +159456100 +162036000 +169093178 +176265839 +185634183 +250236013 +191098212 +196307786 +195431982 +266147499 +248587113 +202796095 +267778474 +206493137 +322474018 +215544590 +225789541 +253159372 +283278536 +303931714 +340783400 +290335714 +375000690 +474376748 +310988892 +468912719 +388430278 +453032108 +372573625 +376732395 +518014487 +386530194 +398228077 +401925119 +472640636 +418340685 +409289232 +520937846 +459652509 +478948913 +536778433 +865479107 +678932404 +587210250 +594267428 +715784090 +466456641 +1108148096 +1105224737 +1325131616 +846182703 +749306020 +945405554 +770801702 +763262589 +816568762 +2040915706 +800153196 +946067665 +827629917 +868941741 +875745873 +926109150 +1353347195 +1003235074 +1053666891 +1442194993 +1924716858 +1060724069 +1182240731 +1646547575 +1215762661 +1520107722 +1512568609 +1534064291 +1549459216 +1773697582 +1853820087 +1696910852 +1563415785 +1692314635 +1627783113 +2455413030 +1753739067 +1744687614 +1801855023 +1878980947 +1929344224 +2185475805 +2114390960 +2242964800 +4200100644 +2276486730 +4155467677 +2398003392 +2735870383 +3330153621 +3806705595 +3204883244 +5606640351 +3241773851 +4152323882 +3191198898 +3255730420 +3308103399 +3320097748 +3372470727 +4142691006 +4993053921 +3808325171 +5718101140 +6079081591 +4114820029 +4299866765 +5319274204 +4519451530 +4674490122 +5012357113 +5133873775 +5589202290 +6043973782 +8389604195 +6396082142 +6432972749 +8926738099 +6446929318 +10753571713 +6499302297 +9026204539 +6628201147 +6692568475 +7180795898 +8634271559 +7923145200 +8108191936 +8819318295 +8414686794 +8789310151 +8974356887 +9193941652 +9531808643 +9686847235 +10146230888 +10723076065 +11633176072 +15237915434 +19556321272 +12829054891 +12932275046 +13680098195 +15236239469 +15133573856 +20409923300 +15107255269 +25313274267 +14800760411 +15103941098 +16031337136 +16337831994 +17203996945 +17793675182 +17389043681 +17763667038 +18168298539 +18725750295 +26920852324 +40551189701 +20869306953 +28837173017 +27936310160 +33698361844 +25761329937 +26509153086 +31138592405 +28480858606 +29904701509 +34593040626 +46600840055 +29908015680 +30832097547 +31135278234 +31441773092 +32369169130 +33726875675 +46226216698 +35152710719 +53878461014 +35931965577 +63603063353 +52682182261 +46630636890 +47378460039 +59071588394 +52270483023 +53697640097 +54242188543 +95003553971 +54990011692 +58385560115 +59812717189 +67067243811 +86431784784 +67373738669 +113293460509 +61967375781 +95044836445 +114061600086 +66096044805 +68879586394 +71084676296 +113697880701 +82562602467 +83310425616 +94009096929 +98901119913 +99648943062 +101076100136 +106512671566 +108687651789 +107939828640 +109232200235 +200521768495 +113375571807 +118198277304 +125908761994 +128063420586 +167172144941 +136253325063 +184386525752 +130846962175 +134975631199 +137180721101 +139964262690 +270811224865 +153647278763 +165873028083 +336775093558 +177319522545 +200725043198 +198550062975 +208336594851 +207588771702 +250556292908 +216627480429 +217172028875 +222607772042 +559382865600 +249628896870 +268027683276 +253972182580 +258910382761 +265822593374 +317283785235 +329397025150 +348300857541 +272156352300 +533850276650 +293611541453 +713030144363 +330966801308 +415501924953 +449475874845 +375869585520 +424216252131 +425508623726 +415925366553 +424760800577 +433799509304 +439235252471 +439779800917 +481518154803 +521999865856 +531066735061 +512882565341 +547583724033 +524732976135 +755183053439 +754157825727 +565767893753 +1072316700168 +1053066600917 +624578342761 +669481126973 +706836386828 +746468726261 +1058377852065 +800085837651 +791794952073 +840141618684 +840686167130 +1371047069022 +1285224560788 +1090500869888 +1193393078198 +921297955720 +994400720144 +1034882431197 +1235249020726 +1331414729589 +1113351617786 +1190346236514 +1464719961445 +1312236620014 +1272604280581 +1640772004781 +1294059469734 +1376317513801 +1415949853234 +1765214238893 +1538263678334 +1858463689716 +1591880789724 +1631936570757 +2304861580129 +2557828841369 +1915698675864 +2193902236301 +2225228667711 +2107752337930 +2111644192234 +2507853301307 +2328941900931 +3884170815108 +2303697854300 +2385955898367 +2462950517095 +2566663750315 +2584840900595 +2648921794382 +3234781203517 +4017892469124 +2792267367035 +3223817360481 +3130144468058 +5539642783646 +3547635246621 +3507579465588 +3739688908687 +4023451013794 +4027342868098 +4219396530164 +4301654574231 +6608291914389 +5731670661788 +6299846832623 +4714897799298 +4791892418026 +6027048570552 +5620737101884 +4848906415462 +5255217884130 +5151504650910 +5233762694977 +10054391438650 +5922411835093 +9470047081714 +6016084727516 +6677779714679 +6637723933646 +7055214712209 +7287324155308 +10794903620896 +16354238271273 +8934294329462 +9068302945626 +8521051104395 +11148753248085 +9506790217324 +17341715593958 +12704828285231 +9563804214760 +11829284365589 +10000411066372 +10082669110439 +17589354050021 +10385267345887 +11073916486003 +11156174530070 +18361240641311 +11938496562609 +12653808661162 +12693864442195 +13315503648325 +15706026879272 +18436077403393 +16794114372632 +26009368090520 +30035580036153 +18906318450282 +18027841321719 +18084855319155 +20580706703327 +19070594432084 +28470122665042 +19564215281132 +19646473325199 +27868030858635 +38007713966510 +20467936456326 +34878969691787 +21459183831890 +23727725147165 +31560127111444 +54525443016986 +24592305223771 +43351083684478 +51124342392576 +29021530527597 +58606694838952 +34821955694351 +35700432822914 +45079962522604 +49929306496932 +36934159772001 +37155449751239 +58475650422836 +38634809713216 +38717067757283 +41105657157089 +60883174898404 +40114409781525 +41927120288216 +44195661603491 +45060241680097 +45186908979055 +56152432335215 +48320030370936 +53613835751368 +59414260918122 +78173039378829 +82041530069741 +79082570039455 +63843486221948 +70522388517265 +74936365475876 diff --git a/9-encoding_error/src/main.rs b/9-encoding_error/src/main.rs new file mode 100644 index 0000000..e7a11a9 --- /dev/null +++ b/9-encoding_error/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + println!("Hello, world!"); +}