Skip to content

Instantly share code, notes, and snippets.

@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
@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;
;; 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'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
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 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's solution to A Half-Truth
;; https://4clojure.com/problem/83
#(or (and (some false? %&) (some true? %&))
false)
;; fronx's solution to Happy numbers
;; https://4clojure.com/problem/86
(fn [n]
(loop [seen #{} n n]
(let [v (->> n
str vec
(map #(- (int %) 48))
(map #(* % %))
(reduce +))]
@fronx
fronx / fronx-4clojure-solution73.clj
Created September 16, 2011 17:49 — forked from anonymous/fronx-4clojure-solution73.clj
fronx's solution to Analyze a Tic-Tac-Toe Board ;; https://4clojure.com/problem/73
;; fronx's solution to Analyze a Tic-Tac-Toe Board
;; https://4clojure.com/problem/73
(fn [m]
(first
(filter
(fn win? [player]
(->> (let [idx [0 1 2]]
(concat m ; rows
(map (fn [i] (map #(% i) m)) idx) ; columns
require 'spec_helper'
describe SharesController do
render_views
describe '#create' do
let(:share_params) { :facebook_id => 'abc', :address_id => 7 }
it "redirects to login" do
post :create, :share => share_params