@@ 0,0 1,9 @@
+[package]
+name = "day17"
+version = "0.1.0"
+authors = ["Tomasz Kłak <tomasz@tomaszklak.pl>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
@@ 0,0 1,24 @@
+fn powerset<T>(s: &[T]) -> Vec<Vec<T>> where T: Clone {
+ (0..2usize.pow(s.len() as u32)).map(|i| {
+ s.iter().enumerate().filter(|&(t, _)| (i >> t) % 2 == 1)
+ .map(|(_, element)| element.clone())
+ .collect()
+ }).collect()
+}
+
+fn count(target: i32, cont: &[i32]) -> usize {
+ powerset(cont).iter().filter(|v| v.iter().sum::<i32>() == target).count()
+}
+
+fn count2(target: i32, cont: &[i32]) -> usize {
+ let all_correct : Vec<_> = powerset(cont).iter().filter(|v| v.iter().sum::<i32>() == target).cloned().collect();
+ let min = all_correct.iter().map(|v| v.len()).min().unwrap();
+ all_correct.iter().filter(|v| v.len() == min).count()
+}
+
+fn main() {
+ let input = vec![43, 3, 4, 10, 21, 44, 4, 6, 47, 41, 34, 17, 17, 44, 36, 31, 46, 9, 27, 38];
+ dbg!(count(150, &input));
+ dbg!(count2(150, &input));
+
+}