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
158 views

Incrementing colors

I just started messing around with Java's BufferedImage. I had an idea to try to encode a message into a picture by coloring each pixel a certain color that ...
2
votes
1answer
952 views

Flattening a nested map [closed]

We're migrating our streaming ETL application from Python into Clojure, the hottest part of the code isn't yet performing as well as our existing implementation. This looks to be down to the ...
4
votes
1answer
403 views

Short Clojure digit extraction

I'm new to Clojure, and would appreciate feedback on this short program. The problem I set out to solve was selected at random from Project Euler, and is described in the comments. The part that I'm ...
2
votes
2answers
130 views

Finding the longest path in an equally-weighted tree

Its purpose is to find the longest path in an equally-weighted tree denoted as such: 3 1 2 2 3 The first number denotes both the number of vertices and the ...
1
vote
1answer
90 views

Quicklyish finding primes by trial division

I ask because it seems to be taking waaaay more space/time than it should. Also, I know that if I want to be super efficient I should use Java's BitSet and a Sieve of Eratosthenes, but I wrote it like ...
5
votes
0answers
80 views

Python-style object library for Clojure

Background I am authoring pulley.objective, an Open Source library that provides an object system inspired by Python's object model. I have some features ...
7
votes
1answer
259 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 ...
2
votes
1answer
349 views

Multiple files data processing in Clojure

I have made a small script which grabs data into a map from 80 CSV files and calculates some statistics like average, standard deviation etc. It's also adding some additional data to map from filename....
3
votes
2answers
181 views

Scrape 4chan for alive images

I'm trying to learn Clojure recently and I thought writing a simple web app would be a good way to dive in. This function gets the list of alive threads from the API and reduces, filters and maps ...
2
votes
1answer
59 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
164 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
94 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
45 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
409 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
27 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
212 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
710 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
148 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
107 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 ? My ...
3
votes
1answer
145 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
219 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
94 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
342 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
109 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
98 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
437 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
114 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
105 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
133 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
677 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
2k 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
180 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
221 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
170 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
148 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
73 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
400 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
111 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
265 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
2k 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
88 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
187 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
565 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
428 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
100 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
524 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
576 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 ...

1 2
3
4 5
7