This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Something { | |
private Something() { | |
} | |
private static class LazyHolder { | |
public static final Something INSTANCE = new Something(); | |
} | |
public static Something getInstance() { | |
return LazyHolder.INSTANCE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Something { | |
private Something() { | |
} | |
private static class LazyHolder { | |
public static final Something INSTANCE = new Something(); | |
} | |
public static Something getInstance() { | |
return LazyHolder.INSTANCE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
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 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
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 |