This file contains 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 Foundation | |
func gcd(_ m: Int, _ n: Int) -> Int { | |
var a = 0 | |
var b = max(m, n) | |
var r = min(m, n) | |
while r != 0 { | |
a = b | |
b = r |
This file contains 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
''' | |
Chaos Game Sierpinski Triangle | |
Reference: https://www.youtube.com/watch?v=kbKtFN71Lfs | |
''' | |
import random | |
import matplotlib.pyplot as plt | |
from numpy.random import rand | |
def midPoint(p1, p2): | |
return ((p1[0] + p2[0]) / 2.0, (p1[1] + p2[1]) / 2.0) | |
This file contains 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
from random import randint | |
import math | |
def gcd(x,y): | |
while y!= 0: | |
(x, y) = (y, x % y) | |
return x | |
rolls = 1000 | |
max_int = 10000000000 |
This file contains 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 Foundation | |
let rolls = 1_000_000 | |
func getPi() -> Double { | |
func gcd(x: Int, y: Int) -> Int { | |
var internal_x = x | |
var internal_y = y | |
This file contains 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 PlaygroundSupport | |
import UIKit | |
class TableViewManager: NSObject, UITableViewDataSource, UITableViewDelegate { | |
weak var tableView: UITableView? | |
var strings = ["a", "b", "c", "d","e", "f", "g", "h","i", "j", "k", "dl","am", "bn", "co", "dp","aq", "br", "cs", "dt","au", "bv", "cw", "dx","ay", "bz", "caa", "dbb","acc", "bdd", "cee", "dff","agg", "bhh", "cii", "djj","akk", "bll", "cmm", "dnn","aoo", "bpp", "cqq", "zrr"] | |
func add(data: [String]) { |
This file contains 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
extension String { | |
///Get array of individual strings | |
func array() -> [String] { | |
return self.characters.map({ (char) -> String in | |
return String(char).lowercaseString | |
}) | |
} | |
///Get `NSCountedSet` from string | |
func countedSet() -> NSCountedSet { |
This file contains 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
from operator import mul | |
def sievePrimes(maximum): | |
primes = dict.fromkeys(range(3,maximum+1,2),True) | |
sieveList = [2] | |
for num in sorted(primes): | |
if primes[num] == True: | |
sieveList.append(num) | |
j = num ** 2 | |
while j < maximum: |
This file contains 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 UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var tableView: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
self.tableView.estimatedRowHeight = 44 |
NewerOlder