From 31b9d9d813420f8922c872c6d081d14d149512f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Wed, 7 Apr 2021 15:11:23 +0200 Subject: [PATCH] Solve first part of day 1 --- data/day01.dat | 200 ++++++++++++++++++++++++++++++++++++++++++++++ src/days.rs | 1 + src/days/day01.rs | 18 +++++ src/main.rs | 4 +- 4 files changed, 222 insertions(+), 1 deletion(-) create mode 100644 data/day01.dat create mode 100644 src/days.rs create mode 100644 src/days/day01.rs diff --git a/data/day01.dat b/data/day01.dat new file mode 100644 index 0000000..94edb75 --- /dev/null +++ b/data/day01.dat @@ -0,0 +1,200 @@ +1140 +1736 +1711 +1803 +1825 +1268 +1651 +2007 +1923 +1661 +1788 +1876 +2003 +1752 +1988 +1955 +1568 +1478 +1699 +1717 +1828 +1636 +1387 +1870 +1658 +1572 +1703 +1185 +1569 +1515 +1142 +1407 +1587 +1608 +1827 +1546 +1808 +1937 +1815 +1957 +1401 +1763 +1970 +1960 +1853 +1987 +1865 +1567 +1664 +1961 +1771 +1846 +1971 +1416 +1897 +633 +1708 +1606 +515 +1397 +1873 +1374 +1969 +1918 +1170 +1660 +1494 +1764 +2002 +1938 +1396 +1926 +1714 +1659 +1805 +1593 +1899 +1850 +1644 +1877 +1561 +1895 +1985 +1353 +395 +1919 +1522 +1745 +1721 +901 +1765 +1939 +2009 +1949 +1852 +1792 +1749 +1675 +1883 +1240 +1868 +1615 +1693 +1720 +1388 +1325 +1337 +867 +1751 +1408 +1715 +1942 +1706 +1894 +1260 +1945 +1700 +1148 +1373 +351 +1790 +1861 +1755 +1155 +1622 +1743 +1872 +1979 +1262 +1789 +1305 +1311 +1729 +1929 +823 +1623 +2005 +1932 +1814 +1909 +1728 +1592 +1712 +1363 +1338 +1804 +1402 +1198 +264 +1117 +1791 +1419 +1229 +1924 +1838 +1785 +1982 +1683 +1950 +1199 +1984 +1830 +1921 +1980 +1834 +1341 +1282 +1989 +1854 +1395 +1847 +1900 +1913 +1777 +1779 +1333 +1800 +1966 +1543 +1882 +1375 +1811 +1673 +1679 +889 +1670 +1879 +1312 +1741 +1772 +1663 +1776 +1642 +1674 +1472 +1580 +1264 +1738 +1999 +1637 diff --git a/src/days.rs b/src/days.rs new file mode 100644 index 0000000..12b8f18 --- /dev/null +++ b/src/days.rs @@ -0,0 +1 @@ +pub mod day01; diff --git a/src/days/day01.rs b/src/days/day01.rs new file mode 100644 index 0000000..b323016 --- /dev/null +++ b/src/days/day01.rs @@ -0,0 +1,18 @@ +use std::fs; + +fn calc_solution1(input: &Vec) -> i32 { + for i in 0..input.len() { + for j in (i + 1)..input.len() { + if (input[i] + input[j]) == 2020 { + return input[i] * input[j]; + } + } + } + panic!("No solution"); +} + +pub fn get_solution() { + let contents = fs::read_to_string("data/day01.dat").expect("Could not read data"); + let input: Vec = contents.lines().flat_map(str::parse).collect(); + println!("Day 1, part 1: {}", calc_solution1(&input)); +} diff --git a/src/main.rs b/src/main.rs index e7a11a9..67c6484 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +mod days; + fn main() { - println!("Hello, world!"); + days::day01::get_solution(); } -- 2.44.0