Created
November 14, 2011 13:52
-
-
Save jonathascosta/1363986 to your computer and use it in GitHub Desktop.
Problem 30
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static long Solve() | |
{ | |
var powers = new List<long>(); | |
var numbers = new List<long>(); | |
for (int i = 0; i < 10; i++) | |
powers.Add((long)BigInteger.Pow(i, 5)); | |
for (int a = 0; a < 10; a++) | |
for (int b = 0; b < 10; b++) | |
for (int c = 0; c < 10; c++) | |
for (int d = 0; d < 10; d++) | |
for (int e = 0; e < 10; e++) | |
for (int f = 0; f < 10; f++) | |
{ | |
var number = powers[a] + powers[b] + powers[c] + powers[d] + powers[e] + powers[f]; | |
var ns1 = number.ToString().PadLeft(6, '0').Select(x => int.Parse(x.ToString())).OrderBy(x => x); | |
var ns2 = new int[] { a, b, c, d, e, f }.OrderBy(x => x); | |
if (ns1.SequenceEqual(ns2)) | |
if (!numbers.Contains(number)) | |
numbers.Add(number); | |
} | |
return numbers.Sum(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment