{{ message }}

Instantly share code, notes, and snippets.

# Naveen naveensrinivasan

Created Aug 25, 2011
C# SelectMany in Clojure
View SelectManyinClojure
 (def x `(1 2 3)) (def y `(4 5 6)) (def z `(7 8 9)) (println (mapcat list x y z))
Created Sep 19, 2011
Perfect Numbers http://4clojure.com/problem/80
View PerfectNumbers
 //perfect number //http://4clojure.com/problem/80 let perfectnumber x = let rec divisor x counter l= match counter < x with |true when x % counter < 1-> divisor x (counter + 1) (counter::l) |true -> divisor x (counter + 1) l |_ -> (l |> List.fold (+) 0) = x divisor x 1 []
Created Sep 20, 2011
Pack consecutive duplicates of list elements into sublists.
View sublist
 //P09 Pack consecutive duplicates of list elements into sublists. // https://sites.google.com/site/prologsite/prolog-problems/1 let packDups l = let result = List.foldBack ( fun ele (flist,(mainlist:List>)) -> match (flist,mainlist) with |([],_) -> (ele::flist,mainlist) |(h::_,_) when ele = h -> ((ele::flist),mainlist) |(_::_,[]) -> ([ele], [flist]) |(_::_,_) -> ([ele],flist::mainlist)
Created Sep 22, 2011
 (* http://4clojure.com/problem/92 Roman numerals are easy to recognize, but not everyone knows all the rules necessary to work with them. Write a function to parse a Roman-numeral string and return the number it represents. You can assume that the input will be well-formed, in upper-case, and follow the subtractive principle. You don't need to handle any numbers greater than MMMCMXCIX (3999), the largest number representable with ordinary letters. (= 14 (__ "XIV"))
Created Nov 16, 2012
Prime and Prime factors
View PrimeFactors.fs
 let isprime i = List.filter(fun x -> i%x = 0) [1..i] |> List.length = 2 let primefactor x = let rec innerprime number divisor l= let intermedidate = number /divisor match (not(isprime intermedidate ),number > divisor) with |true,true when number % divisor = 0 -> innerprime intermedidate divisor (divisor::l) |_,true when number % divisor = 0 -> intermedidate::divisor::l
Created Feb 28, 2013