Permalink
Browse files

first commit

  • Loading branch information...
doomchild committed Oct 9, 2012
0 parents commit 726f506122478c7535587b4785d72c31908e8608
Showing with 536 additions and 0 deletions.
  1. +22 −0 .gitattributes
  2. +166 −0 .gitignore
  3. +3 −0 1.fs
  4. +7 −0 10.fs
  5. +27 −0 14.fs
  6. +14 −0 16.fs
  7. +13 −0 2.fs
  8. +6 −0 20.fs
  9. +6 −0 3.fs
  10. +15 −0 4.fs
  11. +13 −0 5.fs
  12. +11 −0 6.fs
  13. +5 −0 7.fs
  14. +32 −0 8.fs
  15. +20 −0 9.fs
  16. +2 −0 hl7v2.fs
  17. +47 −0 levenshtein.fs
  18. +127 −0 util.fs
@@ -0,0 +1,22 @@
+# Auto detect text files and perform LF normalization
+* text=auto
+
+# Custom for Visual Studio
+*.cs diff=csharp
+*.sln merge=union
+*.csproj merge=union
+*.vbproj merge=union
+*.fsproj merge=union
+*.dbproj merge=union
+
+# Standard to msysgit
+*.doc diff=astextplain
+*.DOC diff=astextplain
+*.docx diff=astextplain
+*.DOCX diff=astextplain
+*.dot diff=astextplain
+*.DOT diff=astextplain
+*.pdf diff=astextplain
+*.PDF diff=astextplain
+*.rtf diff=astextplain
+*.RTF diff=astextplain
@@ -0,0 +1,166 @@
+#################
+## Eclipse
+#################
+
+*.pydevproject
+.project
+.metadata
+bin/
+tmp/
+*.tmp
+*.bak
+*.swp
+*~.nib
+local.properties
+.classpath
+.settings/
+.loadpath
+
+# External tool builders
+.externalToolBuilders/
+
+# Locally stored "Eclipse launch configurations"
+*.launch
+
+# CDT-specific
+.cproject
+
+# PDT-specific
+.buildpath
+
+
+#################
+## Visual Studio
+#################
+
+## Ignore Visual Studio temporary files, build results, and
+## files generated by popular Visual Studio add-ons.
+
+# User-specific files
+*.suo
+*.user
+*.sln.docstates
+
+# Build results
+[Dd]ebug/
+[Rr]elease/
+*_i.c
+*_p.c
+*.ilk
+*.meta
+*.obj
+*.pch
+*.pdb
+*.pgc
+*.pgd
+*.rsp
+*.sbr
+*.tlb
+*.tli
+*.tlh
+*.tmp
+*.vspscc
+.builds
+*.dotCover
+
+## TODO: If you have NuGet Package Restore enabled, uncomment this
+#packages/
+
+# Visual C++ cache files
+ipch/
+*.aps
+*.ncb
+*.opensdf
+*.sdf
+
+# Visual Studio profiler
+*.psess
+*.vsp
+
+# ReSharper is a .NET coding add-in
+_ReSharper*
+
+# Installshield output folder
+[Ee]xpress
+
+# DocProject is a documentation generator add-in
+DocProject/buildhelp/
+DocProject/Help/*.HxT
+DocProject/Help/*.HxC
+DocProject/Help/*.hhc
+DocProject/Help/*.hhk
+DocProject/Help/*.hhp
+DocProject/Help/Html2
+DocProject/Help/html
+
+# Click-Once directory
+publish
+
+# Others
+[Bb]in
+[Oo]bj
+sql
+TestResults
+*.Cache
+ClientBin
+stylecop.*
+~$*
+*.dbmdl
+Generated_Code #added for RIA/Silverlight projects
+
+# Backup & report files from converting an old project file to a newer
+# Visual Studio version. Backup files are not needed, because we have git ;-)
+_UpgradeReport_Files/
+Backup*/
+UpgradeLog*.XML
+
+
+
+############
+## Windows
+############
+
+# Windows image file caches
+Thumbs.db
+
+# Folder config file
+Desktop.ini
+
+
+#############
+## Python
+#############
+
+*.py[co]
+
+# Packages
+*.egg
+*.egg-info
+dist
+build
+eggs
+parts
+bin
+var
+sdist
+develop-eggs
+.installed.cfg
+
+# Installer logs
+pip-log.txt
+
+# Unit test / coverage reports
+.coverage
+.tox
+
+#Translations
+*.mo
+
+#Mr Developer
+.mr.developer.cfg
+
+# Mac crap
+.DS_Store
+
+# emacs backup files
+*.fs~
3 1.fs
@@ -0,0 +1,3 @@
+let multiples = List.filter (fun x -> x % 3 = 0 || x % 5 = 0) [1 .. 999]
+let s = List.sum multiples
+printf "%i" s;;
7 10.fs
@@ -0,0 +1,7 @@
+#load "util.fs"
+open util
+
+let answer =
+ get_prime_sequence 2I
+ |> Seq.takeWhile (fun e -> e < 2000000I)
+ |> Seq.sum
27 14.fs
@@ -0,0 +1,27 @@
+#load "util.fs"
+open util
+
+let inline collatz n =
+ match n with
+ | x when n = 0G -> None
+ | x when n = 1G -> Some(1G, 0G)
+ | x when (n % 2G) = 0G -> Some(x, x / 2G)
+ | _ -> Some(n, (3G * n) + 1G)
+
+let inline get_collatz_sequence start =
+ Seq.unfold collatz start
+
+let inline coll_maxer (n:^a) (m:^a) max_length total =
+ let rec proc (n:^a) (m:^a) max_length total =
+ let len = Seq.length (get_collatz_sequence (int64 n))
+ let a =
+ if len >= max_length then
+ (n, len)
+ else
+ total
+ match n with
+ | x when n < m -> proc (n + 1G) m (max len max_length) a
+ | _ -> a
+ proc n m max_length (n, 0)
+
+let m = coll_maxer 3 1000000 0 0
14 16.fs
@@ -0,0 +1,14 @@
+#load "util.fs"
+open util
+
+let n = dpow 2I 1000I
+
+let inline decompose a =
+ let rec proc b =
+ let f, s = b
+ match f with
+ | x when f < 10G -> (f, s + f)
+ | _ -> proc (f / 10G, s + (f % 10G))
+ snd(proc (a, 0G))
+
+let answer = decompose n
13 2.fs
@@ -0,0 +1,13 @@
+open System.Numerics
+
+let limit = BigInteger(4000000 - 1)
+let fib =
+ Seq.unfold
+ (fun (current, next) -> Some(current, (next, current + next)))
+ (BigInteger 0, BigInteger 1)
+
+let even_fibs_sum =
+ fib
+ |> Seq.takeWhile (fun n -> n < limit)
+ |> Seq.filter (fun n -> n % bigint(2) = bigint(0))
+ |> Seq.sum
6 20.fs
@@ -0,0 +1,6 @@
+#load "util.fs"
+open util
+
+let n = fac 100I
+
+let answer = decompose n
6 3.fs
@@ -0,0 +1,6 @@
+#load "util.fs"
+open util
+
+let v = 600851475143I
+
+let s = Seq.max (seq { for i in factors v do if isPrime i then yield i })
15 4.fs
@@ -0,0 +1,15 @@
+#load "util.fs"
+open util
+
+let rec inner o i m =
+ let p = o * i
+ match p with
+ | p when isPalindrome p && i <= 2 -> max m p
+ | p when isPalindrome p -> inner o (i - 1) (max m p)
+ | _ -> inner o (i - 1) m
+
+let rec outer o m =
+ let f = inner o 999 m
+ match f with
+ | _ when o <= 2 -> max f m
+ | _ -> outer (o - 1) (max f m)
13 5.fs
@@ -0,0 +1,13 @@
+#load "util.fs"
+open util
+
+let nums = [3; 7; 8; 9; 11; 13; 16; 17; 19]
+
+let isDivisible x =
+ List.map (fun n -> x % n) nums
+ |> List.exists (fun e -> e <> 0)
+ |> not
+
+let find_divisible =
+ Seq.initInfinite (fun i -> 20 + (20 * i))
+ |> Seq.find (fun a -> (isDivisible a) = true)
11 6.fs
@@ -0,0 +1,11 @@
+#load "util.fs"
+open util
+
+let first_hundred_naturals = Seq.initInfinite (fun x -> x + 1) |> Seq.take 100
+let sum_squares = Seq.sum (Seq.map (fun x -> x * x) first_hundred_naturals)
+
+let s = Seq.sum first_hundred_naturals
+
+let square_sum = s * s
+
+let answer = abs(sum_squares - square_sum)
5 7.fs
@@ -0,0 +1,5 @@
+#load "util.fs"
+open util
+
+let t = get_prime_sequence ()
+let p = Seq.nth 10000 t
32 8.fs
@@ -0,0 +1,32 @@
+#load "util.fs"
+open util
+
+let s = Seq.map (fun i -> Int32.Parse (string i)) (Seq.filter (fun c -> Char.IsWhiteSpace c <> true) @"73167176531330624919225119674426574742355349194934
+96983520312774506326239578318016984801869478851843
+85861560789112949495459501737958331952853208805511
+12540698747158523863050715693290963295227443043557
+66896648950445244523161731856403098711121722383113
+62229893423380308135336276614282806444486645238749
+30358907296290491560440772390713810515859307960866
+70172427121883998797908792274921901699720888093776
+65727333001053367881220235421809751254540594752243
+52584907711670556013604839586446706324415722155397
+53697817977846174064955149290862569321978468622482
+83972241375657056057490261407972968652414535100474
+82166370484403199890008895243450658541227588666881
+16427171479924442928230863465674813919123162824586
+17866458359124566529476545682848912883142607690042
+24219022671055626321111109370544217506941658960408
+07198403850962455444362981230987879927244284909188
+84580156166097919133875499200524063689912560717606
+05886116467109405077541002256983155200055935729725
+71636269561882670428252483600823257530420752963450")
+
+
+let seq_prod (i : int) se =
+ if i < ((Seq.length s) - 5) then
+ Seq.reduce (fun a b -> a * b) (Seq.take 5 (Seq.skip i s))
+ else
+ 0
+
+let m = Seq.mapi seq_prod s
20 9.fs
@@ -0,0 +1,20 @@
+#load "util.fs"
+open util
+
+let rec inner b a =
+ let c = dsqrt(float((a * a) + (b * b)))
+ let p = float(a + b) + c
+
+ match p with
+ | 1000.0 -> a * b * (int c)
+ | _ when a >= 1000 -> -1
+ | _ -> inner b (a + 1)
+
+let rec outer b =
+ let prod = inner b 2
+ match prod with
+ | -1 when b >= 1000 -> 0
+ | -1 -> outer (b + 1)
+ | _ -> prod
+
+let answer = outer 2
@@ -0,0 +1,2 @@
+type HL7v2Message(msg : string) = class
+end
Oops, something went wrong.

0 comments on commit 726f506

Please sign in to comment.