This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- want to get counts of people who's last name starts with a vowel (AEIOU) | |
| -- case, substring | |
| -- SUM(CASE WHEN x.thing = 'whatever' THEN 1 ELSE 0 END) as counts_of_whatever | |
| SELECT t.my_case_outcome, count(*) FROM ( | |
| SELECT c.*, substring(c.last_name, '^[AEIOUaeiou]') as x, | |
| CASE | |
| WHEN substring(c.last_name, '^[AEIOUaeiou]') IS NOT NULL THEN 'last_starts_vow' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Finding the area of a circle through simulation? | |
| import math | |
| import random | |
| def dart_throw_simulator(radius, runs): | |
| hits = 0 | |
| for run in range(runs): | |
| rand_x = random.uniform(-2,2) | |
| rand_y = random.uniform(-2,2) | |
| c_squared = (rand_x ** 2) + (rand_y ** 2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import random | |
| # Create a parent distribution, from the gamma family | |
| shape, scale = 2., 2. # mean=4, std=2*sqrt(2) | |
| s = np.random.gamma(shape, scale, 100000) | |
| print(np.mean(s)) | |
| import matplotlib.pyplot as plt | |
| import scipy.special as sps |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # How to determine sample size through simulation | |
| import random | |
| from collections import Counter | |
| things = ['camel', 'horse', 'donkey', 'mule', 'bulldozer', 'chain', 'machete', 'tool' ,'border collie', 'widget'] | |
| weights = [random.random() * 1000 for _ in range(10)] | |
| assert(len(things) == len(weights)) | |
| universe = random.choices(things, weights=weights, k=100000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # YouTube Walk Through: https://www.youtube.com/watch?v=8JwdenBGmEo&feature=youtu.be | |
| def return_change(to_return, coins = [.01, .05, .10, .25, 1.0, 5.0]): | |
| flag = None | |
| for c in coins: | |
| if c == to_return: return c | |
| if c < to_return: | |
| flag = c | |
| temp_balance = round(to_return - flag, 2) | |
| return [flag] + [return_change(temp_balance)] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # python 3.6 | |
| ### 10 heads in a row, 10 tails in a row | |
| from collections import Counter | |
| from itertools import groupby | |
| print(1 / (.50 ** 11)) | |
| # 1024 tosses to get 1 string of heads or tails consecutive | |
| outcomes = '' |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| numerals = {"I":1, "V":5, "X":10, "L": 50, "C": 100, "D": 500, "M": 1000 } | |
| def convert_roman(input_number): | |
| range_flag = None | |
| for symbol, integer in numerals.items(): | |
| if integer == input_number: return symbol | |
| if input_number > integer: | |
| range_flag = symbol | |
| remaining = input_number - numerals[range_flag] |