Skip to content

Instantly share code, notes, and snippets.

(*
Problem 1
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*)
let problem_1 n =
let mutable result = 0
let rec loop n r =
if n = 0 then r
else
(*
Problem 6
The sum of the squares of the first ten natural numbers is,
12 + 22 + ... + 102 = 385
The square of the sum of the first ten natural numbers is,
(1 + 2 + ... + 10)2 = 552 = 3025
Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 385 = 2640.
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
(*
Problem 2
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
Find the sum of all the even-valued terms in the sequence which do not exceed four million.
*)
let problem_2 bound =
let rec fsum prev preprev sum =
let nfib = prev + preprev
@55v
55v / gist:1286293
Created October 14, 2011 05:01
ML linear regression cost
// Learn more about F# at http://fsharp.net
#light
let T0 = 0.0
let T1 = 1.0
let m = 4.0
let X = [| 3.0; 1.0; 0.0; 4.0 |]
let Y = [| 2.0; 2.0; 1.0; 3.0 |]
//let XY = Array.zip(x y)
let h x = T0 + T1 * x
@55v
55v / Init-on-demand holder
Created February 11, 2012 16:28
Initialization-on-demand holder idiom example
public class Something {
private Something() {
}
private static class LazyHolder {
public static final Something INSTANCE = new Something();
}
public static Something getInstance() {
return LazyHolder.INSTANCE;
@55v
55v / holder_idiom.java
Created February 11, 2012 16:28
Initialization-on-demand holder idiom example
public class Something {
private Something() {
}
private static class LazyHolder {
public static final Something INSTANCE = new Something();
}
public static Something getInstance() {
return LazyHolder.INSTANCE;

Keybase proof

I hereby claim:

  • I am 55v on github.
  • I am 55v (https://keybase.io/55v) on keybase.
  • I have a public key ASAhXYTdsR19azNYI6Sm9b2kSrmgSL_-tZosuHrI4EzhiAo

To claim this, I am signing this object: