5
votes
Accepted
Implementing parser combinators in a functional manner
I'm going to admit right off the bat here that I've never written a parser using combinator functions before. I have quite a bit of experience with Clojure though, so I'll be primarily focusing on ...
4
votes
Accepted
Linked list implementation in Clojure
What do you think about the chosen data structure (nested dictionaries)? Would there be a way to implement this in Clojure, in a more efficient way?
Conceptually it works. I wouldn't use plain maps ...
4
votes
Accepted
Sorting texts by similarity in Clojure
First, the most serious problem with your code:
Never, ever, ever use def inside of defn, unless you really know what you're ...
4
votes
Accepted
Avoid incoming meteors
For code written by students new to the language, this is quite good. You haven't made any of the major mistakes that most newbies to the language make, like abuse of ...
4
votes
Accepted
A* in Clojure - trickier than I expected
I'm not going to be able to do a very thorough review. The code doesn't have anything outright wrong with it, and I'll admit, I've never been able to implement a decent A* implementation. It's just ...
4
votes
Accepted
Count Words in Quotes Fetched from Website
For quote-word-count, there's a few things to note.
I think this is a good use of ->>. Personally, I would have started ...
4
votes
Clojure Prime Numbers from 1 to 1000
Note: It has been a long time since I actively played with Clojure, so I will mostly refrain from writing and/or reviewing any actual code in my answer and will only provide a high-level review.
...
3
votes
Accepted
Kids bank account in Clojure
This isn't bad code. The worst thing I see is a lot of your code is operating via side effects.
You're either directly reading from file with take-csv, or carrying ...
3
votes
Code Chef RAINBOW Palindrome
(defn palindrome? [items]
"Efficient algorithm: loops through only (array-size/2)"
...
(not= (nth items i)
(nth items j))
...
3
votes
Program follows sequence of instructions to arrive at destination
Take a look at Bruce Hauman's answer to the question: https://github.com/bhauman/advent-of-clojure-2016/blob/master/src/advent_of_clojure_2016/day1.clj
One thing that was an eye-opener to me is how ...
3
votes
Accepted
Project Euler #49: Find 12-digit number concatenating a three terms sequence
There's a few things that can be improved here:
First, I'm not sure if you neglected it here or if you actually aren't using it, but every file should start with a call to ...
3
votes
Accepted
Program finds the first almost matching string in a list - Advent Of Code 2018 Day 2 Part 2
There isn't a whole lot of code here, so I'll just point out what I see top-to-bottom. I'll note though that I'm exceedingly tired and don't fully understand what the problem you're solving is, so I'...
3
votes
Accepted
Extract indices of visible nodes in a tree where only some nodes are expanded
You are right to want to avoid creating the nested structure to begin with. I imagine you read my answer in the question you linked (the second one). As there, here the solution is to use ...
3
votes
Langton's ant in Clojurescript
I don't have any performance related suggestions unfortunately. I do have a couple cleanup suggestions though.
The bounds checking function can be cleaned up a bit by making use of "comparison ...
3
votes
Check balanced brackets
I'd never thought of using reduce for this. Neat! However, you can simplify mk-balanced? a little.
...
3
votes
Accepted
Clojure depth first search maze problem from Classic CS Problems in Python Book
Initial comments for only the dfs function:
Variable names
start makes sense for the initial point.
...
3
votes
Accepted
Prime factors kata solution in Clojure
There's a few notable things here:
You're prepending to a list, then reversing the result at the end. It would be better to just start with a vector ([]). ...
3
votes
A Clojure program to classify files based on their filename
fn, defn and let have implicit do, so you can remove it ...
2
votes
Accepted
Depth-first Search Non-Reursive Implementation in Clojure
From the top ...
The label function is a synonym for cons, as is build-stack for
...
2
votes
Accepted
One-Dimensional Cellular Automata
You invent special values for the out-of-bounds index (out-of-bounds-cell) and its value (out-of-bounds-filler): ...
2
votes
Accepted
Rock-Paper-Scissors game in Clojure
This is fairly good code. I don't really have much bad to say about it. Most of my suggestions will be stylistic, or based on little things I've learned that have helped me.
First though:
I was ...
2
votes
Accepted
Predicate testing for equality that returns the common element
You don't need the single argument case. You can abbreviate to
...
2
votes
Predicate testing for equality that returns the common element
Soon after I posted this, I went for a walk and realized that this is the perfect opportunity to use reduce. I'm kind of embarrassed that I didn't see it originally,...
2
votes
Accepted
Clojure "Game of Life"
Your code actually isn't terrible, but there are a few places where it can be improved.
First, the ref. It's entirely unnecessary in this case. What I'd change to ...
2
votes
Accepted
Program follows sequence of instructions to arrive at destination
I see a few things that can be improved on. I'll be commenting more on idiomatic Clojure, rather than the algorithm itself.
(Vector. 0 -1)
Using Java interop ...
2
votes
Accepted
Pascal's Triangle - Remove hack
There's a simpler way.
To get the next line
take two copies of the line,
extend them respectively with 0 at the start and with ...
2
votes
Accepted
Finding the comic ID of the last XKCD comic published
I'm not sure it's much shorter than what you wrote, but finding stuff in any tree-like data structure is what I created the tupelo.forest library for.
Here is a solution for your problem:
...
2
votes
Accepted
Functional Sieve of Eratosthenes in Clojure
Is there a way to avoid the cond dispatch in naïve-prime??
You could do naive-prime? this ...
2
votes
Accepted
Solving Knight's Travails Problem without using vector for position
I'll be commenting just on the code itself, not on improvements to the algorithm. I'll also be removing your docs for brevity here.
First, I see a ton of repetitious code here. ...
2
votes
Accepted
Mutative Heap's algorithm (permutations generator) in Clojure
I'd also, if possible, like to see a fully FP implementation of this,
but I'd wager that that would be quite difficult.
Here is a functional implementation of Heap's algorithm in Clojure, based on ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
clojure × 309beginner × 44
functional-programming × 38
programming-challenge × 32
performance × 26
lisp × 17
algorithm × 15
strings × 10
recursion × 9
clojurescript × 9
comparative-review × 8
primes × 7
game × 6
parsing × 6
unit-testing × 6
matrix × 5
web-scraping × 5
formatting × 5
combinatorics × 5
game-of-life × 5
sorting × 4
tree × 4
tic-tac-toe × 4
asynchronous × 4
mergesort × 4