17
votes
Accepted
Printing binary trees
First of all, in my opinion, both the algorithm is nice and interesting, and the code is really well-written, broken down into easily understandable functions!
Well done!
The only addition that I can ...
7
votes
Accepted
Generate a deck of cards in Clojure / Clojurescript
There are a few minor improvements you can make here that lead to a fairly elegant implementation.
First, using flatten is rarely a good idea, because rather than ...
5
votes
Haversine Formula in Clojure
Naming and interface
Please avoid mixing English (calculate-distance) with Portuguese (raio). The code should be in English; ...
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
Short Clojure digit extraction
I'd simplify as follows:
(defn get-digit [x k] (Character/digit (.codePointAt x k) 10))
codePointAt is a method of Java's <...
4
votes
Accepted
Filtering a data structure using regex predicates
First up, notice that you're creating 3 leted names by using exactly the same expression but replacing one key lookup function. This is a prime candidate for ...
4
votes
Accepted
Musical graph algorithm, with an inlined lookup helper function
... I would like to understand how to properly get the most out of low
level operations. ... Is this the correct way? ...
Up to a point.
There's little or nothing wrong with your ...
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
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
Get RSS feeds and store them into database
When using defn, the docstring goes before the arguments list, not after.
In order to prevent environment coupling, functions that use a ...
3
votes
Accepted
Lazy sub sequence
One way to improve:
(defn lsubseq
[coll left-index right-index]
(take (- right-index left-index) (drop left-index coll)))
There is also a built-in function - ...
3
votes
Accepted
Shuffling many collections by folding over a numeric range
If you want to transform a value v by applying a function f n times, it may be clearer to ...
3
votes
Accepted
Multiple files data processing in Clojure
Don't forget about for
Consider using for instead of map in places where you use an ...
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
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
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
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 ...
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
2048 game implementation in Clojure
core.clj
(def x 1)
(def y 1)
Use more descriptive names. These seem to be used as the origin for rendering the game, so ...
2
votes
Accepted
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
clojure × 308beginner × 44
functional-programming × 38
programming-challenge × 32
performance × 26
lisp × 17
algorithm × 15
strings × 10
recursion × 9
clojurescript × 9
comparative-review × 7
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