This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::{Read, stdin}; | |
| fn main() { | |
| let mut s = String::new(); | |
| stdin().read_to_string(&mut s).unwrap(); | |
| for m in s.lines().skip(1).map(|l| l.parse::<isize>().unwrap()) { | |
| if m % 2 == 0 { | |
| println!("{m} is even"); | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::{Read, stdin}; | |
| fn main() { | |
| let mut s = String::new(); | |
| stdin().read_to_string(&mut s).unwrap(); | |
| let (x, y) = s.trim().split_once(' ').unwrap(); | |
| let (x, y) = (x.parse::<f32>().unwrap(), y.parse::<f32>().unwrap()); | |
| // n = n*y + x | |
| // 0 = yn - n + x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::{ | |
| cmp::Ordering, | |
| io::{Read, stdin}, | |
| }; | |
| fn main() { | |
| let mut s = String::new(); | |
| stdin().read_to_string(&mut s).unwrap(); | |
| let mut s = s.lines(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::{ops::RangeInclusive, time::Instant}; | |
| const INPUT: &str = include_str!("inputs/day05.txt"); | |
| fn parse(input: &str) -> (Vec<RangeInclusive<usize>>, impl Iterator<Item = usize>) { | |
| let (ranges, ingredients) = input.split_once("\n\n").unwrap(); | |
| // Collect our ranges. | |
| let ranges = ranges | |
| .lines() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::time::Instant; | |
| use itertools::Itertools; | |
| use rustc_hash::FxHashSet; | |
| const INPUT: &str = include_str!("inputs/day04.txt"); | |
| #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)] | |
| struct Point { | |
| row: isize, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::time::Instant; | |
| const INPUT: &str = include_str!("inputs/day03.txt"); | |
| fn parse(input: &str) -> impl Iterator<Item = Vec<usize>> { | |
| // Turn each line into a list of digits. | |
| input.lines().map(|l| { | |
| l.chars() | |
| .map(|c| c.to_digit(10).unwrap() as usize) | |
| .collect() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use rayon::prelude::*; | |
| use std::{ops::RangeInclusive, time::Instant}; | |
| const INPUT: &str = include_str!("inputs/day02.txt"); | |
| fn parse(input: &str) -> impl Iterator<Item = RangeInclusive<usize>> { | |
| // Convert the input into a list of ranges. | |
| input.trim().split(',').map(|l| { | |
| l.split_once('-') | |
| .map(|(l, r)| l.parse().unwrap()..=r.parse().unwrap()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::time::Instant; | |
| const INPUT: &str = include_str!("inputs/day01.txt"); | |
| fn parse(input: &'_ str) -> impl Iterator<Item = (char, isize)> { | |
| input.lines().map(|l| { | |
| let mut chars = l.chars(); | |
| ( | |
| chars.next().unwrap(), | |
| chars.as_str().parse::<isize>().unwrap(), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::{Read, stdin}; | |
| fn main() { | |
| let mut s = String::new(); | |
| stdin().read_to_string(&mut s).unwrap(); | |
| let mut s = s.lines(); | |
| let x = s.next().map(|l| l.parse::<usize>().unwrap()).unwrap(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use std::io::{Read, stdin}; | |
| fn main() { | |
| let mut s = String::new(); | |
| stdin().read_to_string(&mut s).unwrap(); | |
| let q = s | |
| .lines() | |
| .skip(1) | |
| .map(|l| { |