summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJustin Worthe <justin@worthe-it.co.za>2017-12-01 07:12:21 +0200
committerJustin Worthe <justin@worthe-it.co.za>2017-12-01 07:12:21 +0200
commit331556e64dd4beed1223d749d9e21de8fff389c6 (patch)
tree88224063d782a6786a08aeb7ed814a8a7959c439 /src
parent2fa7e467549d9c4499932a48663034e173ec02b1 (diff)
Day 1: sum of characters
Diffstat (limited to 'src')
-rw-r--r--src/bin/day_1.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/bin/day_1.rs b/src/bin/day_1.rs
index 7bcfcee..5d0e431 100644
--- a/src/bin/day_1.rs
+++ b/src/bin/day_1.rs
@@ -3,6 +3,22 @@ use advent_of_code_2017::*;
fn main() {
let args = AdventArgs::init();
+
+ let number_chars = args.input[0].chars().collect::<Vec<_>>();
+
+ let mut sum = 0;
+
+ for i in 0..number_chars.len() {
+ let next = if args.part == 1 {
+ (i + 1)
+ } else {
+ (i + number_chars.len() / 2)
+ } % number_chars.len();
+ if (number_chars[i] == number_chars[next]) {
+ let parsed: i32 = number_chars[i].to_string().parse().unwrap();
+ sum += parsed;
+ }
+ }
- println!("{:?} {:?}", args.part, args.input);
+ println!("Sum is {}", sum);
}