This file contains hidden or 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
| let gridArray = | |
| let arr = (Array2D.init 20 20 (fun i j -> 0)) | |
| for i in [0..(grid.Split '\n').Length-1] do | |
| for j in [0..((grid.Split '\n').[0].Split ' ').Length-1] do | |
| arr.[i,j] <- int ((grid.Split '\n').[i].Split ' ').[j] | |
| arr |
This file contains hidden or 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
| (* Project Euler Problem 9 | |
| A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, | |
| a2 + b2 = c2 | |
| For example, 32 + 42 = 9 + 16 = 25 = 52. | |
| There exists exactly one Pythagorean triplet for which a + b + c = 1000. | |
| Find the product abc. | |
| *) |
This file contains hidden or 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
| let charToInt x = int (string x) | |
| let number = "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557668966489504452445231617318564030987111217223831136222989342338030813533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271218839987979087922749219016997208880937766572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408071984038509624554443629812309878799272442849091888458015616609791913387549920052406368991256071760605886116467109405077541002256983155200055935729725716362695618826704282524836 |
This file contains hidden or 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
| let generatePairs xs ys = | |
| let pairs = ref [] | |
| for i in xs do | |
| for j in ys do | |
| if (List.filter (fun y -> ((y = [i;j]) || y = [j;i])) !pairs = []) then | |
| printfn "%A" [i;j] | |
| pairs := [i;j] :: !pairs |
This file contains hidden or 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
| let euler4 = | |
| let largestPalindrome = ref 0 | |
| for i in 100..999 do | |
| for j in 100..999 do | |
| if pairMakesPalindrome i j && i*j > !largestPalindrome then | |
| largestPalindrome := i*j | |
| !largestPalindrome |
This file contains hidden or 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
| let rec primesIn (ns: int list) (x: int) = | |
| let newList = | |
| (List.choose (fun y -> | |
| match y with | |
| | y when (y % x = 0) -> None | |
| | _ -> Some y) ns) | |
| if newList.[0]*newList.[0] <= newList.[newList.Length-1] then | |
| x :: primesIn newList newList.[0] | |
| else x :: newList |
This file contains hidden or 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
| let rec primesIn (ns: int list) (x: int) = | |
| let newList = | |
| (x :: ((List.choose (fun y -> | |
| match y with | |
| | y when (y % x <> 0) -> Some y | |
| | _ -> None) ns).Tail)) | |
| if newList.[0]*newList.[1] <> newList.[newList.Length-1] then | |
| primesIn newList.Tail newList.[1] | |
| else ns |
This file contains hidden or 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
| let square x:float = x**2 | |
| let numbers = [1.0 .. 100.0] | |
| let sum_squares = List.reduce (+) (List.map (square) numbers) | |
| let square_sum = square (List.reduce (+) numbers) |
This file contains hidden or 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
| [<Measure>] type kg | |
| [<Measure>] type m | |
| [<Measure>] type s | |
| let gravityOnEarth = 9.81<m/s^2> | |
| let heightOfTowerOfPisa = 55.86<m> | |
| let speedOfImpact = sqrt(2.0 * gravityOnEarth * heightOfTowerOfPisa) |
This file contains hidden or 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
| let rec dividesIntoAllUpTo (n: int) (d: int) = | |
| match d with | |
| | 1 -> true | |
| | _ -> (n % d = 0) && (dividesIntoAllUpTo n (d - 1)) | |
| let matchesCriteria n = | |
| dividesIntoAllUpTo n 20 | |
| let main = | |
| let current_num = ref 20 |