Skip to content

Instantly share code, notes, and snippets.

Avatar

Shiang Yong Looi ShiangYong

View GitHub Profile
@ShiangYong
ShiangYong / main.py
Created Apr 15, 2017
Simulation code to solve the Riddler Classic puzzle (Supreme Court Judges),https://fivethirtyeight.com/features/how-many-bingo-cards-are-there-in-the-world/
View main.py
import numpy as np
def runSimulation(N):
judge_num = np.zeros(N, dtype=np.int)
for i in range(9):
judge_num[:(np.random.randint(0, 41))] += 1
for i in range(4, N, 4):
if np.random.random() > 0.5:
@ShiangYong
ShiangYong / four_square_ranches.py
Created Mar 19, 2017
Monte Carlo code to solve the Four Square Ranches (Riddler Classic), https://fivethirtyeight.com/features/can-you-find-the-honest-prince/
View four_square_ranches.py
import numpy as np
import time
import matplotlib.pyplot as plt
def isConvex(dx, dy):
for j in range(4):
if dx[j]*dy[(j+1) % 4] < dy[j]*dx[(j+1) % 4]:
return False
return True
@ShiangYong
ShiangYong / strategy.txt
Created Mar 16, 2017
Optimal Strategy and proof for the Space Race (Riddler Classic), https://fivethirtyeight.com/features/who-will-win-the-space-race/
View strategy.txt
The player that places first is guaranteed to win, as long as he/she uses the optimal strategy.
Winning Strategy
----------------
1. First player begins by placing the first coin right right at the center of the table
2. Second player places a coin anywhere on the table
3. First player tries to mimic second player's coin in the following way:
Imagine rotating the table about the center by 180 degrees, then place the coin where the second player's coin was before the rotation.
Done correctly, this newly placed coin makes the table look identical under a 180 degrees rotation about the center.
4. If there is no more space on the table, first player wins. Otherwise go back to Step 2.
@ShiangYong
ShiangYong / mnist.py
Created Jan 13, 2017
Deep convolutional neural network to solve MNIST classification problem. Adapted code from Anuj Shah's tutorial https://www.youtube.com/watch?v=yDVap0lpYKg.
View mnist.py
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten, normalization, Convolution2D, MaxPooling2D
from keras.utils import np_utils
import matplotlib.pyplot as plt
from sklearn import metrics
import numpy as np
# input image dimensions
View stormtroopers.nb
calcLimitingProb[K_] :=
Module[{p, n, plose, pdrop, pwin, tmp, solution},
p = {(999 K)/(1000 + 999 K)};
solution = {N[1000/999]};
For[n = 2, n <= 20, n++,
pdrop = (K*Sqrt[n]/1000)*(999/1000)^n;
plose = 1 - (999/1000)^n + (1 - p[[n - 1]])*pdrop;
pwin = p[[n - 1]]*pdrop;
tmp = Simplify[pwin/(plose + pwin)];
View main.py
import math
import matplotlib.pyplot as plot
def generate_path(speed, num_steps):
scaled_step = speed/num_steps
step = 1.0/num_steps
ram_x = [0] * (num_steps + 1)
ram_y = [0] * (num_steps + 1)
@ShiangYong
ShiangYong / main.py
Created Dec 6, 2016
Python code to solve the Secret Santa puzzle (Riddler Classic) from http://fivethirtyeight.com/features/can-you-unmask-the-secret-santas/
View main.py
import numpy as np
import math
import matplotlib.pyplot as plot
import time
def gen_rand_derang(n):
comparison = np.arange(n)
sigma = np.random.permutation(n)
View main.py
import statistics
import random
import numpy as np
import time
def repeated_cull_sim(initial_size, runs):
sum = 0
init_time = time.time()