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
2
votes
1answer
54 views

Custom threading macro

To help myself learn macros, I made a custom version of the threading macro that lets you choose which argument the "thread" gets put into. My main concern is simplifying it, and making it more ...
4
votes
2answers
155 views

Birthday Paradox Tester

I randomly decided to write a program that tests the Birthday Problem/Paradox. The gist of the problem/paradox is that if you have a group of people in a room, how many people are required for there ...
2
votes
2answers
82 views

Lazy sub sequence

For a genetic algorithm I'm writing, I need to sub-sequence a list, but I need it to be lazy so I can compose it with other lazy functions. If I introduce strictness into the chain, I risk potentially ...
1
vote
2answers
40 views

Shuffling many collections by folding over a numeric range

Often, I find myself folding over a range object if I need to repeatedly transform something. This, to me though, feels like an abuse of ...
2
votes
3answers
307 views

Solving quadratic equation in Clojure

I wrote a function in Clojure to solve quadratic equations using the quadratic formula The function ...
0
votes
1answer
26 views

Filtering out illegal moves from a map of available moves

I'm writing a console blackjack game. To hold all the possible moves a player can make, I have a map that maps a keyboard key to a move keyword: ...
1
vote
1answer
180 views

A Simple Async Task in Clojure

Purpose of Code: To simulate scraping the web and updating a db, by, presently, adding randomly generated numbers to a "database". Have I wired up the followin async code properly? Is there a simpler,...
3
votes
1answer
649 views

Get RSS feeds and store them into database

It is my first program in Clojure. It read RSS feed's list from text file, get each feed and store result into sqlite database. project.clj: ...
3
votes
2answers
138 views

Project Euler #11 - Largest product in a grid

Problem statement I've tried to solve the following Euler problem in a very straight-forward way, ideally avoiding recursion if possible and writing it in a functional style. What is the greatest ...
1
vote
1answer
96 views

Project Euler #6 - Sum square difference

I'd like to get the code below reviewed on all aspects, specifically I wonder if it's common usage to use let like this, as currently more computations are done in ...
4
votes
2answers
69 views

Project Euler #3

I'd like to have the code below reviewed on all aspects. Task: Largest prime factor The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ...
2
votes
1answer
128 views

Project Euler #1 - Revisited

I'm learning Clojure and solved Project Euler #1, I'd like to have my code reviewed on all aspects. I'm marking this as follow-up of Project Euler #1 because I answered my own question and implemented ...
2
votes
0answers
175 views

Selectively flatten JSON structure

Today I spent quite some time on providing a solution for a Stack Overflow answer. It looked quite easy to me, but my solution is complex. The question can be found here and this is my answer. If I ...
4
votes
1answer
84 views

Project Euler #1

I'm learning Clojure and solved Project Euler #1, I'd like to have my code reviewed on all aspects and have one specific question. This is also my first Functional Programming language, I have however ...
5
votes
1answer
329 views

A very simple TODO app's domain model

I am currently rewriting a todo app from java to clojure. This is my first "real" clojure project so I'm not sure that what I write is idiomatic clojure code. I have just finished rewriting the domain ...
3
votes
1answer
35 views

Search for everything at a tile in Minesweeper

I'm writing a Minesweeper clone. I needed a function that returns everything located at a certain tile, and ended up with an atrocious mess. I'd like help making it cleaner and more idiomatic. The ...
5
votes
2answers
108 views

Resolve double auction orders

Given a vector of seller orders (asks) of a certain product (each order having a price) and buyer orders (bids) of the same product, I'm creating a function that resolves the auction by matching the ...
2
votes
0answers
94 views

Handling async in Clojure

I've defined myself a function for caching requests and their responses in a browser environment; I'm using ClojureScript. ...
1
vote
0answers
404 views

Pattern match on type in Clojure spec conformer

I am using Clojure spec to conform (coerce) a 1 or 2 value of a number type or string into a 1, 2 or :clojure.spec/invalid. ...
6
votes
1answer
95 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 ...
2
votes
1answer
103 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. ...
3
votes
1answer
73 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
498 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 ...
2
votes
1answer
1k 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
164 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
191 views

Clojure performance for solving Project Euler 72 (counting proper reduced fractions)

Challenge 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\$? Code ...
3
votes
1answer
152 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
134 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
69 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: ...
2
votes
1answer
382 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
87 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
233 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
1k 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
52 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
86 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
145 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: ...
3
votes
1answer
432 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
403 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
98 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: ...
5
votes
2answers
372 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
2answers
474 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
167 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 ...
4
votes
1answer
103 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
308 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
552 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\$...
5
votes
2answers
270 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 ...
14
votes
0answers
178 views

Tracking the bounding box of a map

Context I have a bunch of data points that look roughly like this: ...
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 ...
2
votes
1answer
96 views

Integer square root

This essentially performs the same function as exact-integer-sqrt in math.numeric-tower. ...
64
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 ...