Example #1
0
		public P039 ()
		{
			var res = new Dictionary<int, int> ();

			for (int p = 3; p <= 1000; p++) {
				int n = 0;
				for (int a = 1; a <= p - 2; a++) {
					for (int b = a; a + b <= p - 1; b++) {
						var c = p - a - b;
						if (a * a + b * b == c * c) {
							Console.WriteLine (p + "\t" + a + "\t" + b + "\t" + c);
							n++;
						}
					}
				}
				res.Add (p, n);
			}

			Console.WriteLine (res.MinBy (x => -x.Value));
		}
Example #2
0
        public Location NextEmpty()
        {
            if (_emptySpaces.Count == 0)
            {
                return null;
            }

            var possibles = new Dictionary<Location, List<int>>();

            foreach (var emptySpace in _emptySpaces)
            {
                possibles[emptySpace] = TotalSpaceValues.Except(UsedNumbersInSpace(emptySpace)).ToList();

                if (possibles[emptySpace].Count == 1)
                {
                    Set(emptySpace, possibles[emptySpace].First());

                    return NextEmpty();
                }
            }
//
//            foreach (var possible in possibles)
//            {
//                if (possible.Value.Count == 1)
//                {
//                    Set(possible.Key, possible.Value.First());
//
//                    return NextEmpty();
//                }
//            }

            return possibles.MinBy(kvp => kvp.Value.Count()).Key;
        }