Subscribe to The Madman Scribblings        RSS Feed
-----

FizzBuzz in Nemerle

Icon Leave Comment
Nemerle Version of FizzBuzz
using Nemerle.Collections;
using Nemerle.Text;
using Nemerle.Utility;

using System;
using System.Collections.Generic;
using System.Console;
using System.Linq;

module Program
{
  Main() : void
  {
   $[1 .. 100].Iter( x =>WriteLine("{0} {1}",x, x.FizzBuzz([(3,"Fizz"),(5,"Buzz")])));
    _ = ReadLine();
  }
 static public IsMultipleOf(this x:int,mn : IEnumerable[int]) : IEnumerable[bool]{ mn.Map( n => x.IsMultipleOf(n))}
 static public IsMultipleOf(this x:int,m:int):bool { (x % m) == 0 }
 static public FizzBuzz(this x:int, ns : IEnumerable[ int * string]) : string
 { x.IsMultipleOf(ns.Map(e=>e[0])).Select(
     (curr, i)=>
   {|(true, _)=>ns.ElementAt(i)[1];
    |(_   , _)=>""
 	 }).Aggregate((p,c)=>p+c);
 };
}

0 Comments On This Entry

 

Search My Blog

Recent Entries

Recent Comments