Skip to content

Instantly share code, notes, and snippets.

@skybrian
skybrian / sudoku.dart
Last active December 20, 2015 20:38
A line-by-line translation of Peter Norvig's Sudoku solver into Dart.
// Solve Every Sudoku Puzzle in Dart
// A translation of: http://norvig.com/sudopy.shtml
// Translated by Brian Slesinsky
// See http://norvig.com/sudoku.html
// Throughout this program we have:
// r is a row, e.g. 'A'
// c is a column, e.g. '3'
// s is a square, e.g. 'A3'
@skybrian
skybrian / sudoku_output.txt
Last active December 20, 2015 21:59
Performance tests comparing sudoku.py with sudoku.dart
Python
------
$ python sudoku.py
All tests pass.
Solved 95 of 95 hard puzzles (avg 0.02 secs (47 Hz), max 0.10 secs).
Solved 11 of 11 hardest puzzles (avg 0.01 secs (130 Hz), max 0.01 secs).
Solved 99 of 99 random puzzles (avg 0.01 secs (155 Hz), max 0.02 secs).
Macintosh:~/dart/sudoku/bin skybrian
$ python sudoku.py
@skybrian
skybrian / sudoku2.dart
Created August 12, 2013 07:07
An optimized version of sudoku.dart that runs 8x faster.
// Solve Every Sudoku Puzzle in Dart, optimized version
// A translation of: http://norvig.com/sudopy.shtml
// Translated and optimized by Brian Slesinsky
// See http://norvig.com/sudoku.html
// Throughout this program we have:
// r is a row, e.g. 'A'
// c is a column, e.g. '3'
// s is a Square, e.g. 'A3'
import Dict
indexed: [a] -> Dict.Dict Int a
indexed list = Dict.fromList (zip [0..(length list)] list)
type Palette = Dict.Dict Int Color
makePalette: [Color] -> Palette
makePalette colors = indexed colors
import Dict
type Painting = {palette: [Color], grid: [[Int]]}
model: Painting
model = {
palette = [red, orange, yellow, green, blue, purple],
grid = [[0,1,2,3,4,5], [1,2,3,4,5,0], [2,3,4,5,0,1]] }
indexed: [a] -> Dict.Dict Int a
import Dict
import Graphics.Input (Input, input, clickable)
type Pixel = (Int)
type Palette = {length: Int, colors: Dict.Dict Pixel Color}
makePalette: [Color] -> Palette
makePalette list =
let indexed = zip [0..(length list) - 1] list
import Dict
import Graphics.Input (Input, input, hoverable)
import Mouse
import Window
type Pixel = (Int)
type Palette = {length: Int, colors: Dict.Dict Pixel Color}
makePalette: [Color] -> Palette
@skybrian
skybrian / grid.dart
Created August 1, 2015 00:52
test of angular 2 change detection
import 'dart:html';
import 'package:angular2/angular2.dart';
import 'package:angular2/src/reflection/reflection.dart' show reflector;
import 'package:angular2/src/reflection/reflection_capabilities.dart'
show ReflectionCapabilities;
void main() {
reflector.reflectionCapabilities = new ReflectionCapabilities();
bootstrap(Grid);
import Html
import Html.Events as Events
import Http
import Json.Decode as Json exposing ((:=))
import Signal
import Task
main = mysteryButton2
-- before
{
"[plaintext]": {
"editor.quickSuggestions": false,
"editor.wordWrap": "bounded"
},
// See: https://github.com/Microsoft/vscode/issues/34606
"editor.autoClosingBrackets": false,
"editor.stablePeek": true,
"files.autoSave": "onFocusChange",