Warning: Spoilers ahead!nRecently, I enjoyed watching Squid Game non NetFlix.nThere is a particular episode where the players need to cross a glass bridge.nA related mathematical puzzle was posted onnFiveThirtyEight.nThe puzzlen|”’| |”’|n| |oooooooooooooooooo| |n| |oooooooooooooooooo| |n|”’| |”’|nnnThere is a bridge made of 18 pairs of glass squares.nThere are 16 Players. Their objective is crossing the bridge.nOne player at at time attempts to cross thenbridge by picking one glass square from the next pair and jumping ot it.nOn each pair, one square is tempered glass and can withstand a jump. nThe other is not. A player that lands on it will break it and die.nFind the average number of playersnthat make it to the other side.nnSimulate to solvennBeing a programmer, I find simulatingnthe solution more interesting than doing the math. So, here we go.nThis type of puzzle involves random variables and processesnand can be solved by running a simple Monte Carlo simulation.nIt’s not as fancy as it sounds! The basic premise is we define na single game run,nthen do this a bunch of times, collecting the number of alive players after each run. nFinally, we calculate the mean, median and mode of the data.nSome observations:nnThe bridge glass square configuration is random and varies in each game run.nIt follows that each jump is the equivalent of tossing a coin. In code, it looks like anrandom.randint(0, 1)ndying is basically guessing the wrong coin side. Assuming that 1 is the “bad glass”,nthen whenever the random generator returns a 1 the player dies.nwhatever the result, the rest of the players should be aware of it.nnHere is the entire Python code:n# Simulation of https://fivethirtyeight.com/features/can-you-survive-squid-game-riddler/nfrom random import randintnimport statisticsnntimes = 100000nndata = []n# bridge made up of 18 pairs of separated glass squares.nBRIDGE_SQUARES = 18nBAD_GLASS = 1nnfor i in range(times):n # In this round, you are one of the 16 remaining competitors.n alive_competitors = 16n known_squares = 0nn while known_squares < BRIDGE_SQUARES:n # everyone died!n if alive_competitors == 0:n breakn # choose one of the two squares in a pair to land on.n square_to_land = randint(0, 1)n if square_to_land == BAD_GLASS:n alive_competitors -= 1n # Once a pair is revealed all remaining competitors take notice.n known_squares += 1nn data.append(alive_competitors)nnmean = statistics.mean(data)nmedian = statistics.median(data)nmode = statistics.mode(data)nn# On average, how many of the competitors survive and make it to the nextn# round of the competition?nprint(f'alive competitors: mean: {mean} median: {median} mode: {mode}')nnnalso available as a gist
Category: software
Software behaviour
This article’s top highlight has had me thinking:nnSoftware is simply the encoding of human thought, and as such has an almost unbounded design space.nnI disagree with “simply”, if it means “merely/just/straightforwardly/plainly”.nYes, software behaviour tends to be predetermined by humans.nBut look at AlphaGo: It’s behaviour was not predetermined.nMove 37 was in nobody’s mind before it happened and changed how human Go mastersnthink about Go.
WordPress Rest API: Adding custom fields
WordPress 4.7 Introduced register_rest_field, which enables us to add custom fields to object types. Here is how to add one to a custom post type.
Visualizing Euclidean Rhythms in Python
Visualization can help explore the patterns of Euclidean rhythms. Here are some generated .png images using Python and pillow.
Euclidean rhythms in Python
Recently I’ve been playing around with Euclidean rhythms.nExploring stacked polyrhythms and asymmetrical looping.nI tend to prefer it’s output when not using gcd-based numbers (the original paper used it to recreate middle-eastern/traditional rhythms).nThe Python implementation I am using
How to quickly log into a Debian Docker container
Debian can be hard to install for a beginner.nDocker is great for experimenting with it without having to install and boot into it. Here is how:
Tools for local WordPress development
These plugins and tools will help smooth your local/staging WordPress development experience
How to check for undefined in JavaScript
Some progressively better ways to strictly check for undefined in JavaScript.