Skip to content

Instantly share code, notes, and snippets.

View SelectManyinClojure
(def x `(1 2 3))
(def y `(4 5 6))
(def z `(7 8 9))
(println (mapcat list x y z))
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 []
@naveensrinivasan
naveensrinivasan / sublist
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<List<_>>)) ->
match (flist,mainlist) with
|([],_) -> (ele::flist,mainlist)
|(h::_,_) when ele = h -> ((ele::flist),mainlist)
|(_::_,[]) -> ([ele], [flist])
|(_::_,_) -> ([ele],flist::mainlist)
@naveensrinivasan
naveensrinivasan / Readromannumerals
Created Sep 22, 2011
Read roman numerals in F#
View Readromannumerals
(*
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"))
@naveensrinivasan
naveensrinivasan / PrimeFactors.fs
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
@naveensrinivasan
naveensrinivasan / downloadextractlinqpad
Created Feb 28, 2013
Script to download and extract beta linqpad
View downloadextractlinqpad
#! /bin/sh
curl -O http://download.linqpad.net/preview/LINQPad4.zip
unzip -q -o -d /cygdrive/c/tools/ LINQPad4.zip
rm LINQPad4.zip
@naveensrinivasan
naveensrinivasan / conditionalbp
Created Mar 20, 2013
Conditional breakpoint in windbg.
View conditionalbp
as /c stack !CLRStack;
.if ($spat("${stack}","*Foo*"))
{ $$ do the evaluation}
View gist:5207506
0:000> !do @esi
Name: System.Data.SqlClient.SqlCommand
MethodTable: 60b9fcb0
EEClass: 60ac8eac
Size: 132(0x84) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll
Fields:
MT Field Offset Type VT Attr Value Name
6897f638 40001cf 4 System.Object 0 instance 00000000 __identity
662a2480 40001ae 8 ...ponentModel.ISite 0 instance 00000000 site
View gist:5207522
.foreach ( $obj {$$>a<"d:\Debuggersx86\dumplist.txt" poi(poi(poi(@esi+18)+8)+4)}) { !do poi(${$obj}+38)}
View gist:5207531
Name: System.Data.SqlClient.SqlParameter
MethodTable: 60ba012c
EEClass: 60ac8ef0
Size: 100(0x64) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll
Fields:
MT Field Offset Type VT Attr Value Name
6897f638 40001cf 4 System.Object 0 instance 00000000 __identity
60ba1e18 400195f 8 ...qlClient.MetaType 0 instance 00000000 _metaType
60ba3cac 4001960 c ...ient.SqlCollation 0 instance 00000000 _collation