Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Excelsior!

Sameer Kolhar kolharsam

🚀
Excelsior!
View GitHub Profile
@kolharsam
kolharsam / goldenRatio.clj
Last active May 11, 2020
Cassidy's Interview Question - 10/5/20
View goldenRatio.clj
;; 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 — forked from smarr/truffle-material.md
Truffle: Languages and Material
View truffle-material.md
@kolharsam
kolharsam / oneRow.clj
Created May 4, 2020
Cassidy's Interview Question - 04/05/2020
View oneRow.clj
(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 Apr 13, 2020
Cassidy's Interview Question - 13/04
View generateParenthesis.clj
(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 Apr 7, 2020
Cassidy's Interview Question - 07/04/20
View compareWithBackSpace.clj
(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 Apr 1, 2020
Cassidy's Interview Question - 30/03
View brokenCalculator.clj
(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 Mar 26, 2020
Cassidy's Interview Question - 23/03/20
View compress.js
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 Mar 9, 2020
Cassidy's Interview Question - Mar 09/03/2020
View soln.hs
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)]
View lispParser.js
/*
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 Jan 19, 2020
Advent of Code - Day 18 - Both Parts
View GameOfLife.py
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