Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace MathsShit
- {
- class Program
- {
- struct RatingSet : IEquatable<RatingSet>
- {
- public int P1, P2, P3;
- public IEnumerable<RatingSet> GetPermutations()
- {
- yield return new RatingSet { P1 = P1, P2 = P3, P3 = P2 };
- yield return new RatingSet { P1 = P2, P2 = P1, P3 = P3 };
- yield return new RatingSet { P1 = P2, P2 = P3, P3 = P1 };
- yield return new RatingSet { P1 = P3, P2 = P1, P3 = P2 };
- yield return new RatingSet { P1 = P3, P2 = P2, P3 = P1 };
- }
- public int BiggestDiff
- {
- get
- {
- return Math.Max(Math.Max(Math.Abs(P1 - P2), Math.Abs(P1 - P3)), Math.Abs(P2 - P3));
- }
- }
- public override string ToString()
- {
- return string.Format("{0}/10, {1}/10, {2}/10", P1, P2, P3);
- }
- public MoneySet ToMoney()
- {
- float sum = P1 + P2 + P3;
- return new MoneySet
- {
- P1 = (int)(P1 * 10000 / sum),
- P2 = (int)(P2 * 10000 / sum),
- P3 = (int)(P3 * 10000 / sum)
- };
- }
- public bool Equals(RatingSet other)
- {
- return P1 == other.P1 && P2 == other.P2 && P3 == other.P3;
- }
- }
- struct MoneySet
- {
- public int P1, P2, P3;
- public RatingSet JakesMethod()
- {
- return new RatingSet
- {
- P1 = P1 / 500,
- P2 = P2 / 500,
- P3 = P3 / 500
- };
- }
- }
- static void Main(string[] args)
- {
- HashSet<RatingSet> considered = new HashSet<RatingSet>();
- int cnt = 0;
- for (int i = 1; i < 10; i++)
- {
- for (int j = 1; j < 10; j++)
- {
- for (int k = 1; k < 10; k++)
- {
- RatingSet ratings = new RatingSet { P1 = i, P2 = j, P3 = k };
- MoneySet money = ratings.ToMoney();
- RatingSet jakeratings = money.JakesMethod();
- if (ratings.Equals(jakeratings) && jakeratings.BiggestDiff <= 2)
- {
- bool duplicate = false;
- foreach (var perm in jakeratings.GetPermutations())
- {
- if (considered.Contains(perm))
- {
- duplicate = true;
- break;
- }
- }
- if (!duplicate)
- {
- considered.Add(ratings);
- Console.WriteLine("Permutation found! {0}", ratings);
- cnt++;
- }
- }
- }
- }
- }
- Console.WriteLine("End of testing. {0} permutations found.", cnt);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment