Skip to content

Instantly share code, notes, and snippets.

View Shaddyjr's full-sized avatar
📉
You must construct additional models

Mahdi Shadkam-Farrokhi Shaddyjr

📉
You must construct additional models
View GitHub Profile
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
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
# 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
class Node{
constructor(val){
this.val = val
this.next = null;
}
}
class Node{
constructor(val){
this.val = val
this.next = null;
}
}
function listContains(root, val){
let curr = root;
while(curr){
class LinkedList{
constructor(){
this.root = null;
}
}
class LinkedList{
constructor(){
this.root = null;
}
append(val){
const newNode = new Node(val);
if(this.root){
let curr = this.root;
while(curr.next){
@Shaddyjr
Shaddyjr / medianHeap.js
Created October 13, 2019 01:56
HackerRank "Find the Running Median"
class Heap{
constructor(){
this.array = new Array(50000);
this.length = 0;
}
guardEmpty(){
if(this.length === 0) throw Error("Heap is Empty");
}
@Shaddyjr
Shaddyjr / heapSort.js
Last active October 14, 2019 16:50
Implementation of the heap sort algorithm. Includes a MinHeap implementation with abstracted functionality to quickly turn it into a MaxHeap.
class MinHeap{
constructor(){
this.array = [];
}
// insert
insert(val){
this.array.push(val);
this.bubbleUp(this.array.length - 1);
}
// 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));