diff options
author | Justin Wernick <justin@worthe-it.co.za> | 2019-12-16 14:43:21 +0200 |
---|---|---|
committer | Justin Wernick <justin@worthe-it.co.za> | 2019-12-16 14:43:21 +0200 |
commit | 50c67c8cbe1cdccea28359eeea0280759931469b (patch) | |
tree | 62162335f84336726b3cc43a3e2745f0e9c7080a /src/lib.rs | |
parent | b8b6c411125f1f12cb4bbcde997141559b3ea797 (diff) |
Day 10 and 11! Yay!
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -6,6 +6,7 @@ use std::fmt; use std::iter; use std::iter::FromIterator; use std::iter::IntoIterator; +use std::iter::Iterator; pub type Intcode = BigInt; @@ -57,6 +58,18 @@ impl fmt::Debug for IntcodeProgram { } } +pub fn intcode_to_bool(i: &Intcode) -> bool { + *i != Intcode::from(0) +} + +pub fn bool_to_intcode(i: bool) -> Intcode { + if i { + Intcode::from(1) + } else { + Intcode::from(0) + } +} + impl IntcodeProgram { pub fn with_noun_verb_input(&self, noun: Intcode, verb: Intcode) -> IntcodeProgram { self.with_memory_set(1.into(), noun) @@ -444,3 +457,12 @@ mod tests { assert_eq!(program.output, i32_vec_to_intcode_vec(quine)); } } + +pub fn sort_by_key<T, K: Ord>( + iter: impl IntoIterator<Item = T>, + f: impl FnMut(&T) -> K, +) -> impl Iterator<Item = T> { + let mut tmp: Vec<T> = iter.into_iter().collect(); + tmp.sort_by_key(f); + tmp.into_iter() +} |