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
#Take any number you want than follow given instuctions. | |
#If it is even divide it by 2, if odd multiply by 3 and add 1 then keep going, | |
#writing down the sequence of numbers that you generate. | |
#It seems no matter what number you start with you eventually hit a 1. | |
#These sequences are called the "hailstone numbers" because, like hailstones, | |
#they go up and down a number of times before inevitably falling to Earth. | |
def hailstone(n): |
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
# Project Euler | |
# Multiples of 3 and 5 | |
# 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. | |
def multiples_of_three_and_five(): |
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
# Even Fibonacci numbers | |
# 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, ... | |
# | |
# By considering the terms in the Fibonacci sequence whose values do not exceed four million, | |
# find the sum of the even-valued terms. |
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
# This code is curently really slow and has not | |
# been optimized for speed. | |
# Largest prime factor | |
# Problem 3 | |
# | |
# The prime factors of 13195 are 5, 7, 13 and 29. | |
# | |
# What is the largest prime factor of the number 600851475143 ? |
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
// Simple version. | |
printfn "Hello, world." | |
// More complex one that taught me about | |
// type coercion going on behind curtains | |
let hello = "Hello, world" | |
printfn "%s" hello | |
// Note that |
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
let numbers = [0..100] | |
match with numbers | |
| is divisible by 3 -> printfn "Fizz %d" current number | |
| is divisible by 5 -> printfn "Buzz %d" current number | |
| is divisible by 3 and 5 -> printfn "FizzBuzz %d" current number | |
// I know this is wrong, because I'm still thinking procedurally. | |
// It's going to be fun figuring this one out and coming back to see where I was wrong. |
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
// Still a work in progress. | |
// This code runs and returns | |
// two lists with the results. | |
// Now need to simplify so | |
// results are returned as one list. | |
let fizz x = | |
match x % 3 = 0 with | |
| true -> "Fizz" |
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
// This is the third iteration | |
// of FizzBuzz in F#. | |
// This version works. | |
// Not optimized or checked for idioms. | |
let FizzBuzz x = | |
match x with | |
| x when x % 3 = 0 -> "Fizz" | |
| x when x % 5 = 0 -> "Buzz" | |
| x when x % 3 = 0 && x % 5 = 0 -> "FizzBuzz" |
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
# Project Euler | |
# Largest palindrome product | |
# Problem 4 | |
# A palindromic number reads the same both ways. | |
# The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. | |
# Find the largest palindrome made from the product of two 3-digit numbers. | |
# Note: this is v0.1 of this solution. It is not optimized or pretty in any way. |
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
# Smallest multiple | |
# Problem 5 | |
# | |
# 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. | |
# | |
# What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? | |
# This is not the actual solution (although it solves the problem) | |
# This is an exercise to figure out the problem before optimizing the code. |
OlderNewer