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 / 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 / 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 / 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 / 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 / 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 / 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 / car-and-diamond.md
Last active November 12, 2020 06:48
MPMP18(JGJG1) - The Car and the Diamond

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

The Car and the Diamond

A contestant is on a game show with five different prizes:

  • A car;
  • A diamond;
  • A goat;
  • A jar of bogeys; and,
@chrismilson
chrismilson / the-challenge.md
Created November 29, 2020 07:23
MPMP19 - The 19 Challenge

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

The 19 Challenge

If you sum of the squares of the first 19 primes you get a multiple of 19.

Find another number n that has the property that the sum of the squares of the first n primes is a multiple of n.

Solution

@chrismilson
chrismilson / python-zip.ts
Last active October 12, 2022 10:03
A python-like zip iterator in typescript
export type Iterableify<T> = { [K in keyof T]: Iterable<T[K]> }
/**
* Iterates over multiple iterable objects in parallel.
*
* Stops iteration when any of the iterators is done.
*/
export function* zip<T extends Array<any>>(
...toZip: Iterableify<T>
): Generator<T> {
@chrismilson
chrismilson / Tuple.d.ts
Last active January 22, 2021 05:58
Typescript Tuple Definition
/**
* Constructs tuples of `never` of length 2^K for all 0 ≤ K and 2^(K - 1) ≤ N.
* The tuples are in decreasing order by their lengths.
*
* The placeholder type `never` is chosen because it lets us test the length, as
* opposed to a generic type, which may be extended by undefined, and give us
* unexpected results.
*
* This type should not be used directly; it is a support type for Tuple.
*