Skip to content

Instantly share code, notes, and snippets.

View chrismilson's full-sized avatar

Chris Milson-Tokunaga chrismilson

  • In Transit
View GitHub Profile
@chrismilson
chrismilson / cats-and-dogs.md
Last active October 30, 2020 00:56
MPMP17 - Cats and Dogs

This is the seventeenth puzzle in Matt Parker's Matt Parker's Maths Puzzles puzzle series

Cats and Dogs

As the owner of a pet hotel, you have ten kennels in a row that you can put either a cat, or a dog into each night. Cats, being as they are, are not happy when placed adjacent to other cats. Dogs do not mind who they are next to though.

How many different ways are there to put cats and dogs into the ten kennels,

@chrismilson
chrismilson / odd-pascal.md
Last active October 16, 2020 06:11
MPMP 16 - Odd Pascal

This is the sixteenth puzzle in Matt Parker's Matt Parker's Maths Puzzles puzzle series

Odd Pascal

Pascal's triangle is a tower of integers. The first row contains a single 1 and subsequent rows are obtained by taking the sum of the two integers above a number. Here are the first 5 rows

@chrismilson
chrismilson / prime-pairs.md
Last active October 2, 2020 03:02
MPMP15 - Prime Pairs

This is the fifteenth puzzle in Matt Parker's Matt Parker's Maths Puzzles puzzle series

Prime Pairs

Submittable Puzzle

Find a permutation of the numbers 1 to 9 such that the sum of any two adjacent numbers is prime.

@chrismilson
chrismilson / card-order.md
Last active September 26, 2020 04:40
MPMP14 - The Card Order Puzzle

This puzzle is the fourteenth puzzle from the Matt Parker's Maths Puzzles series.

Card Order Puzzle

Submittable Puzzle

If you have four cards numbered 1 to 4, how many of the 24 permutations contain no subsequence of length three that is increasing or decreasing?

@chrismilson
chrismilson / JS-Quine.md
Last active August 25, 2020 07:05
Javascript Quine

The following javascript code will evaluate to itself:

(function f () {return `(${f})()`})()

That is, if x = (function f () {return `(${f})()`;})(), then x === eval(x) is true.

Code snippets like this are known as quines. I first learnt about quines in a video by the AI researcher and youtuber Lex Fridman.

@chrismilson
chrismilson / Marching-Band.md
Created August 7, 2020 05:31
MPMP12 - Marching Band

This puzzle is the twelfth puzzle from Matt Parker's Matt Parker's Maths Puzzles series.

Marching Band

You are creating a marching band. Your marching band must march in rows, but each row must have an equal number of performers in it. You want your marching band to be able to march in exactly 64 different formations.

Solution

@chrismilson
chrismilson / Power-of-a-Power.md
Last active August 6, 2020 01:33
Interview Question

Power of a Power

Write a program to determine whether a number, n, is a power of 2k.

clarification: n, k ≥ 0

Follow up: Can you do it with O(1) time and space complexity?

Examples

@chrismilson
chrismilson / green-bananas.md
Created July 31, 2020 06:42
An inspirational story

Green Bananas

When I was younger i had a great friend, Little Johnny. He was a very good boy. He woke up every morning at six sharp and promptly had a shower, ate his breakfast, and brushed his teeth before either leaving for school, or starting a shift in his mother's bakery on the weekends.

On one particular day at school the teacher annouced that we were going to have no more than two weeks to write speeches, which we would then have to present in front of the rest of the class. Johnny was stumped. He had absolutely

@chrismilson
chrismilson / david-and-anton.md
Last active July 27, 2020 02:19
David and Anton Puzzle - MPMP11

This puzzle is the eleventh puzzle from the Matt Parker's Maths Puzzles series.

David And Anton

David and Anton's ages combined equals 65. David is currently three times as old as Anton was when David was half as old as Anton will be when Anton is three times as old as David was when David was three times as old as Anton.

How old is David?

@chrismilson
chrismilson / Chromosome.py
Created July 22, 2020 03:37
My first genetic algorithm
from random import random
def countBits(num):
result = 0
while num:
result += 1
num &= num - 1
return result
def likelihood(probability):