// The Computer Language Shootout // http://shootout.alioth.debian.org/ // contributed by Micky Latowicki, translated from the python program (itself translated from the lua) // Date: May 7, 2007 #pragma indent using System using System.Collections.Generic using Nemerle.Imperative module CheapConcurrency MakeChain(n:int) : IEnumerable[int] if (n > 1) foreach (x in MakeChain(n-1)) yield x+1 else while(true) yield 1 SumUpPrefix(xs: IEnumerable[int], mutable n:int) : int mutable total = 0 foreach (x in xs) when (n==0) break total += x n -= 1 total public Main() : void def n = int.Parse(Environment.GetCommandLineArgs()[1]) Console.WriteLine(SumUpPrefix(MakeChain(500), n))