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
import Html exposing (Html) | |
import Html.Attributes | |
import Html.Events | |
import Mouse | |
import Signal exposing (Signal, Address) | |
import StartApp | |
import Json.Decode exposing ((:=)) | |
import List |
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 List (..) | |
import Random (..) | |
import Text (asText) | |
shuffle : List a -> List a | |
shuffle lt = | |
let len = length lt | |
fgen = float 0 1 | |
lgen = list len fgen | |
rlist = fst <| generate lgen (initialSeed 31415) |
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 = |
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 Immutable from 'immutable'; | |
/* Selection List Data Structure */ | |
class SelectionList { | |
constructor(list) { | |
if (list.length > 0) { | |
this._previous = new Immutable.Stack(); | |
this._selected = list[0]; | |
this._next = new Immutable.Stack(list.splice(1)); |
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
/* | |
* type Definition = { | |
* kind: String, | |
* name: String, | |
* properties: [Property] | |
* } | |
* | |
* type Property = { | |
* key: String, | |
* value: [String] |