blob: 65ed1a0b2629cdd5489eb7e65d12ad8170cd6a73 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::env;
use std::fs::File;
use std::io::Read;
fn main() {
let args: Vec<String> = env::args().collect();
let filename = if args.len() == 1 {
"in/".to_owned() + args[0].split('/').last().unwrap() + ".pzl"
} else {
args[1].clone()
};
let mut f = File::open(filename).expect("cannot open file");
let mut content = String::new();
f.read_to_string(&mut content).expect("cannot read file");
let lines = content.trim_end().split("\n");
let mut nodes: HashMap<&str, HashSet<&str>> = HashMap::new();
let mut conns: HashSet<(&str, &str)> = HashSet::new();
for line in lines {
let (a, b) = line.split_once("-").unwrap();
nodes.entry(a).or_default().insert(b);
nodes.entry(b).or_default().insert(a);
conns.insert((a, b));
}
println!("{:?}", nodes);
let mut triplets: HashSet<Vec<&str>> = HashSet::new();
for n0 in nodes.keys() {
if n0.starts_with("t") {
for n1 in &nodes[n0] {
for n2 in &nodes[n1] {
for n3 in &nodes[n2] {
if n0 == n3 {
let mut v = [*n0, *n1, *n2].to_vec();
v.sort();
println!("{:?}", v);
triplets.insert(v);
}
}
}
}
}
}
let res1 = triplets.len();
let mut res2 = 0;
println!("res1: {}", res1);
println!("res2: {}", res2);
//assert_eq!(res1, );
//assert_eq!(res2, );
}
|