Skip to content

Instantly share code, notes, and snippets.

Avatar

Peter Anderson BWPanda

View GitHub Profile
@BWPanda
BWPanda / 19.py
Created Nov 25, 2020
'19 Challenge' puzzle
View 19.py
"""
Solving the '19 Challenge' puzzle:
https://www.think-maths.co.uk/19challenge
(https://www.youtube.com/watch?v=tBXGIXEV7tI)
This script requires a file, `primes`, to be located in the same directory. It
should contain a list of prime numbers, one per line. I used the first million
primes from https://primes.utm.edu/lists/small/millions/.
"""
@BWPanda
BWPanda / cats_dogs.py
Created Oct 29, 2020
'Arranging Cats & Dogs' puzzle
View cats_dogs.py
"""
Solving the 'Arranging Cats & Dogs' puzzle:
https://www.think-maths.co.uk/catsanddogs
(https://www.youtube.com/watch?v=8gppjTZ1vCE)
"""
import itertools
def main():
for arrangement in itertools.product('CD', repeat=10):
@BWPanda
BWPanda / pascal.py
Created Oct 15, 2020
'Pascal's Triangle' puzzle
View pascal.py
"""
Solving the "Pascal's Triangle" puzzle:
https://www.think-maths.co.uk/pascaltriangle
(https://www.youtube.com/watch?v=tjJ2qL9uaz4)
"""
# Start triangle with the first few rows pre-filled.
triangle = [
[1],
[1, 1],
@BWPanda
BWPanda / prime_pairs.py
Created Oct 1, 2020
'Prime Pairs' puzzle
View prime_pairs.py
"""
Solving the 'Prime Pairs' puzzle:
https://www.think-maths.co.uk/primepairs
(https://www.youtube.com/watch?v=AXfl_e33Gt4)
"""
import itertools
# Check permutations of numbers from 1 to this value. Can't exceed 36, unless we
# add more primes to the list below.
@BWPanda
BWPanda / 80-chars.py
Last active Sep 24, 2020
Find comments longer than 80 characters
View 80-chars.py
"""
Checks all files with a given extension, in a given directory, and displays any
comment lines (i.e. starting with '//' or '*') that are longer than 80
characters.
"""
import glob
import sys
@BWPanda
BWPanda / card_order.py
Created Sep 16, 2020
'Card order' puzzle
View card_order.py
"""
Solving the 'Card Order' puzzle:
https://www.think-maths.co.uk/card-order
(https://www.youtube.com/watch?v=8I1OCqX93XI)
"""
import itertools
# Check a subset of 3 cards to see if they're in ascending or descending order.
def in_order(subset):
@BWPanda
BWPanda / ellipse.py
Created Sep 4, 2020
'Optimal ellipse' puzzle
View ellipse.py
"""
Solving the 'Optimal Ellipse' puzzle:
https://www.think-maths.co.uk/ellipsepuzzle
(https://www.youtube.com/watch?v=qJSHdJX6gB0)
'a' and 'b' are the semi-major and semi-minor axes respectively.
'd' is the distance between the foci.
"""
import math
@BWPanda
BWPanda / marching_band.py
Created Aug 6, 2020
'Marching Band' puzzle
View marching_band.py
"""
Solving the 'Marching Band' puzzle:
https://www.think-maths.co.uk/marchingband
(https://www.youtube.com/watch?v=5GZ5IqxAt30)
"""
import math
def formations(performers):
formations = []
@BWPanda
BWPanda / avoidsquare.py
Last active Jul 9, 2020
'Avoid the Squares' puzzle
View avoidsquare.py
"""
Solving the 'Avoid the Square' puzzle:
https://www.think-maths.co.uk/avoidthesquare
(https://www.youtube.com/watch?v=FMQQFbZaQTk)
Players' tokens are represented by 'x's and 'o's.
"""
import itertools
@BWPanda
BWPanda / triangles.py
Created Jun 26, 2020
'Take-Away Triangles' puzzle
View triangles.py
"""
Solving the 'Take-Away Triangles' puzzle:
https://www.think-maths.co.uk/trianglepuzzle
(https://www.youtube.com/watch?v=WZnVOYGLiy4)
"""
import itertools
# Create a new set of numbers by finding the difference of each pair of numbers
# in the given set.