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 ...
4
votes
1answer
14 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 ...
2
votes
0answers
26 views
Escape the Trolls, or just walking through a maze
Clojure beginner, looking to improve this code I submitted for Escape the Trolls, a Weekly Programming challenge over in reddit. No trolls yet, just walking through a maze for now.
...
1
vote
0answers
12 views
Round-tripping from LinkedHashMaps to Clojure collections
I'm trying to implement round-tripping from LinkedHashMaps to Clojure collections. The implementation below works for smaller collections, but larger collections raise ...
0
votes
2answers
33 views
Intersection of two lists in clojure
context: this is somewhat related to project euler problem 5, which is:
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
I apply prime number ...
1
vote
1answer
38 views
Generate all permutations in Clojure
Given a set, generate all permutations:
(permutations #{1 4 5}) => ((5 4 1) (4 5 1) (5 1 4) (1 5 4) (4 1 5) (1 4 5))
Here's what I cobbled together:
...
3
votes
0answers
41 views
Functional Merge Sort
I just finished this Merge Sort in Clojure, structured according to ex. 22-26 of this workshop.
The main question I have can be answered without spending time understanding the code: ...
4
votes
2answers
90 views
Clojure performance for solving Project Euler 72 (counting proper reduced fractions)
This is a solution of Project Euler 72 in Java. How may proper reduced fractions \$\dfrac{n}{d}\$ are there, where \$n < d \le 10^6\$?
...
3
votes
0answers
24 views
The Miller-Rabin Primality Test in Clojure
I am new to clojure and I wanted to test out my skills by taking an existing implementation written in Python and writing it in Clojure.
Concerns
My main concerns are where I use ...
1
vote
1answer
23 views
Eight queens puzzle
Problem
In the famous eight queens puzzle, one must place eight queens on a chessboard without letting any queen threaten any other queen. There are 92 (or 12, depending on how you count) solutions ...
2
votes
1answer
62 views
Adding/removing map values: unsymmetric implementation
I am learning Clojure by implementing a simplistic resource reservation system. At its core are the two functions for placing/canceling reservations for a given resource:
...
3
votes
1answer
88 views
Print matrix in spiral order
I have a task formulated like this
Please print a matrix in spiral order, clockwise from outer rings to inner rings.
I decided to implement it in Clojure.
...
1
vote
1answer
45 views
Wrapping a character code for a Caesar Cipher
I'm writing a Caesar Cipher. To deal with characters being shifted to outside of the "normal" printable ASCII range ([32 126]), I'm having them "wrapped" to the max/...
1
vote
1answer
68 views
Exercism: clean and format a phone number in Clojure
Problem statement
Phone Number
Write a program that cleans up user-entered phone numbers so that they can be sent SMS messages.
The rules are as follows:
If the phone number is ...
1
vote
2answers
71 views
Formatting a date in ClojureScript
I want to convert strings with the iso date format (2015-08-02) to the default format of our app (2 Aug 2015) in ClojureScript. ...
0
votes
1answer
33 views
Dueling beings on a grid
I'm remaking an old program of mine in Clojure. It involves "Beings" (generic entities capable of attacking and breeding) let loose in a confined space.
I've noticed a pattern of taking a record, ...
4
votes
1answer
67 views
Building blocks of Life
I'm learning Clojure, and decided to write a Conway's Game of Life clone as my starting project. I ended up dicking around for a bit before diving in, and came up with a few functions that I'd like ...
2
votes
1answer
55 views
Spiral a matrix of size NxN filled with integers from 1 up to and including n^2
I have written a solution in Clojure for the following question:
When starting from the number 1 and adding three numbers on each row
a 3x3 matrix is formed as follows:
...
2
votes
1answer
65 views
Clojure counter
I'm learning clojure ref types and was trying to make a robust counter generating function. Is there any error or improvement on the code? is there a simpler way?
(I want the function to be thread-...
3
votes
0answers
130 views
Filling a Boot with CIDER
I'm trying to put together a workflow for building Clojure applications with Boot in CIDER. To test this workflow, I've written a small example application using Seesaw. My project structure looks ...
5
votes
1answer
67 views
Selecting HTML nodes
I'm new to Clojure, and I'm writing some code that processes HTML. I'm parsing the HTML using clj-tagsoup and then trying to pull out the relevant bits with this function:
...
4
votes
2answers
68 views
Number of ways to make change for an amount
Task
Write a program that, given the amount to make change for and a list of coins prints out how many different ways you can make change from the coins to STDOUT.
My approach
The number to make ...
6
votes
1answer
58 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 ...
5
votes
1answer
116 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 ...
3
votes
1answer
56 views
Clojure reverse multiple times
I have a piece of Clojure code that reverses a string recursively.
It is working but too slow (because I got the problem from Codewars and I cannot validate it ...
3
votes
1answer
45 views
Run tasks in parallel using limited number of threads
To learn about concurrency in Clojure, I wrote a function that accomplishes the following:
Takes a (possibly lazy or infinite) sequence of functions representing tasks to be run asynchronously
Runs ...
8
votes
1answer
121 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 \$...
5
votes
2answers
102 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 ...
10
votes
0answers
103 views
Tracking the bounding box of a map
Context
I have a bunch of data points that look roughly like this:
...
5
votes
3answers
112 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 ...
2
votes
1answer
62 views
Integer square root
This essentially performs the same function as exact-integer-sqrt in math.numeric-tower.
...
20
votes
0answers
362 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 ...
0
votes
0answers
49 views
Performance Optimized Project Euler Problem 14 in Clojure
Here is the problem:
The following iterative sequence is defined for the set of positive
integers:
n → n/2 (n is even)
n → 3n + 1 (n is odd)
Using the rule above and starting ...
0
votes
1answer
23 views
Read Twitter direct messages and check messages for links
I'm learning Clojure and I'm doing a little thing that reads direct messages from Twitter using twitter-api wrapper. The code doing that is below.
...
2
votes
1answer
50 views
Reversing all nested sequences
I'm writing a function that returns all (nested) sequences reversed:
...
2
votes
0answers
80 views
Project Euler #14 in Clojure (finding long Collatz sequence chain)
I'm working on a Clojure implementation for Project Euler #14, which asks for the initial element, under 106, that produces the longest collatz-sequence chain. I'm trying to make use of every ...
1
vote
0answers
45 views
Understanding lazy sequence in Clojure
In order to understand how the lazy sequences work in Clojure, I decided to implement the quick-sort example from the "The Joy of Clojure, Second Edition" book simulating lazy sequences in Java. Of ...
2
votes
1answer
58 views
RLE-like string compression in clojure
There have been already many similar questions to this one (e.g. this and this, just to point two), but I did not find any for clojure.
The goal is to compress a string in a RLE-like way: i.e. each ...
5
votes
1answer
266 views
Shuffle a deck of cards, using the overhand shuffle method
I've started learning Clojure, after many years of Java. As one of a series of exercises, I'm writing a simple card game, and the overhand-shuffle function is shown ...
2
votes
1answer
48 views
Add an entry to every element in a nested data structure
I currently use a data structure like this:
...
6
votes
1answer
50 views
Printing a nested data structure in Clojure
I wrote the following code which transforms a nested data structure
...
3
votes
2answers
191 views
Djikstra's algorithm in Clojure
I'm learning Clojure and I'm interested in areas that could be more idiomatic. The main function is below. If you're interested in the whole lib, check out this.
The function operates on a ...
6
votes
1answer
64 views
Creating and displaying a checkers board
I am learning clojure this week end and just starting to develop a simple checkers engine. I currently coded some basic functions to create the board and display it. I would love to get some feedback !...
4
votes
1answer
56 views
Visualizing Brainf_ck interpreter in ClojureScript
I have written a working Brainfuck interpreter using ClojureScript, reagent, core.async and dommy. I am not very satisfied with the code, however, in particular the central part of the code - the ...
9
votes
2answers
134 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 ...
4
votes
1answer
86 views
Sending mail using nodemailer in Clojure
I'm very new to Clojure/ClojureScript and have a question regarding a "proper" way to express something.
This code sends a mail using nodemailer on nodejs:
...
4
votes
2answers
92 views
Squaring a tree in Clojure
I am working on Problem 2.30 from Structure and Interpretation of Computer Programs. I book is in scheme, but I am doing the exercises in Clojure.
The problem is to write code that takes a tree of ...
1
vote
1answer
61 views
1
vote
3answers
455 views
Sum of digits in Clojure
I wrote a simple program to sum the digits of a number in Clojure for learning purpose. Not very complex (I hope) so not adding any explanation. I am a beginner in Clojure so please don't mind ...
0
votes
0answers
89 views
RabbitMQ RPC client
I'm familiarising myself with RabbitMQ and Clojure, so I looked at the Get Started guide for the former and added the client and server parts for the RPC tutorial.
I already got the feedback that ...
2
votes
2answers
88 views
PMX crossover implementation in Clojure
I'm starting to learn Clojure and as an exercise I've implemented the following functions (written in Java) in Clojure:
...