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
(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)) | |
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
(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))) |
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
// 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) | |
}) | |
}, |
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
# 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') |
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
// $ 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 |
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
/*""" | |
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"] |
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
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] { |
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
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 |
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
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 { |
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
#include <iostream> | |
#include <set> | |
using namespace std; | |
struct Cell { | |
const long x, y; | |
Cell(long sx, long sy) : x(sx), y(sy) { } |