heh
2015/14
bendn 12 months ago
parent 77b5f4d · commit f43ba27
-rw-r--r--src/inp.txt66
-rw-r--r--src/main.rs74
-rw-r--r--src/util.rs2
3 files changed, 46 insertions, 96 deletions
diff --git a/src/inp.txt b/src/inp.txt
index a6f9c66..60521d7 100644
--- a/src/inp.txt
+++ b/src/inp.txt
@@ -1,56 +1,10 @@
-Alice would gain 2 happiness units by sitting next to Bob.
-Alice would gain 26 happiness units by sitting next to Carol.
-Alice would lose 82 happiness units by sitting next to David.
-Alice would lose 75 happiness units by sitting next to Eric.
-Alice would gain 42 happiness units by sitting next to Frank.
-Alice would gain 38 happiness units by sitting next to George.
-Alice would gain 39 happiness units by sitting next to Mallory.
-Bob would gain 40 happiness units by sitting next to Alice.
-Bob would lose 61 happiness units by sitting next to Carol.
-Bob would lose 15 happiness units by sitting next to David.
-Bob would gain 63 happiness units by sitting next to Eric.
-Bob would gain 41 happiness units by sitting next to Frank.
-Bob would gain 30 happiness units by sitting next to George.
-Bob would gain 87 happiness units by sitting next to Mallory.
-Carol would lose 35 happiness units by sitting next to Alice.
-Carol would lose 99 happiness units by sitting next to Bob.
-Carol would lose 51 happiness units by sitting next to David.
-Carol would gain 95 happiness units by sitting next to Eric.
-Carol would gain 90 happiness units by sitting next to Frank.
-Carol would lose 16 happiness units by sitting next to George.
-Carol would gain 94 happiness units by sitting next to Mallory.
-David would gain 36 happiness units by sitting next to Alice.
-David would lose 18 happiness units by sitting next to Bob.
-David would lose 65 happiness units by sitting next to Carol.
-David would lose 18 happiness units by sitting next to Eric.
-David would lose 22 happiness units by sitting next to Frank.
-David would gain 2 happiness units by sitting next to George.
-David would gain 42 happiness units by sitting next to Mallory.
-Eric would lose 65 happiness units by sitting next to Alice.
-Eric would gain 24 happiness units by sitting next to Bob.
-Eric would gain 100 happiness units by sitting next to Carol.
-Eric would gain 51 happiness units by sitting next to David.
-Eric would gain 21 happiness units by sitting next to Frank.
-Eric would gain 55 happiness units by sitting next to George.
-Eric would lose 44 happiness units by sitting next to Mallory.
-Frank would lose 48 happiness units by sitting next to Alice.
-Frank would gain 91 happiness units by sitting next to Bob.
-Frank would gain 8 happiness units by sitting next to Carol.
-Frank would lose 66 happiness units by sitting next to David.
-Frank would gain 97 happiness units by sitting next to Eric.
-Frank would lose 9 happiness units by sitting next to George.
-Frank would lose 92 happiness units by sitting next to Mallory.
-George would lose 44 happiness units by sitting next to Alice.
-George would lose 25 happiness units by sitting next to Bob.
-George would gain 17 happiness units by sitting next to Carol.
-George would gain 92 happiness units by sitting next to David.
-George would lose 92 happiness units by sitting next to Eric.
-George would gain 18 happiness units by sitting next to Frank.
-George would gain 97 happiness units by sitting next to Mallory.
-Mallory would gain 92 happiness units by sitting next to Alice.
-Mallory would lose 96 happiness units by sitting next to Bob.
-Mallory would lose 51 happiness units by sitting next to Carol.
-Mallory would lose 81 happiness units by sitting next to David.
-Mallory would gain 31 happiness units by sitting next to Eric.
-Mallory would lose 73 happiness units by sitting next to Frank.
-Mallory would lose 89 happiness units by sitting next to George.
+[22, 8, 165],
+[8, 17, 114],
+[18, 6, 103],
+[25, 6, 145],
+[11, 12, 125],
+[21, 6, 121],
+[18, 3, 50],
+[20, 4, 75],
+[7, 20, 119],
+, \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 8baaca9..81c296f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -41,47 +41,43 @@ use atools::prelude::*;
pub use util::prelude::*;
#[no_mangle]
-#[lower::apply(wrapping)]
pub fn p1(x: &str) -> impl Display {
- let mut relations = HashMap::<&[u8], HashMap<_, _>>::default();
- x.行()
- .map(|x| {
- let [who, _, gain, quant, _, _, _, _, _, _, to] = x.μₙ(b' ').carr();
- let quant = if gain == b"gain" {
- quant.λ::<i64>()
- } else {
- -quant.λ::<i64>()
- };
- relations
- .entry(who)
- .or_default()
- .insert(&to[..to.len() - 1], quant);
- })
- .Θ();
-
- for person in relations.keys().copied().collect::<Vec<_>>() {
- relations.entry(b"me").or_default().insert(person, 0);
- relations.entry(person).or_default().insert(b"me", 0);
- }
-
- let people = Vec::from_iter(relations.keys().copied());
- people
- .iter()
- .copied()
- .permutations(people.len())
- .map(|arrangement| {
- arrangement
- .iter()
- .ι::<usize>()
- .flat_map(|(me, i)| {
- let left = arrangement[(i - 1) % arrangement.len()];
- let right = arrangement[(i + 1) % arrangement.len()];
- [relations[me][left], relations[me][right]]
- })
- .sum::<i64>()
- })
+ let x = [
+ [22usize, 8, 165],
+ [8, 17, 114],
+ [18, 6, 103],
+ [25, 6, 145],
+ [11, 12, 125],
+ [21, 6, 121],
+ [18, 3, 50],
+ [20, 4, 75],
+ [7, 20, 119],
+ ];
+ let mut deer = x.map(|deer| {
+ repeat_n(deer[0], deer[1])
+ .chain(repeat_n(0, deer[2]))
+ .cycle()
+ });
+ dbg!(deer
+ .clone()
+ .into_iter()
+ .map(|x| x.take(2503).sum::<usize>())
.max()
- .unwrap()
+ .unwrap());
+ let mut states = [0; 9];
+ let mut points = [0; 9];
+ for _ in 0..2503 {
+ deer.iter_mut()
+ .ι::<usize>()
+ .for_each(|(deer, i)| states[i] += deer.next().unwrap());
+ let max = states.into_iter().max().unwrap();
+ states
+ .into_iter()
+ .ι::<usize>()
+ .filter(|&(x, _)| x == max)
+ .for_each(|(_, i)| points[i] += 1);
+ }
+ points.into_iter().max().unwrap()
}
fn main() {
diff --git a/src/util.rs b/src/util.rs
index adecb87..c969839 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -33,7 +33,7 @@ pub mod prelude {
hint::black_box as boxd,
io::{self, Read, Write},
iter,
- iter::{chain, once, successors, zip},
+ iter::{chain, once, repeat_n, successors, zip},
mem::{replace as rplc, swap, transmute as rint},
ops::Range,
};