Day 8 part 1 add a bunch of variations

This commit is contained in:
Bill Thiede 2021-12-08 18:49:38 -08:00
parent b15a06e07c
commit df51dcdaa8

View File

@ -127,7 +127,7 @@ use std::{
use anyhow::Result;
use aoc_runner_derive::aoc;
#[aoc(day8, part1)]
#[aoc(day8, part1, original)]
fn part1(input: &str) -> Result<usize> {
Ok(input
.lines()
@ -143,6 +143,44 @@ fn part1(input: &str) -> Result<usize> {
.sum())
}
#[aoc(day8, part1, no_result)]
fn part1_no_result(input: &str) -> usize {
input
.lines()
.map(|l| {
l.split_once(" | ")
.unwrap()
.1
.split(' ')
// 1 | 7 | 4 | 8
.filter(|s| matches!(s.len(), 2 | 3 | 4 | 7))
.count()
})
.sum()
}
#[aoc(day8, part1, flat_map)]
fn part1_flat_map(input: &str) -> usize {
input
.lines()
.flat_map(|l| l.split_once(" | ").unwrap().1.split(' '))
// 1 | 7 | 4 | 8
.filter(|s| matches!(s.len(), 2 | 3 | 4 | 7))
.count()
}
#[aoc(day8, part1, glenng)]
fn part1_glenng(input: &str) -> usize {
input
.split('\n')
.flat_map(|line| {
let (_, output) = line.split_once(" | ").unwrap();
output.split(' ')
})
.filter(|s| [2usize, 3, 4, 7].contains(&s.len()))
.count()
}
#[derive(Copy, Clone, Eq, Hash, PartialEq)]
struct Segment(u8);