Clojure is a Lisp dialect for the Java Virtual Machine. Its main features include a software transactional memory system for coherent updates to data structures, transparent access to Java libraries, a dynamic REPL development environment, runtime polymorphism, and built-in concurrent programming ...
5
votes
3answers
113 views
How to write this small program better?
This is just a fun little exercise I had to do for a homework once (in Java rather than Clojure though). Basically, the goal is to find the number of different coin stacks you can build with the coins ...
1
vote
0answers
47 views
Clojure - Combination Circuit Calculator
I wrote a combination circuit calculator in Clojure. It is my first project in Clojure, so I know it has horrible style/flow. I would like any comments, especially suggestions. May include:
Program ...
4
votes
3answers
111 views
Critique my Clojure “Game of Life” code
I'm a Clojure n00b (but am experienced with other languages) and am learning the language as I find time - enjoying it so far, though the strange dreams and accidental use of parenthesis elsewhere ...
1
vote
1answer
43 views
Idiomatic text munging in Clojure
In getting accustomed to Clojure syntax, I wrote the following stutter function:
(defn doublelist [coll]
(flatten (map (fn [x] [x x]) coll)))
(defn stutter [s]
(clojure.string/join
" " ...
2
votes
1answer
71 views
Find largest two numbers from list using clojure
I'm trying to write a function that finds the largest two numbers from a list of positive integers in Clojure.
I've toyed around with Scheme in the past, but I'm very new to Clojure. This is what I ...
2
votes
2answers
56 views
More concise and/or idiomatic max subarray in Clojure?
I've implemented the following two versions of the classic "Max Sub-Array" problem in Clojure, using the Kadane algorithm.
First with loop / recur
(defn max-sub-array [A]
(loop [x (first A)
...
5
votes
1answer
105 views
Depth-first search algorithm in clojure
Context
As an exercise for myself (I'm learning clojure). I wanted to implement the Depth-first search algorithm.
How I did it
Using recursion
(def graph
{:s {:a 3 :d 4}
:a {:s 3 :d 5 :b 4}
...
3
votes
1answer
110 views
Connect Four: Bitboard checking algorithm
I'm rather new to Clojure and so I decided to program a Connect Four for fun and learning.
The code below is a Clojure implementation of this bitboard algorithm.
The whole code can be found here: ...
0
votes
1answer
57 views
Calculating a factorial with parallel sub-computations using pmap, pvalues and pcalls
In an attempt to learn more about Clojure's parallel computation functions, I devised the following task: calculate a factorial in parallel using pmap, pcalls and pvalues.
The idea is to split the ...
3
votes
0answers
48 views
Toggle chart series in clojurescript
I'm toggling on/off series in chart and was wondering if I was doing anything crazy.
Is the atom really a good idea here?
;; ================ Graph data ================
(def serie1 {:label "Bar" ...
3
votes
1answer
110 views
Implementation of Python's re.split in Clojure (with capturing parentheses)
If you use capturing parenthesis in the regular expression pattern in Python's re.split() function, it will include the matching groups in the result (Python's documentation).
I need this in my ...
6
votes
2answers
184 views
Expanding a map, style guidance
I have a map that I want to 'expand' into an infinite sequence in the following manner:
{0 'zero 3 'three 10 'ten}
=>
('zero 'zero 'zero 'three 'three 'three 'three 'three 'three 'three 'ten 'ten ...
4
votes
2answers
463 views
higher order fizzbuzz! clojure
make it better! requirement: support arbitrary number of factors, not just 3 & 5.
(ns fizzbuzz.core
(:use [clojure.contrib.string :only (join)]))
(def targets (sorted-map 3 "fizz" 5 "buzz" 7 ...
3
votes
3answers
424 views
Find the common characters between two strings without using set operations
Below are two implementations of the problem "find the characters in common between two strings" - in Clojure without using collections / set operations.
Are these approaches sufficiently idiomatic ...
7
votes
1answer
168 views
Powerset in Clojure
I think I have correctly implemented Powerset in Clojure.
(use '(clojure set))
(defn powerset [input result]
(if (nil? (first input))
(concat result #{})
(set (reduce concat
...