Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<!-- saved from url=(0018)http://tif.ca/eat/ -->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Eat, drink, be nerdy</title>
<meta name="description" content="Dinner and meet-up for lovers of coding &amp;&amp; food: Eat, drink, be nerdy.">
<meta name="rating" content="general">
<meta name="robots" content="all, index, follow">
<link rel="shortcut icon" type="image/ico" href="http://tif.ca/favicon.ico">
<style type="text/css">article, aside, dialog, figure, footer, header, hgroup, menu, nav, section{ display: block; }</style>
;; fronx's solution to Transitive Closure
;; https://4clojure.com/problem/84
(fn [rel]
(let [trans (set
(for [[a b] rel [c d] rel]
[a (if (= b c) d b)]))
done (= trans rel)]
(if done trans (recur trans))))
@fronx
fronx / transclose.m
Created October 25, 2011 22:05 — forked from moink/transclose.m
Transitive closure solution in Matlab
function A=transclose(A)
%returns the transitive closure matrix of the input matrix
%input: A(i,j) is 1 if the binary relation if (element i) R (element j) using the
%notation in the introduction of http://en.wikipedia.org/wiki/Transitive_closure
%
%Usage example: Implements the first example problem on https://www.4clojure.com/problem/84
%
%divideskey=[2 3 4 8 9 27];
%%I don't actually use that variable, but it keeps track of what my matrix means
%
;; fronx's solution to Power Set
;; https://4clojure.com/problem/85
(fn [s]
(let [bit-filter (fn [items mask]
(set
(keep-indexed
(fn [idx item]
(if (bit-test mask idx)
item))
;; fronx's solution to Love Triangle
;; https://4clojure.com/problem/127
(fn [field]
(let [
bit-max (fn [int]
(loop [n 1 i 0]
(if (>= int n)
(recur (* 2 n) (inc i))
i)))
@fronx
fronx / gist:1322338
Created October 28, 2011 14:02 — forked from theophani/gist:1322203
best is also the best of the best
var max = function (a, b) {
return (a > b ? a : b);
};
var min = function (a, b) {
return (a > b ? b : a);
};
var best = function (fun, array) {
if (!array.reduce) return array;
def rand5
rand(5) + 1
end
# n <= 25
def rand_n(n)
if (x = (((rand5 - 1) * 5) + rand5)) <= (25 - 25 % n)
(x % n) + 1
else
rand_n(n)
tracks = {
hihats: [0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0],
snare: [0,1,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,1],
kick: [1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,1,1,0,0,1,0,0]
};
samples = {
hihats: sounds.woody10,
snare: sounds.woody5,
kick: sounds.woody1
@fronx
fronx / ants.clj
Created November 9, 2011 17:25 — forked from michiakig/ants.clj
Clojure ant sim from Rich Hickey
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Ant sim ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
; which can be found in the file CPL.TXT at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
;dimensions of square world
class Array
def mapfn(&proc)
map do |item|
lambda do |*args|
proc.call(*([item] + args))
end
end
end
end