main
henine 4 years ago
parent 3a0d07631d
commit 1562c726a5

6
.gitignore vendored

@ -8,3 +8,9 @@ Cargo.lock
# These are backup files generated by rustfmt
**/*.rs.bk
id.txt
**/.idea
*.iml
*/target

@ -0,0 +1,9 @@
[package]
name = "day1"
version = "0.1.0"
authors = ["henine <matija@rezar.biz>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

@ -0,0 +1,200 @@
1993
1715
1997
1666
1676
1830
1203
1800
1125
1191
1902
1972
1471
1137
2003
1250
1548
1070
1152
2004
1127
1111
1898
1848
1934
1236
1704
1950
1387
1713
1214
1266
1114
1089
1677
1207
1341
1689
1772
1901
1932
1645
1285
1884
883
1291
1543
1455
1213
1088
1784
1506
1879
1811
1880
994
1021
1585
1662
1683
1071
1643
1754
1389
1124
1820
1168
1875
1017
1180
1375
1359
1311
1357
1501
1719
1584
1609
1977
1786
1232
1263
1748
1664
1693
1766
1598
1053
1277
1466
1877
1844
1829
1165
1606
1298
1963
1873
1911
1729
1418
1372
1777
1371
1588
1329
1029
1931
1115
1810
1595
1237
1282
1838
1642
1937
1343
1578
1425
1814
1690
1129
1321
1174
1863
1405
1066
1220
1780
1410
1156
1991
1568
1368
99
1750
1280
1400
1601
1804
1363
1613
1252
1434
1094
1867
1542
1093
1926
1251
1348
689
1441
1913
1969
1409
1201
1459
1110
1452
1051
1860
1346
1537
1060
1182
1386
1141
1184
1989
1852
1097
1135
1078
1587
1984
1970
1259
1281
1092
1294
1233
1186
1555
1755
1886
1030
1706
1313
1481
1998
1181
1244
1269
1684
1798
1023
1960
1050
1293

@ -0,0 +1,32 @@
use std::vec::Vec;
use std::io;
fn main() {
let mut numbers: Vec<i32> = Vec::new();
let mut line = String::new();
loop {
match io::stdin().read_line(&mut line) {
Ok(0) => {
break;
}
Ok(_n) => {
println!("{}", line);
numbers.push(line.trim().parse().unwrap());
line.truncate(0);
}
Err(error) => println!("error: {}", error),
}
}
for i in 0..numbers.len() - 2 {
for j in i + 1..numbers.len() - 1 {
for k in j + 1..numbers.len() {
if numbers[i] + numbers[j] + numbers[k] == 2020 {
println!("{}", numbers[i] * numbers[j] * numbers[k]);
};
}
}
}
}

@ -0,0 +1,10 @@
[package]
name = "day2"
version = "0.1.0"
authors = ["henine <matija@rezar.biz>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
scan_fmt = "*"

File diff suppressed because it is too large Load Diff

@ -0,0 +1,46 @@
use std::fs::File;
use std::io::{BufReader, BufRead};
#[macro_use]
extern crate scan_fmt;
fn main() {
let file = match File::open("input") {
Ok(file) => file,
Err(e) => panic!(e)
};
let input_buffer = BufReader::new(&file);
let mut count = 0;
for line_result in input_buffer.lines() {
let line = line_result.unwrap();
if match scan_fmt!(&line, "{d}-{d} {}: {}", i32,i32,char, String) {
Ok((min_occ, max_occ, letter, password)) => is_correct2(min_occ as usize, max_occ as usize, letter, &password),
Err(e) => panic!(e)
} {
count += 1;
}
}
println!("{}", count);
}
fn is_correct(min_occ: i32, max_occ: i32, letter: char, password: &String) -> bool {
let mut count = 0;
for c in password.chars() {
if c == letter {
count += 1;
}
}
count >= min_occ && count <= max_occ
}
fn is_correct2(p1: usize, p2: usize, letter: char, password: &String) -> bool {
(password.as_bytes()[p1-1] == letter as u8) ^ (password.as_bytes()[p2-1] == letter as u8)
}

@ -0,0 +1,9 @@
[package]
name = "day3"
version = "0.1.0"
authors = ["henine <matija@rezar.biz>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

@ -0,0 +1,323 @@
.........###......#...#.......#
.#.#...........#..#..#.........
#.......#.................#....
.........#.#.........#......###
.....#......##...##............
...##...#......#.....#.....##..
#.#..#....#...#....#......#....
........##.....#.....#.#.......
......#.....#......#...##.#....
...####...#.......##.....#.#...
.........#....#......##........
..##...........###.#...........
.....#............#............
#.#..#..##........#.....#..#...
.....................#....##..#
...........##.....###...#.#.#..
..#......#...........#.........
.##.##...#...#......##.#.......
......#..#......#.#.#..#.#.....
........#.#..#..........#...#.#
...........##...........#....#.
...........#...##.#............
.......#...........#...........
.......#......#..#...#....#..#.
..#.....#.#....#.#......#...#.#
.#..........###..#....#........
........##..#..#...#..#....#..#
#..........#...#..#.#........#.
..#.#........##.##....##.#.....
#.##....#...#.......#.#..#....#
......##...#.#.#.#.....#....#..
..........#..............#.....
....................###.#......
#.....#...#...#.#.......#....#.
.......#..#...................#
........##.##........#......#..
...#...##.#...#...........#....
..#.........#...#....##......#.
......#..............#..#..#.#.
.....##...#...#...##....#......
#.#....#...#......##.....#...##
.#...#.#..................#....
#.##.....#......#..........#...
..#..#.......#.................
..#.....#.........#........#...
.......#...##.##.#..#..##.#..#.
#.............#.........#.#....
..#..##..........#..#..##.#.#..
.#......#.......#...#.....##.#.
.....#......#...#...........###
..........#.........#.....#....
.....#..........#.......##...#.
......#..#..#..............#...
.#.####..#...##...#.#..........
..#....#.......#........#.....#
....#.##.....#..#.....#.#.#..#.
.......#..#..##.......#........
.#.....#...........#.....#.....
........#..........##..##.#....
.#.....#........#.....#..#.....
..#..........#...#......##..#..
.#............#.........#....#.
........#..###.......#.....###.
##.#...#.#..#..#..#.#.##...#...
.#....#...#..#......##.........
.............##.....##.........
.....##.#..###.#....#...#...#.#
#........#...#......#...#.##...
#....#......#.....###.##.#.....
.....#..#.#.##....#..##.....##.
....#...#...#..........##......
..........#......#...#.....##..
.....##....##.#.............#.#
#.........#.##.............#..#
.....#.........##.#...#.#.#....
..........#..#......#..#.....#.
....#....#....#....#.......###.
....#...#..##....#..##..#...##.
.###......#...........###......
#..................####.#....#.
#....#.#.....#.#....#..#.......
...#......#....##......#..#..#.
#.#...#.##.....#.#.......##..#.
.........##.................#..
#..##.#....#.#.............#...
....................####.#.#..#
.......#..#...#..#..#.....#...#
.....#.#.#........#....#...##..
......#..#....#......#..##.....
............#......##.#....#..#
...#..........#..#...........#.
..........#.............###....
....##.#.#......#.#..#....##..#
..#..........#........#......#.
..#...........####......##..#.#
...##......##...#..#.##........
.....#...#.....##.....###..##..
.#.##.....#....##....#.........
#....##..#.....#.#......#.#....
..#.......#...#....#...#.#.....
...........#.........#.........
..#..#....##..#....#....#.....#
.......#..#....##....#.........
#.........#...........##....##.
#........#.#...............##..
#...##.#...............#.......
#....#..#......#..#.###...##..#
..#.........#.#......#.....#..#
......#...........##........##.
.#.........#................#..
#...#...............#...#....#.
.#.#......##.........#.#.......
..........#....................
.#.....#..#...#.#.#.......#...#
..#..........#.................
.#.#.....#.#......#...#.....##.
.....#.#..##...##..#..###...#..
......#......#.#......#.##.....
#.#......#...#.......#....#....
..........#....#.#..#.....##...
#...........#.#....#.##....#.#.
#.#....#..#.........###....#...
..............#..##.......#....
.......................#.##.#..
##...............##....#..#.#..
.#.#..#.##...#.............#...
...#...........#............#..
..#......#........##....#.#.##.
.#.#..#........#....#....#....#
.#.....#.##....#.....#..#...#..
......#...#..........#..###....
..#.#.......#........#........#
.......##.####..........#......
.#.#..#......##..#.........#..#
..#...##.#.......#...#.##...#.#
#.#..........#..#.#.#..........
.....#......#............#.....
........###...#.......#........
.....#.##....#....#............
...#.#....##.....#.....#.......
..#.............#......#.......
.#....#...#....##..#......#....
..#.....#.#............#.......
......#........##.........#...#
.......#........#..#.#.#...##.#
#....#...#..#.......#....##....
#...##.#.#.....#.......#.......
.....#........#.#.....#...##...
..#....#..##......#.#.....#...#
....#.....#......#.....#.......
#.#....#......#...##...........
..#.......#...#...............#
........#........#.............
#.#.#......#...#..#..........#.
.##...#.........#........#..#..
#.#.#...#.#.......#.....#...#..
...#..............#..........#.
#.#...#.###.............#......
................#.....###.##.#.
.......#..........#....#..#....
......##....#..#..##...........
...#...#.....######.......#....
..##.....##.#...#.........#.#.#
.......#...#..#.#.#...........#
........###.............#...#.#
#.....#.........#.............#
..#...#.....#..................
.....#....#.....#......#.#....#
...#....#........##...#.......#
...##.#...#.....#..............
..#.##....##..#.........#......
.....#..#.#....#...#......#.#..
...........##..##...#..#..###..
#...........#.........####....#
.#...........#...........###...
........#................#.....
.....#....#............#....#.#
...#...#.......#...............
#.....##.#.......#.#...........
#.......#.#.#.#..#...#.........
....####.#...#.#......#.....##.
...##...#.....#.#......#..#....
..........#..#....#......###...
...................#....##...#.
....#......#........#...##..#..
##...#.........#.#......#......
#........#...#....#......#.....
#..#.......#...............##..
......##......#...........##.#.
......#..#....#....#.##........
..#....#..#.#.###....#.........
.#......#..#..............#....
.#..........#...#..#.#...#.....
....#......#..#......#....#....
...##.....#............####..#.
......#.#...#....#..#...#..#.#.
......##.......................
#.##........#...........####..#
.....#......#.......#.#....#...
#.......#....#.....#....#...##.
.....#..##.#...........#..#...#
...........#.##.#.#...#.#..#...
..#.......#.#....#..#..........
...#.......##..#.............#.
....#..#....#....#...#....#....
#......#.#...##..........#..#..
..#.#.......#.........#......#.
#...............#.............#
....##..#......................
.##....#............#......#...
.......#....#..##......##......
#..##.....#..#..........#......
...#.........#.......#..##.....
....#.##.....#.#...#...#.....#.
##...........#.#..#...#.#......
....#.............##...#.#..#..
...#....#......................
#..#...##.#.......#.##..#.###..
...##.#.#...##........##...#...
......##..#..#.....#..#.#..#...
#.......##...............##.#..
.##......#..#....#...##..#..#.#
##.........##..#...#.....##....
...#..........#...#..##.#......
..##.#........#...#..........##
.......................##.#....
....#...#...#..###.#.......#.##
....#....#.#..........#.##.....
..#..........##...#....#.......
.....#.....#.....#..#.........#
..##..##..#..#....#..#.......##
.............#............##...
....#.#.#.......###.........#..
...##.#..........#.#...#.#.....
.#........#..#.#.#..#..........
...##...#.....##.......#..#..#.
...#......#..#.......##.#.#....
.........#.........##........#.
.........##..................##
....##.....#................#..
....#..................##...#.#
.........#..............#......
...#......#..#..#....#..#...##.
.#.##......##...#.#......#.#...
...#.#...###....#...#.#..#....#
....#..#.......#.....#..##.#.#.
#.#.#..#.......#####.#..##..#..
#..........#.....#..#.#..#.....
.#......#...#..#.#..#..#.......
...#....##...#..........#.##.#.
#.##..#...#..................#.
......#.###..#..#..#.......#...
...#....#...#..#............###
#.........#........#.......#...
...#..#.................#....##
...#.#.............##......#...
##....#.##.............##......
#............#..#..#.....#.....
....#........#...#.....#.#...##
..#.##..#.....................#
#.#........#...#..#...#.#......
...#..#...........##.....#.....
......#.#....#..##...#.....#...
......#......#.###..##.........
....#.......#...##.##.....#....
#.....##....#........#..##.....
.#..#..#..#..#.#...#...#.......
.......##...#......#.........#.
.#..##....#.....#...........##.
.......##....#.#........#......
..#.#.#....#...................
.#...#.......#...#.#......#....
..##.##..##...........###......
#...#......#.......#...........
#....##.#.......#.........#....
.............##.#.#..#...#...#.
..##.##...........#.........##.
#.#...#..........#.#....#....##
.....#.....#..##..#............
#.........#.........#.#...##..#
...#.#.....#.........###..#....
..#.#.##.#...................#.
......####....#.......#.......#
.........#..#..#....#..##......
....#..........#...##........#.
..........#..#....#.....#....#.
.#.#.................#....#....
.......#......#.....#...##.....
....#..............#...........
###...........##.#...........#.
...####.......#...#....#.#...#.
..##.#................#........
...#..#....#.....#.....##..#...
##.#....#....##..........#.#..#
...#....#.....#................
..#...#....#..#..#.##.##..#....
....#....#.##.....#...#......#.
......#................#..#..#.
...##..#...#....#.#.....#..#...
#...#..............#.#.....#.#.
....#.........#.##...#.#....#..
..................#..##.#......
.#.....#.....#.............#..#
..........####....###..##...#..
......#........#...#......##..#
#......#.#..........#....#.#...
###................#.#....#....
#..#.##.#.............#..#.....
.....#............#.....##.....
....#.....#....#.........#.....
#..#...........###.#....#......
..#............##...#........##
..#....#..#....#.....#.......#.
..#..#.#.#.##.#..#...#.....#...
..........#..#.................
...#.#......#..##........#.....
...............#...............
#.......#.......#....#.........
#...........#....#.............
....#..#..........#....#..##...
.........#.#.#.........#......#
.....#...##.....#.#.......#...#
.........#....#...#.......#....

@ -0,0 +1,45 @@
use std::fs::File;
use std::io::{BufReader, BufRead};
fn main() {
let file = match File::open("input") {
Ok(file) => file,
Err(e) => panic!(e)
};
let input_buffer = BufReader::new(&file);
let mut count: [u32; 5] = [0, 0, 0, 0, 0];
let mut line_n = 0;
for line_result in input_buffer.lines() {
let line_string = line_result.unwrap();
let line = line_string.as_bytes();
if line[(1 * line_n) % line.len()] == '#' as u8 {
count[0] += 1;
}
if line[(3 * line_n) % line.len()] == '#' as u8 {
count[1] += 1;
}
if line[(5 * line_n) % line.len()] == '#' as u8 {
count[2] += 1;
}
if line[(7 * line_n) % line.len()] == '#' as u8 {
count[3] += 1;
}
if line_n % 2 == 0 && line[(1 * line_n/2) % line.len()] == '#' as u8 {
count[4] += 1;
}
line_n += 1;
}
println!("{}", count[0] * count[1] * count[2] * count[3] * count[4]);
}
Loading…
Cancel
Save