This file contains hidden or 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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 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 |
This file contains hidden or 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
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; |
This file contains hidden or 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
;; 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))) |
This file contains hidden or 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
;; 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)) |
This file contains hidden or 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
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 | |
% |
This file contains hidden or 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
;; 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)))) |
This file contains hidden or 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
;; fronx's solution to A Half-Truth | |
;; https://4clojure.com/problem/83 | |
#(or (and (some false? %&) (some true? %&)) | |
false) |
This file contains hidden or 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
;; 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 +))] |
This file contains hidden or 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
;; 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 |
This file contains hidden or 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
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 |
NewerOlder