Skip to content

Instantly share code, notes, and snippets.

View saludes's full-sized avatar

Jordi Saludes saludes

  • Universitat Politècnica de Catalunya
View GitHub Profile
@saludes
saludes / rounding_division.rkt
Last active November 27, 2019 12:40
Computing the probability that the rounding of y/x be an even number, where x, y are uniformly distributed on [0,1].
#lang racket
(require plot)
(define (ct p)
(match-define (vector x y) p)
(/ y x))
(define (f g)
(λ (p)
(zero? (modulo (inexact->exact (g (ct p))) 2))))
@saludes
saludes / collatz.rkt
Last active July 23, 2018 14:04
Plots related to the Collatz function
#lang racket
;; http://www2.bakersfieldcollege.edu/resperic/ca/cellular_automata_dynamics.pdf
(require graph racket/system 2htdp/image)
(struct memf [f h domain])
(define (new-memf f [dom #f])
(memf f (make-hash) dom))
@saludes
saludes / distribute.rkt
Created July 26, 2017 09:59
An example of how to distribute a predicate on a NP conjunction.
#lang racket
(require gf/pgf gf/expr)
(define app
(get-concrete "exp/App.pgf" "AppEng"))
(define ps
(map unpack
(parse/sort app "A , B and C are equal" 'Cl)))
(define (distribute p exp)
@saludes
saludes / non_transitive_dice.rkt
Last active June 13, 2017 09:53
Compute winning probabilities and dominance graph for sets of dice
#lang racket
(struct die [name faces])
(define R (die "red" '(4 4 9 4 4 4)))
(define B (die "blue" '(7 7 7 2 2 2)))
(define O (die "olive" '(5 5 0 5 5 5)))
(define Y (die "yellow" '(8 8 3 3 3 3)))
(define M (die "magenta" '(1 1 6 6 6 6)))
@saludes
saludes / competencia.py
Created February 2, 2016 15:07
Ompla la columna _competències_ a partir de la nota habitual
import sys, locale
locale.setlocale(locale.LC_ALL, 'es_ES.UTF-8')
if __name__ == '__main__':
inPath, outPath = sys.argv[1:3]
with open(outPath, 'w') as outf:
with open(sys.argv[1]) as inf:
for row in inf.readlines():
studentId,sgrade,extra = row.split(' ')
assert extra == '\n'
@saludes
saludes / Dockerfile
Last active October 6, 2015 16:53
Assuming you have `GF` sources downloaded from `darcs` repository, install `GF` with runtime extension. Name it saludes/gf-runtime.
FROM saludes/docker-gf
WORKDIR /GF
RUN darcs pull -a
RUN cabal install
CMD gf
#lang racket
(require rackunit racket/generator)
(define (poly->pairs p)
(let ([cs (poly-coefs p)])
(foldl
(λ (k c xs)
(if (zero? c)
xs
(cons (cons c k) xs)))
(ns my-gf-java.core)
(def WS_DOC_ROOT
(let [pwd (System/getenv "PWD")]
(str pwd "/resources/")))
(def WS_PORT 41297)
(def WS_URL_LOCALHOST (str "http://localhost:" WS_PORT))
(let [server (str " -server=" WS_PORT)