all stats

melody's stats

guessed the most

namecorrect guessesgames togetherratio

were guessed the most by

namecorrect guessesgames togetherratio

entries

round #99

submitted at
0 likes

guesses
comments 0

post a comment


main.rs ASCII text
 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
struct Polyomnio(Vec<(i8,i8)>);
impl Polyomnio {
	fn normalize_translation(&mut self) {
		let (min_x, min_y) = self.0.iter().fold((127,127),|(x,y),(z,w)| (x.min(*z),y.min(*w)));
		for (x, y) in &mut self.0 {
			*x -= min_x;
			*y -= min_y;
		}
	}
	fn push_superominos(&self, v: &mut Vec<Polyomnio>) {
		for xy in &self.0 {
			for dxy in [(0,-1),(0,1),(1,0),(-1,0)] {
				let new_xy = (xy.0+dxy.0, xy.1+dxy.1);
				if self.0.contains(&new_xy) { continue; }
				let mut new_polyomino = self.0.clone();
				new_polyomino.push(new_xy);
				v.push(Polyomnio(new_polyomino));
			}
		}
	}
}
impl PartialEq for Polyomnio {
	fn eq(&self, rhs: &Self) -> bool {
		if self.0.len() != rhs.0.len() {
			return false;
		}
		let (max_x, max_y) = self.0.iter().fold((0,0), |(x,y),(z,w)| (x.max(*z),y.max(*w)));
		fn test_under_transformation(a: &Polyomnio, b: &Polyomnio, f: impl Fn(i8,i8)->(i8,i8)) -> bool {
			for xy in &a.0 {
				if !b.0.contains(&f(xy.0, xy.1)) {
					return false;
				}
			}
			true
		}
		test_under_transformation(self, rhs, |x,y| (x,y))
		|| test_under_transformation(self, rhs, |x,y| (max_x-x,y))
		|| test_under_transformation(self, rhs, |x,y| (max_x-x,max_y-y))
		|| test_under_transformation(self, rhs, |x,y| (x,max_y-y))
		|| test_under_transformation(self, rhs, |x,y| (y,x))
		|| test_under_transformation(self, rhs, |x,y| (max_y-y,x))
		|| test_under_transformation(self, rhs, |x,y| (max_y-y,max_x-x))
		|| test_under_transformation(self, rhs, |x,y| (y,max_x-x))
	}
}

fn polyominos_of_size_n(n: usize) -> Vec<Polyomnio> {
	match n {
		0 => return vec![],
		1 => return vec![Polyomnio(vec![(0,0)])],
		_ => (),
	};
	let previous = polyominos_of_size_n(n-1);
	let mut polyominos = vec![];
	for p in previous {
		p.push_superominos(&mut polyominos);
	}
	// translate so min_x == 0 and min_y == 0
	for p in &mut polyominos {
		p.normalize_translation();
	}
	// deduplicate
	for i in (0..polyominos.len()).rev() {
		for j in 0..i {
			if polyominos[i] == polyominos[j] {
				polyominos.remove(i);
				break;
			}
		}
	}
	polyominos
}


fn main() {
	for n in 0..=10 {
		println!("number of {}-omnios: {}", n, polyominos_of_size_n(n).len());
	}
}