Commit dabd19af authored by Kai Brandes's avatar Kai Brandes

solution for 4a

parent eaf7f184
......@@ -8,4 +8,5 @@ fn main() {
println!("Solution for day 2b is: {}", adventofcode_2017::results::day_2_b());
println!("Solution for day 3a is: {}", adventofcode_2017::results::day_3_a());
println!("Solution for day 3b is: {}", adventofcode_2017::results::day_3_b());
println!("Solution for day 4a is: {}", adventofcode_2017::results::day_4_a());
\ No newline at end of file
This diff is collapsed.
use wasm_bindgen::prelude::*;
fn line_valid(input: &str) -> bool {
let mut whitespace: Vec<&str> = input.split_whitespace().collect();
let total_words = whitespace.len() as u32;
whitespace.dedup_by(|a,b| a == b);
total_words == whitespace.len() as u32
pub fn calc_day_4_a(input: String) -> u32 {
return input.lines()
.filter(|a| *a == true)
.count() as u32;
mod tests {
use super::*;
fn it_aoc_example_1() {
assert_eq!(true, line_valid("aa bb cc dd ee"));
fn it_aoc_example_2() {
assert_eq!(false, line_valid("aa bb cc dd aa"));
fn it_aoc_example_3() {
assert_eq!(true, line_valid("aa bb cc dd aaa"));
fn it_aoc_example_4() {
assert_eq!(2, calc_day_4_a(String::from("aa bb cc dd ee\naa bb cc dd aa\naa bb cc dd aaa")));
......@@ -4,6 +4,7 @@ extern crate wasm_bindgen;
pub mod day1;
pub mod day2;
pub mod day3;
pub mod day4;
pub mod results;
mod utils;
use day1;
use day2;
use day3;
use day4;
use std::fs::File;
use std::io::prelude::*;
......@@ -35,4 +36,8 @@ pub fn day_3_a() -> u32 {
pub fn day_3_b() -> u32 {
return day3::calc_day_3_b(312051);
\ No newline at end of file
pub fn day_4_a() -> u32 {
return day4::calc_day_4_a(parse_input_from_file(String::from("src/day4/a.txt")));
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment