Commits

Dominic Kexel committed 6661150

added F#

  • Participants
  • Parent commits e32ad4a

Comments (0)

Files changed (1)

+let args = System.Environment.GetCommandLineArgs()
+
+if args.Length <> 2
+then 
+    System.Console.WriteLine("Usage: Adler32 [filename]")
+    exit 0
+
+let _base = 65521
+    
+let proceed (a, b) (x : byte) = 
+    let a' = (a + (int x)) % _base
+    let b' = (a' + b) % _base
+    (a', b')
+    
+let adler32 data = 
+    let (a, b) = Array.fold proceed (1, 0) data
+    int (b <<< 16) ||| a
+
+System.Console.WriteLine (adler32 (System.IO.File.ReadAllBytes args.[1]))