summaryrefslogtreecommitdiff
path: root/2023/day15/src
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2023-12-15 21:47:10 +0100
committerSanto Cariotti <santo@dcariotti.me>2023-12-15 21:47:10 +0100
commit67dff579e91c13ef40ecb17d14497d145861c5e7 (patch)
tree3ec7cccea75ba25aa0da34f528811d28f6c9b21a /2023/day15/src
parent49ecb2db619bb32c712e619ec66833a917b5ffc3 (diff)
add day15 pt1
Diffstat (limited to '2023/day15/src')
-rw-r--r--2023/day15/src/lib.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/2023/day15/src/lib.rs b/2023/day15/src/lib.rs
new file mode 100644
index 0000000..e9d36eb
--- /dev/null
+++ b/2023/day15/src/lib.rs
@@ -0,0 +1,56 @@
+pub fn part1(input: &str) -> u32 {
+ let mut res: u32 = 0;
+
+ let inputs: Vec<String> = input.trim_end().split(',').map(|x| x.to_string()).collect();
+
+ for i in inputs {
+ let mut s = 0;
+ for ch in i.chars() {
+ s += ch as u32;
+ s *= 17;
+ s %= 256;
+ }
+ res += s;
+ }
+
+ res
+}
+
+pub fn part2(input: &str) -> u32 {
+ let mut res: u32 = 0;
+
+ res
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn example_part1() {
+ let input = include_str!("../example.txt");
+ let result = part1(input);
+ assert_eq!(result, 1320);
+ }
+
+ #[test]
+ fn input_part1() {
+ let input = include_str!("../input.txt");
+ let result = part1(input);
+ assert_eq!(result, 2331);
+ }
+
+ // #[test]
+ // fn example_part2() {
+ // let input = include_str!("../example.txt");
+ // let result = part2(input);
+ // assert_eq!(result, 2286);
+ // }
+ //
+ // #[test]
+ // fn input_part2() {
+ // let input = include_str!("../input.txt");
+ // let result = part2(input);
+ // assert_eq!(result, 71585);
+ // }
+}