This file contains 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
macro eval_with_params(expr, params...) | |
# Put the params before the expression | |
expr_with_params = [collect(params)..., expr] | |
# Wrap the expressions in :block Expressions | |
Expr(:block, expr_with_params...) | |
end | |
@eval_with_params( | |
x + y, |
This file contains 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
import Html exposing (Html, div, text, button) | |
import Html.App exposing (beginnerProgram) | |
import Html.Events exposing (onClick) | |
import Random exposing (Seed, initialSeed, step, float, bool) | |
-- Start with initial probability | |
-- For every miss : | |
-- p = p * 0.9 |
This file contains 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
-- Goal: In point-free style | |
mapReduce : (a -> b) -> (List b -> c) -> List a -> c | |
-- Simple | |
mapReduce mapper reducer list | |
= reducer (List.map mapper list) | |
-- Remove the last argument via composition | |
mapReduce mapper reducer | |
= reducer << List.map mapper |
This file contains 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
#!usr/bin/python | |
from itertools import permutations | |
def n_queens(n): | |
cols = range(n) | |
for vec in permutations(cols): | |
if n == len(set(vec[i] + i for i in cols)) and n == len(set(vec[i] - i for i in cols)): | |
print("\n".join('.' * i + 'Q' + '.' * (n - i - 1) for i in vec) + "\n===\n") |
This file contains 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
// makeRunner : (renderer : ReactComponent -> ()) | |
// -> (update : s -> a -> s, render : s -> Dispatcher a -> ReactComponent, observable : Observable a) | |
// -> () | |
export const makeRunner = (renderer) => (update, render, observable) => { | |
const store = createStore(update); | |
const renderApp = () => renderer(render(store.getState(), store.dispatch)); | |
renderApp(); |
This file contains 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
import React, { Component } from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { createStore } from 'redux'; | |
import Rx from 'rx'; | |
// run : (update: s -> a -> s, render: s -> Dispatcher a -> Html, observable: Observable a, root: String) | |
export const run = (update, render, observable, root='root') => { | |
const store = createStore(update); | |
const renderApp = () => { |
This file contains 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
import Dict exposing (Dict) | |
import Html exposing (Html, div, text, input, ul, li) | |
import Html.App as Html | |
import Html.Events exposing (..) | |
import Task exposing (Task) | |
import String | |
--------------------------- | |
main = |
This file contains 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
powerSet : String -> List String | |
powerSet = | |
String.words | |
>> List.foldr (\x acc -> acc ++ List.map ((::) x) acc) [[]] | |
>> List.map (String.join " ") | |
>> List.filter ((/=) "") |
This file contains 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
import Signal exposing (Address) | |
import Html exposing (Html, button, text, div) | |
import Html.Events exposing (onClick) | |
import StartApp.Simple as StartApp exposing (start) | |
type alias State = | |
{ counter : Int } | |
This file contains 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
import Random exposing (Generator, Seed) | |
import Signal exposing (Signal) | |
import Graphics.Element exposing (Element, show, flow, down) | |
import Time exposing (Time) | |
import String | |
import List | |
die : Generator Int | |
die = |
NewerOlder