Add 9 first days
This commit is contained in:
1
1-report_repair/.gitignore
vendored
Normal file
1
1-report_repair/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
13
1-report_repair/.vscode/tasks.json
vendored
Normal file
13
1-report_repair/.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"type": "cargo",
|
||||
"command": "run",
|
||||
"problemMatcher": [
|
||||
"$rustc"
|
||||
],
|
||||
"label": "rust: cargo run"
|
||||
}
|
||||
]
|
||||
}
|
||||
239
1-report_repair/Cargo.lock
generated
Normal file
239
1-report_repair/Cargo.lock
generated
Normal file
@@ -0,0 +1,239 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "atty"
|
||||
version = "0.2.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||
dependencies = [
|
||||
"hermit-abi",
|
||||
"libc",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "2.33.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
|
||||
dependencies = [
|
||||
"ansi_term",
|
||||
"atty",
|
||||
"bitflags",
|
||||
"strsim",
|
||||
"textwrap",
|
||||
"unicode-width",
|
||||
"vec_map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.81"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
|
||||
dependencies = [
|
||||
"proc-macro-error-attr",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro-error-attr"
|
||||
version = "1.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "report_repair"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"itertools",
|
||||
"structopt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||
|
||||
[[package]]
|
||||
name = "structopt"
|
||||
version = "0.3.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5277acd7ee46e63e5168a80734c9f6ee81b1367a7d8772a2d765df2a3705d28c"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"lazy_static",
|
||||
"structopt-derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "structopt-derive"
|
||||
version = "0.4.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ba9cdfda491b814720b6b06e0cac513d922fc407582032e8706e9f137976f90"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a2af957a63d6bd42255c359c93d9bfdb97076bd3b820897ce55ffbfbf107f44"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textwrap"
|
||||
version = "0.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||
dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-width"
|
||||
version = "0.1.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
|
||||
|
||||
[[package]]
|
||||
name = "vec_map"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5a972e5669d67ba988ce3dc826706fb0a8b01471c088cb0b6110b805cc36aed"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
11
1-report_repair/Cargo.toml
Normal file
11
1-report_repair/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "report_repair"
|
||||
version = "0.1.0"
|
||||
authors = ["Guilhem MARION <gmarion@netc.fr>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
itertools = "0.9.0"
|
||||
structopt = "0.3.20"
|
||||
200
1-report_repair/data/input.txt
Normal file
200
1-report_repair/data/input.txt
Normal file
@@ -0,0 +1,200 @@
|
||||
1749
|
||||
1897
|
||||
881
|
||||
1736
|
||||
1161
|
||||
1720
|
||||
1676
|
||||
305
|
||||
264
|
||||
1904
|
||||
1880
|
||||
1173
|
||||
483
|
||||
1978
|
||||
1428
|
||||
1635
|
||||
1386
|
||||
1858
|
||||
1602
|
||||
1916
|
||||
1906
|
||||
1212
|
||||
1730
|
||||
1777
|
||||
1698
|
||||
1845
|
||||
1812
|
||||
1922
|
||||
1729
|
||||
1803
|
||||
1761
|
||||
1901
|
||||
1748
|
||||
1188
|
||||
1964
|
||||
1935
|
||||
1919
|
||||
1810
|
||||
1567
|
||||
1849
|
||||
1417
|
||||
1452
|
||||
54
|
||||
1722
|
||||
1784
|
||||
1261
|
||||
1744
|
||||
1594
|
||||
1526
|
||||
1771
|
||||
1762
|
||||
1894
|
||||
1717
|
||||
1716
|
||||
51
|
||||
1955
|
||||
1143
|
||||
1741
|
||||
1999
|
||||
1775
|
||||
1944
|
||||
1983
|
||||
1962
|
||||
1198
|
||||
1553
|
||||
1835
|
||||
1867
|
||||
1662
|
||||
1461
|
||||
1811
|
||||
1764
|
||||
1726
|
||||
1927
|
||||
1179
|
||||
1468
|
||||
1948
|
||||
1813
|
||||
1213
|
||||
1905
|
||||
1371
|
||||
1751
|
||||
1215
|
||||
1392
|
||||
1798
|
||||
1823
|
||||
1815
|
||||
1923
|
||||
1942
|
||||
1987
|
||||
1887
|
||||
1838
|
||||
1395
|
||||
2007
|
||||
1479
|
||||
1752
|
||||
1945
|
||||
1621
|
||||
1538
|
||||
1937
|
||||
565
|
||||
1969
|
||||
1493
|
||||
1291
|
||||
1438
|
||||
1578
|
||||
1770
|
||||
2005
|
||||
1703
|
||||
1712
|
||||
1943
|
||||
2003
|
||||
1499
|
||||
1903
|
||||
1760
|
||||
1950
|
||||
1990
|
||||
1185
|
||||
1809
|
||||
1337
|
||||
1358
|
||||
1743
|
||||
1707
|
||||
1671
|
||||
1788
|
||||
1785
|
||||
1972
|
||||
1863
|
||||
1690
|
||||
1512
|
||||
1963
|
||||
1825
|
||||
1460
|
||||
1828
|
||||
1902
|
||||
1874
|
||||
1755
|
||||
1951
|
||||
1830
|
||||
1767
|
||||
1787
|
||||
1373
|
||||
1709
|
||||
1514
|
||||
1807
|
||||
1791
|
||||
1724
|
||||
1859
|
||||
1590
|
||||
1976
|
||||
1572
|
||||
1947
|
||||
1913
|
||||
1995
|
||||
1728
|
||||
1624
|
||||
1731
|
||||
1706
|
||||
1782
|
||||
1994
|
||||
1851
|
||||
1843
|
||||
1773
|
||||
1982
|
||||
1685
|
||||
2001
|
||||
1346
|
||||
1200
|
||||
1746
|
||||
1520
|
||||
972
|
||||
1834
|
||||
1909
|
||||
2008
|
||||
1733
|
||||
1960
|
||||
1280
|
||||
1879
|
||||
1203
|
||||
1979
|
||||
1133
|
||||
1647
|
||||
1282
|
||||
1684
|
||||
860
|
||||
1444
|
||||
1780
|
||||
1989
|
||||
1795
|
||||
1819
|
||||
1797
|
||||
1842
|
||||
1796
|
||||
1457
|
||||
1839
|
||||
1853
|
||||
1711
|
||||
1883
|
||||
1146
|
||||
1734
|
||||
1389
|
||||
66
1-report_repair/src/main.rs
Normal file
66
1-report_repair/src/main.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use std::io::{BufRead, BufReader};
|
||||
use std::path::{PathBuf, Path};
|
||||
use std::fs::File;
|
||||
use itertools::Itertools;
|
||||
|
||||
use structopt::StructOpt;
|
||||
|
||||
|
||||
#[derive(StructOpt, Debug)]
|
||||
struct Opt {
|
||||
/// Input file
|
||||
#[structopt(parse(from_os_str))]
|
||||
input_file: PathBuf,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Check argv
|
||||
let opts = Opt::from_args();
|
||||
// eprintln!("opts = {:?}", opts);
|
||||
// Load file if possible
|
||||
let file_path = Path::new(&opts.input_file);
|
||||
let input = File::open(file_path).unwrap();
|
||||
let buffered_input = BufReader::new(input);
|
||||
let lines: Vec<String> = buffered_input.lines().filter_map(Result::ok).collect();
|
||||
// eprintln!("lines_iter = {:?}", lines_iter);
|
||||
|
||||
/* First, naïve solution */
|
||||
// while let Some(line) = lines_iter.next() {
|
||||
// let iter_clone = lines_iter.clone();
|
||||
// // eprintln!("iter_clone = {:#?}", iter_clone);
|
||||
// for line2 in iter_clone {
|
||||
// let l1: i64 = line.parse().unwrap();
|
||||
// let l2: i64 = line2.parse().unwrap();
|
||||
// if l1 + l2 == 2020 {
|
||||
// eprintln!("l1 = {:#?}", l1);
|
||||
// eprintln!("l2 = {:#?}", l2);
|
||||
// dbg!(l1 + l2);
|
||||
// dbg!(l1 * l2);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
let res_two = find_2_sum_to_2020(lines.iter().filter_map(|x| Result::ok(x.parse::<i64>())).collect());
|
||||
let res_three = find_3_sum_to_2020(lines.iter().filter_map(|x| Result::ok(x.parse::<i64>())).collect());
|
||||
//let res_three = find_sum_to_2020(3);
|
||||
}
|
||||
|
||||
fn find_3_sum_to_2020(numbers: Vec<i64>) -> Option<(i64,i64, i64)> {
|
||||
for (i,j, k) in numbers.into_iter().tuple_combinations() {
|
||||
if i + j + k == 2020 {
|
||||
println!("Found {} and {} and {} whose sum is {} and whose product is {}", i, j, k, i+j+k, i*j*k);
|
||||
return Some((i,j,k));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn find_2_sum_to_2020(numbers: Vec<i64>) -> Option<(i64,i64)> {
|
||||
for (i,j) in numbers.iter().tuple_combinations() {
|
||||
if i + j == 2020 {
|
||||
println!("Found {} and {} whose sum is {} and whose product is {}", i, j, i+j, i*j);
|
||||
return Some((*i,*j));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
Reference in New Issue
Block a user