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 math | |
def movie(card, ticket, perc): | |
ticket_num = 0 | |
sys_a = 0 | |
sys_b_prev = ticket | |
while math.ceil(card) >= sys_a: | |
sys_a += ticket | |
sys_b_prev *= perc | |
card += sys_b_prev | |
ticket_num += 1 |
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 math | |
def movie(card, ticket, perc): | |
ticket_num = 0 | |
sys_a = 0 | |
sys_b = 500 | |
sys_b_prev = ticket | |
while math.ceil(sys_b) > sys_a: | |
sys_a += ticket | |
sys_b_prev *= perc | |
sys_b += sys_b_prev |
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
# All credit to CodeWars users: S666, hahanbyul, Lukegb94, Vesmil, CBR | |
import math | |
def movie(card, ticket, perc): | |
num = 0 | |
priceA = 0 | |
priceB = card | |
while math.ceil(priceB) >= priceA: | |
num += 1 |
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
class Node{ | |
constructor(val){ | |
this.val = val | |
this.next = null; | |
} | |
} |
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
class Node{ | |
constructor(val){ | |
this.val = val | |
this.next = null; | |
} | |
} | |
function listContains(root, val){ | |
let curr = root; | |
while(curr){ |
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
class LinkedList{ | |
constructor(){ | |
this.root = null; | |
} | |
} |
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
class LinkedList{ | |
constructor(){ | |
this.root = null; | |
} | |
append(val){ | |
const newNode = new Node(val); | |
if(this.root){ | |
let curr = this.root; | |
while(curr.next){ |
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
class Heap{ | |
constructor(){ | |
this.array = new Array(50000); | |
this.length = 0; | |
} | |
guardEmpty(){ | |
if(this.length === 0) throw Error("Heap is Empty"); | |
} |
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
class MinHeap{ | |
constructor(){ | |
this.array = []; | |
} | |
// insert | |
insert(val){ | |
this.array.push(val); | |
this.bubbleUp(this.array.length - 1); | |
} |
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
// Use Monte Carlo to estimate pi to 3 decimals | |
// x^2 + y^2 = r^2 | |
// pi * r^2 | |
function randSpot(){ | |
return {x : Math.random(),y : Math.random()} | |
} | |
function getRadius({x,y}){ | |
return Math.sqrt(Math.pow(x,2) + Math.pow(y,2)); |