Skip to content

Instantly share code, notes, and snippets.

#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):
# 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():
# 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 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 ?
@yelluw
yelluw / hello-world.fs
Last active February 7, 2017 04:17
Hello world in F#.
// 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
@yelluw
yelluw / fizzbuzz.fs
Created February 7, 2017 06:12
Understading fizzbuzz in F#. This code and pseudo code are to document my state before while learning the language.
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.
// 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"
@yelluw
yelluw / fizzbuzz.fs
Last active February 15, 2017 04:19
Third iteration of implementing FizzBuzz in F#. Run it here -> https://repl.it/Fcyx/0
// 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"
# 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.
@yelluw
yelluw / smallest-multiple.py
Last active February 15, 2017 03:45
Project Euler problem #5: Smallest multiple. First draft of problem.
# 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.