Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _25points;
- public static class Program {
- public static void Main() {
- int size = 9, size2 = size * size;
- int X(int n) => n / size;
- int Y(int n) => n % size;
- int cnt;
- int max = size * 2;
- var p = new int[max];
- void Show() {
- for (int i = 0; i < cnt; i++)
- Console.Write($" ({X(p[i])};{Y(p[i])})");
- }
- void Show1() {
- Console.WriteLine();
- for (int i = 0; i < size2; i++) {
- if (Array.IndexOf(p, i) >= 0) {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.Write(" •");
- } else {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.Write(" •");
- }
- if ((i + 1) % size == 0) Console.Write("\n");
- }
- Console.ForegroundColor = ConsoleColor.White;
- }
- bool Test() {
- if (cnt < 3) return true;
- double x = X(p[cnt - 1]), y = Y(p[cnt - 1]);
- for (int i = 0; i < cnt - 2; i++) {
- double x1 = X(p[i]), y1 = Y(p[i]);
- for (int j = i + 1; j < cnt - 1; j++) {
- double x2 = X(p[j]), y2 = Y(p[j]);
- if ((x - x1) * (y - y2) == (x - x2) * (y - y1)) return false;
- }
- }
- return true;
- }
- bool[,] F() {
- var f = new bool[size, size];
- for (int i = 0; i < max; i++) {
- f[X(p[i]), Y(p[i])] = true;
- }
- return f;
- }
- bool Eq(bool[,] f0, bool[,] f) {
- bool[,] Copy(bool[,] f) {
- var ff = new bool[size, size];
- for (int i = 0; i < size; i++)
- for (int j = 0; j < size; j++)
- ff[i, j] = f[i, j];
- return ff;
- }
- bool[,] Op1(bool[,] f) {
- var ff = new bool[size, size];
- for (int i = 0; i < size; i++)
- for (int j = 0; j < size; j++)
- ff[size - 1 - i, j] = f[i, j];
- return ff;
- }
- bool[,] Op2(bool[,] f) {
- var ff = new bool[size, size];
- for (int i = 0; i < size; i++)
- for (int j = 0; j < size; j++)
- ff[j, i] = f[i, j];
- return ff;
- }
- var ff = Copy(f0);
- for (int i = 0; i < 8; i++) {
- bool eq = true;
- ff = ((i & 1) == 0 ? Op1(ff) : Op2(ff));
- for (int j = 0; j < size; j++)
- for (int k = 0; k < size; k++)
- if (ff[j, k] != f[j, k]) eq = false;
- if (eq) return true;
- }
- return false;
- }
- var l = new List<bool[,]>();
- cnt = 1;
- int cnt1 = 0;
- p[0] = 0;
- bool tst = true;
- while (cnt > 0) {
- if (tst) {
- //Console.Clear();
- //Show();
- if (cnt == max) {
- //Console.Clear();
- //Console.WriteLine("OK" + (++cnt1));
- bool[,] f = F();
- bool test1 = true;
- for (int i = 0; i < l.Count; i++)
- if (Eq(l[i], f)) { test1 = false; break; }
- if (test1) {
- Show1();
- l.Add(f);
- }
- //return;
- //Console.ReadLine();
- tst = false;
- } else {
- if (p[cnt - 1] < size2 - 1) {
- cnt++;
- p[cnt - 1] = p[cnt - 2] + 1;
- tst = Test();
- } else {
- cnt--;
- tst = false;
- }
- }
- } else {
- if (p[cnt - 1] < size2 - 1) {
- p[cnt - 1]++;
- tst = Test();
- } else cnt--;
- }
- }
- Console.WriteLine(l.Count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement