Skip to content

Instantly share code, notes, and snippets.

View snahor's full-sized avatar

Hans Roman snahor

  • Wakanda
View GitHub Profile
@snahor
snahor / hofstadter.sml
Last active September 10, 2017 09:19
Hofstadter sequences
(*
* Hofstadter sequences
* https://en.wikipedia.org/wiki/Hofstadter_sequence
*)
signature QUEUE =
sig
type 'a queue = 'a list * 'a list
val empty: 'a queue
val enqueue: 'a -> 'a queue -> 'a queue
def fib():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
import random
import curses
import sys
import time
class Board(object):
WINNING_COMBOS = (
(0, 1, 2),
(3, 4, 5),
fun help () = print "Run me as: \n\tpoly -q --use foo.sml --eval 'val _ = main ()'\n"
fun main () = (TextIO.output (TextIO.stdErr, "ZOMG!"); OS.Process.exit OS.Process.success)
// count occurrences of the same combination of characters in an array of strings
// example:
// > console.log(count(['ab', 'ba']))
// [2]
const xs = [ 'aba', 'aab', 'ccc', 'ddc', 'dcd', 'baa', 'dds', 'sdd', 'dcd', 'xyz' ];
const count = xs => {
const map = xs.reduce((acc, x) => {
const key = Array.from(new Set(x)).sort().join('');
return {
@snahor
snahor / concurrency-8.go
Created May 2, 2017 18:17
A tour of Go
package main
import (
"fmt"
"sort"
"golang.org/x/tour/tree"
)
// Walk walks the tree t sending all values
{
do {
if (!this.isQuotePublished()) {
<div>
<Dialog ref="modalDeleteQuoteDraft" type="modal">
<DialogOverlay>
<DialogHeader>
<DialogTitle>{ t('QUOTE_DRAFT_DELETE') }</DialogTitle>
</DialogHeader>
<p style={ { padding: 20 } }>
def max_difference(xs):
max = min = xs[0]
d = -1
for x in xs[1:]:
if min > x:
min = max = x
continue
if x > max:
max = x
if max - min > d:
fun fizzbuzz' n =
case (n mod 5 = 0, n mod 3 = 0) of
(true, true) => "FizzBuzz"
| (true, false) => "Buzz"
| (false, true) => "Fizz"
| _ => Int.toString n
fun fizzbuzz n =
let
fun loop m =
@snahor
snahor / derp.hs
Last active October 18, 2016 05:23
F#'s pipe forward in Haskell
(|>) :: a -> (a -> b) -> b
x |> f = f x
[1..6] |> sum
inc = (+) 1
[1..5] |> map inc |> sum