Questions tagged [clojure]

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 constructs.

Filter by
Sorted by
Tagged with
63
votes
1answer
2k views

Printing binary trees

After writing this answer, I was inspired to try to design a more elegant solution to the problem of printing binary trees. And what better tool with which to seek elegance than Clojure? Overall ...
47
votes
1answer
2k views

Connect Four AI (Minimax) in Clojure

I wrote a Connect Four game including a AI in Clojure and since I'm rather new to Clojure, some review would be highly appreciated. It can include everything, coding style, simplifications, etc. But ...
23
votes
3answers
2k views

Project Euler Problem 2 in Clojure

I am in the process of learning Clojure. I am fairly new to functional programming and would like to know if my code smells or if there are any performance implications with my approach. ...
15
votes
1answer
424 views

Clojure Minesweeper from scratch

In order to exercise and learn Clojure, I decided to write a simple Minesweeper game from scratch. I'd consider myself as a Clojure novice and would be thankful if somebody could do a review or give ...
14
votes
0answers
171 views

Tracking the bounding box of a map

Context I have a bunch of data points that look roughly like this: ...
14
votes
0answers
395 views

Shepard Tone stream generation in Clojure

This is my work to generate an infinite Shepard Tone. It is written in Clojure and works by generating repeating streams of incrementing frequencies, converting those to values on a sine wave and then ...
12
votes
3answers
507 views

Reservoir Sampling in Clojure

I am learning clojure and decided to start out by trying to write a solution to a fairly simple algorithm, reservoir sampling. As I stated, I am learning clojure specifically and problem solving in a ...
12
votes
1answer
2k views

Clojure Neural Network

After reading this article about Neural Networks I was inspired to write my own implementation that allows for more than one hidden layer. I am interested in how to make this code more idiomatic - ...
11
votes
2answers
421 views

Number factorization in clojure

I'm just a Clojure noob (started learning yesterday). Here is my helloworld program. It factorizes number into primes. Do you have any comments? How could I make this code cleaner and shorter? Maybe I ...
11
votes
1answer
843 views

Is this the Clojure way to web-scrape a book cover image?

Is there a way to write this better or more Clojure way? Especially the last part with with-open and the let. Should I put the <...
11
votes
1answer
151 views

A port of the 1971 StarTrek game to Clojure

I ported the Star Trek 1971 game to Clojure to help me learn more about the language and functional programming in general. You can see the entire game on Github. The game plays (you can start it with ...
10
votes
1answer
901 views

Clojure tokenizer

Please review the following Clojure tokenizer. The goal is to study Clojure, so sometimes I re-implement functions (it will be nice to see standard functions for this). Beyond of this, code seems ...
10
votes
1answer
276 views

Project Euler #2 - Sum of even Fibonacci numbers to 4,000,000

This particular problem has already been posted here before, but the community is ok with me to post it again, so I can have feedback on my own implementation. I tried to keep things simple, with ...
10
votes
1answer
933 views

Idiomatic clojure code in a markdown parser

Some time ago I created a markdown parser in clojure and I would like to get some feedback, since I'm a clojure noob in the first place (is the code understandable?/is it idiomatic?/can some things be ...
9
votes
1answer
3k views

Clojure - substring? function

Trying to write a substring function in Clojure. I am sure there is a more idiomatic way. Can anyone enlighten me? Otherwise, here is my version. Thoughts? ...
9
votes
0answers
373 views

Idiomatic way to implement `tail -f` in clojure

Disclaimer: This is just an educational task to learn how to program in clojure and switch brain to immutable state-way of developing (the provided snipped has some unused variables which I didn't ...
8
votes
2answers
310 views

Package manager in Clojure

I wrote a package manager in clojure that does 5 things: depend a b //creates a and b (if they don't exist) and adds dependency on a install a //installs a and its dependencies list //prints out the ...
8
votes
2answers
1k views

Using Viterbi algorithm to analyze sentences

I've probably done some pretty horrendous things here, but I'm throwing it out for people to give me some feedback that I can start using to immediately improve my Clojure coding style. Additional ...
8
votes
2answers
1k views

Powerset in Clojure

I think I have correctly implemented Powerset in Clojure. ...
8
votes
1answer
342 views

Bayesian approximation method for online ranking

I've implementing the this algorithm in Java, Scala, and Clojure to show my teammates. I know the code works as expected. What I'm looking for is tips on good Clojure style. ...
8
votes
1answer
529 views

“Curious Numbers” (HackerRank PE 34)

I was inspired by a certain recent question to try my hand at this challenge: Project Euler #34: Digit factorials \$19!\$ is a curious number, as \$1!+9!=1+362880=362881\$ is divisible by \$19\$...
8
votes
1answer
288 views

Expanding a map into an infinite sequence

I have a map that I want to 'expand' into an infinite sequence in the following manner: ...
7
votes
2answers
336 views

Water pouring challenge

I'm trying to write code to solve water pouring problem in Clojure. The following code is strongly influenced by Martin Odersky's solution lectured in his coursera course, Functional Programming ...
7
votes
3answers
2k views

Partitioning strings into substrings of fixed length

I've got a Clojure function here that's meant to parse a string of form: "DDXXXYYY" where DD is meant to be discarded, and XXX and YYY are string representations of integers. ...
7
votes
1answer
666 views

Excessive use of let a problem in Clojure?

I have this set of functions - it works, but I'm concerned about the use of lets. ...
7
votes
1answer
2k 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 ...
7
votes
1answer
153 views

Avoid incoming meteors

I'm visiting a functional programming course at my university which has a small project for examination. The language we are using is clojure and the contents of the lecture have mostly been about it'...
7
votes
1answer
498 views

Unix sort in Clojure

I am implementing Unix sort in Clojure. This is my first program, and I would like some feedback regarding any non-idiomatic, harmful code and any other best practices I can include in future versions....
7
votes
1answer
178 views

2048 game implementation in Clojure

This is my first Clojure program. If you want to run it locally please check out https://github.com/achikin/game2048-clj core.clj ...
7
votes
1answer
733 views

Clojure TicTacToe (logic, no GUI)

I whipped this up last night and was wondering if anyone had any thoughts/comments on it; for example, on: Code organisation Coding style Other improvements Semantic errors ...
7
votes
2answers
251 views

Reading lines from a file in random order

I originally wrote this as an answer to a question on Stack Overflow, but it turned out so nicely that I decided to post it here to see if I can make it even better. ...
7
votes
1answer
325 views

Dining Philosophers Problem in Clojure

I have implemented the Dining Philosophers Problem in Clojure with refs, trying to emphasize readability. Please point out if parts of it are inefficient, not idiomatic, or improvable in any way. Full ...
6
votes
3answers
264 views

Number of Chocolates to Gluttonize in Clojure

I’ve been dabbling in Clojure by solving programming puzzles. This particular puzzle is from HackerRank, with the objective of figuring out how much chocolate one could eat given three parameters: ...
6
votes
3answers
363 views

Finding the sum of the digits appearing in the leaves via in-order traversal

The following text is an in-order traversal of a binary tree with 1023 nodes. What is the sum of the digits appearing in the leaves? How can I improve this Clojure code? It looks strange to me to ...
6
votes
4answers
414 views

Counting ways to form an amount using coins

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 ...
6
votes
1answer
92 views

PE4: Largest Palindrome Product (Clojure)

I solved Project Euler 4 using Clojure Lisp. A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest ...
6
votes
1answer
423 views

Starting a Clojure Chess Engine

In my journey to learn Clojure I recently decided that I would like to write a chess engine, which is kind of funny because I don't really know chess either. ;-) My goals are to learn Clojure and ...
6
votes
2answers
447 views

Matrix Diagonal Difference

Problem Given a square matrix of size N×N, calculate the absolute difference between the sums of its diagonals. Input Format The first line contains a single ...
6
votes
1answer
165 views

Generating XKCD passwords

Obviously, everyone should use a password manager to generate and store long unique random strings of characters for the vast majority of their passwords. However, one still needs to memorize a master ...
6
votes
1answer
100 views

Brainfuck interpreter in Clojure

I'm currently learning Clojure to try to get a good understanding of functionnal programming, so I wrote this brainfuck interpreter that takes a filename on the command line. I tried to make it as ...
6
votes
1answer
126 views

Database Migrations

I'm starting to learn Clojure, and would like feedback on some code I wrote to manage database migrations. Any recommendations to make it more robust, efficient, idiomatic, elegant, etc... are welcome!...
6
votes
1answer
87 views

Clojure “Game of Life”

I'm a Clojure beginner and I implemented Game of life to learn how I should code things in Clojure. ...
6
votes
1answer
187 views

Printing a nested data structure in Clojure

I wrote the following code which transforms a nested data structure ...
6
votes
1answer
960 views

Clojure core.async web crawler

I'm currently a beginner with clojure and I thought I'd try building a web crawler with core.async. What I have works, but I am looking for feedback on the following points: How can I avoid using ...
6
votes
0answers
386 views

Translating CFRM algorithm from Java to Clojure and improving performance

Counterfactual Regret Minimization is an algorithm that can be used to find the Nash Equilibrium for games of incomplete information. I have tried to adapt the exercise from here to Clojure. You can ...
5
votes
2answers
269 views

Document term matrix in Clojure

This is my very first foray into Clojure (I'm normally a Python-pushing data-type). I'm trying to create a simple term-document matrix as a vector of vectors, out of a vector of strings. For those ...
5
votes
3answers
632 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 (e....
5
votes
3answers
132 views

Adding augmented maps to a vector based on regex text grabbing

This is my latest brain child for clojure, could it be done with less code, cleaner, or in a more re applicable way? I am at a pretty early stage in my clojure learning so an in depth explanation of ...
5
votes
3answers
142 views

Haversine Formula in Clojure

I implemented the Haversine formula to calculate the distance between two (latitude, longitude) coordinates. I was wondering if it looks natural to Clojure programmers. What could be improved? <...
5
votes
1answer
156 views

A text-templating system similar to PHP…but with Clojure

I wrote a simple text-templating/processing system which resembles PHP, except that it works with Clojure. The main goal was to provide an easy way to use Clojure PHP-style for small files. This is a ...