Progress to day 11
This commit is contained in:
5
10-adapter_array/Cargo.lock
generated
Normal file
5
10-adapter_array/Cargo.lock
generated
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
[[package]]
|
||||||
|
name = "adapter_array"
|
||||||
|
version = "0.1.0"
|
||||||
9
10-adapter_array/Cargo.toml
Normal file
9
10-adapter_array/Cargo.toml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
[package]
|
||||||
|
name = "adapter_array"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Guilhem MARION <gmarion@netc.fr>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
89
10-adapter_array/data/input
Normal file
89
10-adapter_array/data/input
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
67
|
||||||
|
118
|
||||||
|
90
|
||||||
|
41
|
||||||
|
105
|
||||||
|
24
|
||||||
|
137
|
||||||
|
129
|
||||||
|
124
|
||||||
|
15
|
||||||
|
59
|
||||||
|
91
|
||||||
|
94
|
||||||
|
60
|
||||||
|
108
|
||||||
|
63
|
||||||
|
112
|
||||||
|
48
|
||||||
|
62
|
||||||
|
125
|
||||||
|
68
|
||||||
|
126
|
||||||
|
131
|
||||||
|
4
|
||||||
|
1
|
||||||
|
44
|
||||||
|
77
|
||||||
|
115
|
||||||
|
75
|
||||||
|
89
|
||||||
|
7
|
||||||
|
3
|
||||||
|
82
|
||||||
|
28
|
||||||
|
97
|
||||||
|
130
|
||||||
|
104
|
||||||
|
54
|
||||||
|
40
|
||||||
|
80
|
||||||
|
76
|
||||||
|
19
|
||||||
|
136
|
||||||
|
31
|
||||||
|
98
|
||||||
|
110
|
||||||
|
133
|
||||||
|
84
|
||||||
|
2
|
||||||
|
51
|
||||||
|
18
|
||||||
|
70
|
||||||
|
12
|
||||||
|
120
|
||||||
|
47
|
||||||
|
66
|
||||||
|
27
|
||||||
|
39
|
||||||
|
109
|
||||||
|
61
|
||||||
|
34
|
||||||
|
121
|
||||||
|
38
|
||||||
|
96
|
||||||
|
30
|
||||||
|
83
|
||||||
|
69
|
||||||
|
13
|
||||||
|
81
|
||||||
|
37
|
||||||
|
119
|
||||||
|
55
|
||||||
|
20
|
||||||
|
87
|
||||||
|
95
|
||||||
|
29
|
||||||
|
88
|
||||||
|
111
|
||||||
|
45
|
||||||
|
46
|
||||||
|
14
|
||||||
|
11
|
||||||
|
8
|
||||||
|
74
|
||||||
|
101
|
||||||
|
73
|
||||||
|
56
|
||||||
|
132
|
||||||
|
23
|
||||||
97
10-adapter_array/src/main.rs
Normal file
97
10-adapter_array/src/main.rs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
fn solve_part1(folts: &[usize]) -> (usize, usize) {
|
||||||
|
let counts = folts
|
||||||
|
.iter()
|
||||||
|
.fold((0, HashMap::<usize, usize>::new()), |mut acc, elt| {
|
||||||
|
match elt - acc.0 {
|
||||||
|
x if (1..=3).contains(&x) => {
|
||||||
|
if let Some(count) = acc.1.get_mut(&x) {
|
||||||
|
*count += 1;
|
||||||
|
} else {
|
||||||
|
acc.1.insert(x, 1);
|
||||||
|
}
|
||||||
|
(*elt, acc.1)
|
||||||
|
}
|
||||||
|
_ => unreachable!()
|
||||||
|
}
|
||||||
|
}).1;
|
||||||
|
// Counts of 3 should be incremented by one given last adapter's spec
|
||||||
|
(*counts.get(&1).unwrap(), *counts.get(&3).unwrap() + 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn solve_part2(folts: &[usize]) -> usize {
|
||||||
|
let mut counts: Vec<usize> = std::iter::once(0usize)
|
||||||
|
.chain(folts
|
||||||
|
.iter().copied())
|
||||||
|
.collect();
|
||||||
|
counts.sort_unstable();
|
||||||
|
counts.push(counts.iter().max().unwrap() + 3);
|
||||||
|
// Map <folt, nb of moves from folt>
|
||||||
|
let mut diffs: HashMap<usize, usize> = HashMap::new();
|
||||||
|
diffs.insert(*counts.iter().max().unwrap(), 1);
|
||||||
|
for &foltage in counts.iter().rev().skip(1) {
|
||||||
|
let possible_steps = counts
|
||||||
|
.iter()
|
||||||
|
.filter(|&x| (1..=3).contains(&(*x as isize - foltage as isize)));
|
||||||
|
diffs.insert(foltage, possible_steps.map(|x| diffs.get(x).unwrap()).sum());
|
||||||
|
}
|
||||||
|
// dbg!(&diffs);
|
||||||
|
*diffs.get(&0).unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let input = include_str!("../data/input");
|
||||||
|
let mut folts: Vec<_> = input.lines().map(|l| l.parse::<usize>().unwrap()).collect();
|
||||||
|
folts.sort();
|
||||||
|
let counts = solve_part1(&folts);
|
||||||
|
let counts2 = solve_part2(&folts);
|
||||||
|
|
||||||
|
println!("Counts : {:?}, solution {}",
|
||||||
|
counts,
|
||||||
|
counts.0 * counts.1);
|
||||||
|
println!("Number of paths possible : {}", counts2);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_step1() {
|
||||||
|
let input = r"28
|
||||||
|
33
|
||||||
|
18
|
||||||
|
42
|
||||||
|
31
|
||||||
|
14
|
||||||
|
46
|
||||||
|
20
|
||||||
|
48
|
||||||
|
47
|
||||||
|
24
|
||||||
|
23
|
||||||
|
49
|
||||||
|
45
|
||||||
|
19
|
||||||
|
38
|
||||||
|
39
|
||||||
|
11
|
||||||
|
1
|
||||||
|
32
|
||||||
|
25
|
||||||
|
35
|
||||||
|
8
|
||||||
|
17
|
||||||
|
7
|
||||||
|
9
|
||||||
|
4
|
||||||
|
2
|
||||||
|
34
|
||||||
|
10
|
||||||
|
3";
|
||||||
|
let mut folts: Vec<_> = input.lines().map(|l| l.parse::<usize>().unwrap()).collect();
|
||||||
|
folts.sort();
|
||||||
|
assert_eq!(solve_part1(&folts), (22, 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
1
10-adapter_array/target/.rustc_info.json
Normal file
1
10-adapter_array/target/.rustc_info.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"rustc_fingerprint":4191169781050156317,"outputs":{"13789308117277828956":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/arvil/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nfeature=\"cargo-clippy\"\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""],"4476964694761187371":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/arvil/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""],"1164083562126845933":["rustc 1.46.0 (04488afe3 2020-08-24)\nbinary: rustc\ncommit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9\ncommit-date: 2020-08-24\nhost: x86_64-unknown-linux-gnu\nrelease: 1.46.0\nLLVM version: 10.0\n",""],"16929990295604814582":["___\n",""],"2196823701345282402":["___\nlib___.rlib\nlib___.so\nlib___.so\nlib___.a\nlib___.so\n/home/arvil/.rustup/toolchains/stable-x86_64-unknown-linux-gnu\ndebug_assertions\nproc_macro\ntarget_arch=\"x86_64\"\ntarget_endian=\"little\"\ntarget_env=\"gnu\"\ntarget_family=\"unix\"\ntarget_feature=\"fxsr\"\ntarget_feature=\"sse\"\ntarget_feature=\"sse2\"\ntarget_os=\"linux\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"unknown\"\nunix\n",""],"9859703030026944830":["___\n",""]},"successes":{}}
|
||||||
3
10-adapter_array/target/CACHEDIR.TAG
Normal file
3
10-adapter_array/target/CACHEDIR.TAG
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Signature: 8a477f597d28d172789f06886806bc55
|
||||||
|
# This file is a cache directory tag created by cargo.
|
||||||
|
# For information about cache directory tags see https://bford.info/cachedir/
|
||||||
0
10-adapter_array/target/debug/.cargo-lock
Normal file
0
10-adapter_array/target/debug/.cargo-lock
Normal file
@@ -0,0 +1 @@
|
|||||||
|
9f0077979e3bf484
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"rustc":7210524046684111384,"features":"[]","target":1974148002437621829,"profile":1613559695681135254,"path":1036222786711178230,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/adapter_array-2420e82e6f99395b/dep-bin-adapter_array"}}],"rustflags":[],"metadata":14252281678896127600,"config":0}
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ea7345836e0e7445
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"rustc":7210524046684111384,"features":"[]","target":1974148002437621829,"profile":18074012566298724745,"path":1036222786711178230,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/adapter_array-2cecd1a04665a8d4/dep-bin-adapter_array"}}],"rustflags":[],"metadata":14252281678896127600,"config":0}
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
{"message":"function is never used: `solve_part2`","code":{"code":"dead_code","explanation":null},"level":"warning","spans":[{"file_name":"src/main.rs","byte_start":716,"byte_end":727,"line_start":23,"line_end":23,"column_start":4,"column_end":15,"is_primary":true,"text":[{"text":"fn solve_part2(folts: &[usize]) -> usize {","highlight_start":4,"highlight_end":15}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}],"children":[{"message":"`#[warn(dead_code)]` on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null}],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: function is never used: `solve_part2`\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:23:4\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m23\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0mfn solve_part2(folts: &[usize]) -> usize {\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[33m^^^^^^^^^^^\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: `#[warn(dead_code)]` on by default\u001b[0m\n\n"}
|
||||||
|
{"message":"1 warning emitted","code":null,"level":"warning","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[33mwarning\u001b[0m\u001b[0m\u001b[1m: 1 warning emitted\u001b[0m\n\n"}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
1f74730b1c949727
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"rustc":7210524046684111384,"features":"[]","target":1974148002437621829,"profile":10655494245791646288,"path":1036222786711178230,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/adapter_array-6533e9e7a9619d0a/dep-test-bin-adapter_array"}}],"rustflags":[],"metadata":14252281678896127600,"config":0}
|
||||||
Binary file not shown.
@@ -0,0 +1 @@
|
|||||||
|
This file has an mtime of when this was started.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
56ffdf1b4170cfca
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"rustc":7210524046684111384,"features":"[]","target":1974148002437621829,"profile":8341259748240011191,"path":1036222786711178230,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/adapter_array-e65c4783fd998dbd/dep-test-bin-adapter_array"}}],"rustflags":[],"metadata":14252281678896127600,"config":0}
|
||||||
BIN
10-adapter_array/target/debug/adapter_array
Executable file
BIN
10-adapter_array/target/debug/adapter_array
Executable file
Binary file not shown.
1
10-adapter_array/target/debug/adapter_array.d
Normal file
1
10-adapter_array/target/debug/adapter_array.d
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/home/arvil/code/aoc20/10-adapter_array/target/debug/adapter_array: /home/arvil/code/aoc20/10-adapter_array/data/input /home/arvil/code/aoc20/10-adapter_array/src/main.rs
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/home/arvil/code/aoc20/10-adapter_array/target/debug/deps/adapter_array-2420e82e6f99395b.rmeta: src/main.rs src/../data/input
|
||||||
|
|
||||||
|
/home/arvil/code/aoc20/10-adapter_array/target/debug/deps/adapter_array-2420e82e6f99395b.d: src/main.rs src/../data/input
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
src/../data/input:
|
||||||
BIN
10-adapter_array/target/debug/deps/adapter_array-2cecd1a04665a8d4
Executable file
BIN
10-adapter_array/target/debug/deps/adapter_array-2cecd1a04665a8d4
Executable file
Binary file not shown.
@@ -0,0 +1,6 @@
|
|||||||
|
/home/arvil/code/aoc20/10-adapter_array/target/debug/deps/adapter_array-2cecd1a04665a8d4: src/main.rs src/../data/input
|
||||||
|
|
||||||
|
/home/arvil/code/aoc20/10-adapter_array/target/debug/deps/adapter_array-2cecd1a04665a8d4.d: src/main.rs src/../data/input
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
src/../data/input:
|
||||||
BIN
10-adapter_array/target/debug/deps/adapter_array-6533e9e7a9619d0a
Executable file
BIN
10-adapter_array/target/debug/deps/adapter_array-6533e9e7a9619d0a
Executable file
Binary file not shown.
@@ -0,0 +1,6 @@
|
|||||||
|
/home/arvil/code/aoc20/10-adapter_array/target/debug/deps/adapter_array-6533e9e7a9619d0a: src/main.rs src/../data/input
|
||||||
|
|
||||||
|
/home/arvil/code/aoc20/10-adapter_array/target/debug/deps/adapter_array-6533e9e7a9619d0a.d: src/main.rs src/../data/input
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
src/../data/input:
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
/home/arvil/code/aoc20/10-adapter_array/target/debug/deps/adapter_array-e65c4783fd998dbd.rmeta: src/main.rs src/../data/input
|
||||||
|
|
||||||
|
/home/arvil/code/aoc20/10-adapter_array/target/debug/deps/adapter_array-e65c4783fd998dbd.d: src/main.rs src/../data/input
|
||||||
|
|
||||||
|
src/main.rs:
|
||||||
|
src/../data/input:
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user