In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
It is possible to make £2 in the following way:
1x£1 + 1x50p + 2x20p + 1x5p + 1x2p + 3x1p
How many different ways can £2 be made using any number of coins?
Triple-click for answer: 73682
using System;
namespace project_euler
{
class Program
{
static void Main()
{
//Problem 31
DateTime start = DateTime.Now;
int count = 0;
for (int a = 0; a <= 200; a += 200)
for (int b = 0; a + b <= 200; b += 100)
for (int c = 0; a + b + c <= 200; c += 50)
for (int d = 0; a + b + c + d <= 200; d += 20)
for (int e = 0; a + b + c + d + e <= 200; e += 10)
for (int f = 0; a + b + c + d + e + f <= 200; f += 5)
for (int g = 0; a + b + c + d + e + f + g <= 200; g += 2)
for (int h = 0; a + b + c + d + e + f + g + h <= 200; h++)
if (a + b + c + d + e + f + g + h == 200)
count++;
Console.WriteLine(count);
TimeSpan time = DateTime.Now - start;
Console.WriteLine("This took {0}", time);
Console.ReadKey();
}
}
}
No comments:
Post a Comment