Skip to content

Instantly share code, notes, and snippets.

View groz's full-sized avatar

Tagir Magomedov groz

  • Amsterdam, NL
  • 07:38 (UTC +02:00)
View GitHub Profile
(define (smallest-divisor n)
(find-divisor n 2))
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(else (find-divisor n (+ test-divisor 1)))))
(define (divides? a b)
(= (remainder b a) 0))
@groz
groz / count-change.csm
Created September 4, 2016 16:41
count change in mit-scheme
(define (count-change coins amount)
(display coins) (newline)
(display amount) (newline)
(cond
((= 0 amount) 1)
((< amount 0) 0)
((null? coins) 0)
(else
(+
(count-change coins (- amount (car coins)))
@groz
groz / debounce_afisha.js
Last active August 28, 2016 19:13
Debounce afisha daily
// this is the lag source (decompiled code)
addEventScroll: function(e, t) {
var n = this;
e.attachEvent ? e.attachEvent("onscroll", function() {
t.call(n)
}) : e.addEventListener("scroll", function() {
t.call(n)
})
},
@groz
groz / deep_get.py
Last active January 10, 2022 13:17
Python deep_get
# coding=utf-8
from __future__ import unicode_literals
import collections
_default_stub = object()
def to_unicode(s):
if isinstance(s, str):
return unicode(s, 'utf8')
// $ SBT_OPTS="-Xmx12G" sbt run
object MainApp extends App {
def async[R](f: => R): Thread = new Thread {
override def run(): Unit = f
}
def parallel[A, B](f: => A, g: => B): (A, B) = {
var x: Option[A] = None
/*"""
Given a string s and a list of words w, determine if s can be split into a space-separated sequence of one or more words in w.
For example, given
s = "catdog"
w = ["dog", "car", "catch", "cat", "tiger", "at"]
==> True
s = "catdogtail"
w = ["dog", "car", "catch", "cat", "tiger", "at"]
@groz
groz / RandomAccessListApp.scala
Created April 22, 2016 01:42
Scala RandomAccessList
trait Node[+T] {
val index: Int
val left: Node[T]
val right: Node[T]
val len: Int
def apply(index: Int): T = ???
def update[X >: T](index: Int, value: X): Node[X] = ???
}
case object NullNode extends Node[Nothing] {
@groz
groz / parsers_lecture.hs
Created November 19, 2015 08:59
fp101x parsers lecture working example
module Parsers where
import Prelude hiding (fail, return, (>>=))
type Parser a = String -> [(a, String)]
item :: Parser Char
item [] = []
item (c:cs) = [(c, cs)]
fail :: Parser a
@groz
groz / FBSampleApp.scala
Created October 10, 2015 00:27
Facebook's how to crush your coding interview example in Scala.
object FBSampleApp extends App {
// sample implementations
def nearbyChars(c: Char): Set[Char] = Set(c + 0, c + 1).map(_.toChar)
def isWord(s: String): Boolean = true
def distSoFar(a: String, b: String) = a.zip(b).count(ab => ab._1 != ab._2)
def nearbyWords(input: String, maxDist: Int = 1): Set[String] =
input.foldLeft(Set("")) { (words, char) =>
for {
@groz
groz / main.cpp
Created September 30, 2015 08:48
Conway's Game of Life in C++
#include <iostream>
#include <set>
using namespace std;
struct Cell {
const long x, y;
Cell(long sx, long sy) : x(sx), y(sy) { }