Skip to content

Instantly share code, notes, and snippets.

View kolharsam's full-sized avatar
🚀
Excelsior!

Sameer Kolhar kolharsam

🚀
Excelsior!
  • 23:24 (UTC -04:00)
View GitHub Profile
@kolharsam
kolharsam / goldenRatio.clj
Last active May 11, 2020 10:08
Cassidy's Interview Question - 10/5/20
;; Simple to implement I guess the real problem is of double/float precision
;; Will be updating once I learn more about those concepts within Clojure
(defn is-in-golden-ratio?
"Returns true if the pair of numbers are in the golden ratio"
[x y]
(let [x-y-ratio (quot x y)
greatest (max x y)
sum-ratio (quot (+ x y) greatest)]
(= x-y-ratio sum-ratio)))
@kolharsam
kolharsam / truffle-material.md
Created May 9, 2020 08:36 — forked from smarr/truffle-material.md
Truffle: Languages and Material
@kolharsam
kolharsam / oneRow.clj
Created May 4, 2020 17:09
Cassidy's Interview Question - 04/05/2020
(def default-input ["candy" "doodle" "pop" "shield" "lag" "typewriter" "this"])
(def qwerty-rows ["qwertyuiop" "asdfghjkl" "zxcvbnm"])
(def dvorak-rows ["pyfgcrl" "aoeuidhtns" "qjkxbmwvz"])
(def azerty-rows ["azertyuiop" "qsdfghjklm" "wxcvbn"])
(defn get-letter-row
"Returns the index of the row in which the letter is present"
@kolharsam
kolharsam / generateParenthesis.clj
Created April 13, 2020 16:08
Cassidy's Interview Question - 13/04
(require '[clojure.math.combinatorics :as combo]
'[clojure.string :as str])
(defn validParenthesis?
"Returns true if a sequence of parentheses are balanced"
[coll]
(loop [parens_list (apply list coll)
stack []]
(if (empty? parens_list)
(empty? stack)
@kolharsam
kolharsam / compareWithBackSpace.clj
Last active April 7, 2020 13:23
Cassidy's Interview Question - 07/04/20
(defn resultant_string
[str_a]
(loop [letters (clojure.string/split (apply str (reverse str_a)) #"")
letter_stack []]
(if (empty? letters)
(clojure.string/join letter_stack)
(let [current (peek letters)]
(if (= current "#")
(recur (pop letters) (if (empty? letter_stack) letter_stack (pop letter_stack)))
(recur (pop letters) (conj letter_stack current)))))))
@kolharsam
kolharsam / brokenCalculator.clj
Last active April 1, 2020 13:13
Cassidy's Interview Question - 30/03
(defn multiply-two [x] (* x 2))
(defn sub-one [x] (dec x))
(defn broken-calc
([start goal] (broken-calc start goal 0))
([start goal steps]
(if
(= start goal)
steps
@kolharsam
kolharsam / compress.js
Created March 26, 2020 15:52
Cassidy's Interview Question - 23/03/20
const compress = sortedArr => {
let currentLetterIndex = 0, letterCounter = 0, iter = 0;
// if we one of each letter
let maxIterations = sortedArr.length * 2;
while(iter < maxIterations) {
if (sortedArr[iter] === sortedArr[currentLetterIndex]) {
letterCounter++;
iter++;
@kolharsam
kolharsam / soln.hs
Created March 9, 2020 15:01
Cassidy's Interview Question - Mar 09/03/2020
import qualified Data.List as List
listSum :: (Num a) => [a] -> a
listSum [] = 0
listSum xs = foldr (+) 0 xs
getLength :: (Num a) => [a] -> a
getLength xs = foldr (\_ acc -> acc + 1) 0 xs
myGroup :: (Num a, Eq a, Ord a) => [a] -> [(a, Int)]
@kolharsam
kolharsam / lispParser.js
Created February 17, 2020 14:58
A Lisp Parser
/*
Runtime Env:
- Node v10.16.0
*/
/*
Problem Statement - Lisp Parser
Write code that takes some Lisp code and returns an abstract syntax tree.
The AST should represent the structure of the code and the meaning of each token.
@kolharsam
kolharsam / GameOfLife.py
Created January 19, 2020 13:16
Advent of Code - Day 18 - Both Parts
from os import system
start_grid = [line.rstrip('\n') for line in open("input")]
def printGrid(grid):
print("\n\n\n\n\n\n\n\n\n\n\n")
for r in grid:
print (''.join(r))
def getLightsOn(grid):
counter = 0