Adam Gordon Bell

C#

Tag: C#

Project Euler #24 in c#

November 11, 2010 · euler c#

A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:

012   021   102   120   201   210

What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?

Read more →

Introducing Attribute Based Caching

October 26, 2010 · c# attribute-based-caching

“There are only two hard problems in computer science: cache invalidation, naming things, and off-by-one errors.”

I am a big fan of postsharp and its creator Gael.  There are a number of examples floating around of doing caching with postsharp.  However, none handled cache invalidation in a nice declarative way.  

Read more →

Project Euler #5

October 6, 2010 · euler c#

Here is my solution to the following project Euler Problem:

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?

Read more →

Project Euler #6

October 6, 2010 · euler c#

Ok, this one is stupidly simple:

var squaredsum = Math.Pow(1.To(100).Sum(), 2);
var sumedsquare = 1.To(100).Select(x => x * x).Sum();
Console.WriteLine(squaredsum - sumedsquare);