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
#lang racket | |
;; Notes on CNF form: | |
;; A CNF formula is a list of claues. These clauses are semantically "and-ed" together | |
;; Each clause is a list of "literals". Each literal is semantically "or-ed" together | |
;; Each literal is either a positive or negative atom | |
;; Each atom is either "true", "false", or a variable | |
;; An example satisfiable formula |
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
method Foo(x : int) returns (r : int) ensures r > x { | |
r := x + 1; | |
} | |
class SparseSet { | |
ghost var spec : set<nat> | |
var n : nat | |
var dense : array<nat> | |
var sparse : array<nat> |
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
#lang racket | |
(define N 1000) | |
(define (main) | |
(printf "N: ~a\n" N) | |
(define data (play-n-games N)) | |
(printf "Alice wins: ~a\n" (count alice? data)) | |
(printf "Bob wins: ~a\n" (count bob? data)) | |
(printf "Ties: ~a\n" (count tie? data))) |
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
#lang rosette/safe | |
;; take weights and threshold | |
;; returns a function that implements a perceptron neuron | |
(define (neuron weights threshold) | |
(λ inputs | |
(if ((foldl + 0 (map * weights inputs)) . > . threshold) | |
1 | |
0))) |
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
#lang racket | |
(require threading racket/trace) | |
(define FILE "/tmp/input") | |
(define lines | |
(with-input-from-file | |
FILE | |
(λ () | |
(port->lines (current-input-port))))) |
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
#lang racket | |
(require threading) | |
(define FILE "/tmp/input") | |
(struct grid (data length width) #:transparent) | |
(define/contract (point? x) | |
(-> any/c boolean?) | |
(match x |
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
#lang racket | |
(require threading) | |
(module+ rackunit) | |
(struct line (wires output) #:transparent) | |
(define (parse-list lst) | |
(map (compose list->set string->list string-trim) (string-split lst " "))) |
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
#lang racket | |
(require threading) | |
(define sample-pos | |
(~> | |
"16,1,2,0,4,2,7,1,2,14" | |
#; | |
(with-input-from-file | |
"/tmp/input" | |
(λ () (port->string (current-input-port)))) |
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
use std::fs::read_to_string; | |
const DAYS: usize = 256; | |
type Fish = Vec<u64>; | |
fn main() { | |
let mut fish = vec![0; 9]; | |
let mut scratch; | |
parse_input(&mut fish); |
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
#lang racket | |
(require threading) | |
(module+ test (require rackunit)) | |
(struct line (from to) #:transparent) | |
(struct posn (x y) #:transparent) | |
(define (parse-line l) | |
(match (string-split l "->") | |
[(list to from) | |
(line (parse-cord to) (parse-cord from))])) |
NewerOlder