Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

2
votes
2answers
101 views

Project Euler problem 86 taking a long time

I'm trying to solve problem 86 in Project Euler. After some tinkering, I managed to unroll the DP solution into a loop. But still the solution takes >150s to complete. What can I do to improve the ...
0
votes
0answers
18 views

Naïve Prime Factorization in Clojure Pt. 2

After my last review request, I decided to try and make a "tree" visualization, and thought that I could benefit from making find-prime-factors lazily produce prime ...
1
vote
1answer
26 views

Powerset of collection in Clojure

Similar to this question, here's another implementation. Assume the input is already a set. ...
1
vote
0answers
23 views

Naïve Prime Factorization in Clojure

I saw a question about prime factorization on Stack Overflow and realized I had never attempted it before. This was what I ended up with after some playing around and tweaking. I'd like improvements ...
2
votes
2answers
61 views

Project Euler #10 (sum of primes less than two million) in Clojure

I'm new to Clojure and using some Project Euler problems to familiarize myself with the language's capabilities. Problem #10 asks to find the sum of all primes less than two million. I wanted to ...
2
votes
1answer
53 views

Program finds the first almost matching string in a list - Advent Of Code 2018 Day 2 Part 2

Advent of Code 2018, day 2, part 2: The [two IDs you are looking for] differ by exactly one character at the same position in both strings. For example, given the following IDs: ...
0
votes
1answer
48 views

Five functions to get the digits of a number

I'm writing a simple function: given a number, it will return a sequence or a collection of the digits in the number (in the correct order). i.e ...
1
vote
1answer
52 views

Project Euler #49: Find 12-digit number concatenating a three terms sequence

First of all, project Euler has been a great help for me to learn Clojure. I tried for months trying to get web projects going but ended up frustrated with and struggling with tooling and libraries ...
0
votes
2answers
93 views

Project Euler 23 implementation

This code to solve Problem 23 in Project Euler gives the correct answer. But, running the last expression takes around 40 seconds. I welcome advice on how to improve performance here. ...
1
vote
0answers
33 views

Number Stringifier in Clojure

As an exercise, I decided to write a program that spells out numbers. For example: (stringify-int 12345) => "twelve thousand three hundred forty-five" It ...
1
vote
2answers
68 views

Classic “100 doors” simulation in Clojure

I read this question about the "100 Doors" puzzle, and thought that it would make for a good quick exercise. I ended up with two implementations. The first is more straightforward and uses a vector ...
1
vote
0answers
35 views

Clojure macro to gather functions in a namespace into a map

I'm learning Clojure via a pet project. The project would consist of several workers that would be called from other functions. Each worker is defined in their own namespace as a set of functions (...
1
vote
2answers
32 views

Recamán Sequence (A005132)

I'm going to screw around with visualizing Recamán's Sequence, but want to have a good sequence generator to generate the sequence before I start. I want to use a lazy generator for my actual ...
4
votes
1answer
105 views

A* in Clojure - trickier than I expected

While working through some coding puzzles to brush up on Clojure, I encountered the need to use A* on some search problems. I tried to implement it from first principles/memory and that didn't go ...
7
votes
1answer
138 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'...
1
vote
0answers
24 views

Cleanly preventing flashing an element from corrupting future flashes

For a Seesaw (Swing) app I'm writing, I need to be able to flash a component for a certain duration. Here's the basic function I came up with that accomplishes this: ...
0
votes
1answer
49 views

All of Clojure's Expression Threading Macros

I was bored and in a mood to write some macros, so I decided as an exercise to try and remake each of the standard threading macros: ->, ...
3
votes
1answer
41 views

Mutative Heap's algorithm (permutations generator) in Clojure

For a side project I'm working on, I need to be able to generate permutations. Instead of relying on an existing library like math.combinatorics, I decided to write ...
2
votes
0answers
52 views

An ISeq implementing Priority Queue

This is a follow up to my last review request. I made three major changes: I had it fully implement ISeq and IPersistentStack, ...
2
votes
0answers
43 views

A Priority Queue implemented using a Linked List

I'm going to write a Huffman Coding implementation, and decided to write from scratch a priority queue to help out. I've never written a priority queue before, in any language, so this was interesting....
2
votes
1answer
85 views

Kids bank account in Clojure

I'm learning clojure. A while back I made a python bank account for my kids, teaching them to save. Have a look here. The Python one was a class and it created a table that had a little interest ...
4
votes
1answer
82 views

Implementing parser combinators in a functional manner

I am just starting on my journey of learning clojure (I have just read to the end of chapter 3 in clojure for the brave and true). So for practice, I wrote some parser combinator functions. I am quite ...
3
votes
1answer
37 views

Pascal's Triangle - Remove hack

I had a thought last night on how I could easily write a Pascal's Triangle generator basically just using partition and map. I ...
2
votes
1answer
71 views

Sorting texts by similarity in Clojure

This is my first attempt with a lisp language. I'd like your review to address the following points, already listed in order of relevance: Is my code making good use of standard library? Is my code ...
3
votes
1answer
43 views

Finding the comic ID of the last XKCD comic published

I decided to sidetrack and create a XKCD viewer. For certain functionality, I needed to be able to find the ID of the last comic published. This was my attempt. I'm using Enlive here to parse the page ...
3
votes
1answer
114 views

Functional Sieve of Eratosthenes in Clojure

For some reason, this is the first time I've ever written an implementation of the Sieve of Eratosthenes. I basically just stared at the Wikipedia walkthrough of the algorithm until it made sense, ...
3
votes
1answer
70 views

Solving Knight's Travails Problem without using vector for position

I'm trying to implement a solution to the The Odin Project - Project 2: Knight’s Travails in Clojure (Functional Programming) based on the solution posted by benjdelt. I would like to know your ...
1
vote
0answers
33 views

Generate a random, nested map

To answer a question on Stack Overflow, I needed to generate a large, nested map that I could postwalk over to do some testing. After a couple stabs, this is what ...
4
votes
0answers
61 views

Macro that allows for Linear Problem notation to create Genetic Algorithm fitness functions

As a side toy project for my Genetic Algorithm, I decided to try to create a macro that lets you use maximize: ... subject to: ... linear problem notation to ...
3
votes
1answer
45 views

A running gene crossover function for a Genetic Algorithm

I'm writing a Genetic Algorithm, and need to write a function that crosses two gene sequences. Basically, I want it to work like this: ...
6
votes
1answer
77 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. ...
2
votes
1answer
157 views

Linked list implementation in Clojure

Background Linked lists are a well-known data structure, so I won't waste too much detail on them. Suffice to say that a linked list consists of "cells". Each cell contains some kind of value and a ...
4
votes
1answer
91 views

Rock-Paper-Scissors game in Clojure

I followed braveclojure book and built this little command line Rock, Paper, Scissors game. The game works fine, but I was wondering if there is a better / more ...
1
vote
0answers
68 views

Performance concerns when solving sliding-tile-puzzle via A* algorithm

I have implemented n-puzzle solving in Clojure using A-star algorithm. The following code, when used like this: (solve [0 1 2 3 4 0 6 7 5 8] 3) would return ...
1
vote
2answers
28 views

Predicate testing for equality that returns the common element

I'm going to try brute-forcing the solving of a Magic Square. To simplify the code later on, I wanted a function similar to =, but one that returns the common ...
2
votes
1answer
96 views

Bloom-filter implementation in Clojure

Background Bloom-filter is a data structure to which we can insert elements, and check if it already contains a given element. The peculiarity is, that if a ...
2
votes
2answers
68 views

Find the middle of the string

The follow code should correctly run the test cases at the bottom. It works correctly. I just don't feel like this is clearest way I could write it. A lot of the complexity comes from having to ...
4
votes
0answers
40 views

Sierpinski Carpet using Seesaw

I decided to write a Sierpinski Carpet generator. This has been something I wanted to try since watching the Coding Train this summer. A screenshot of it in action with some experimental coloring: ...
0
votes
1answer
40 views

Find combinations of items in a nested collection

It's a very typical problem that I come across here and there. Imagine that you have a collection of items of any type, and sometimes items are collections themselves; you then need to "expand" them ...
3
votes
0answers
45 views

SQL-like syntax to sort and filter a collection

I was helping someone on SO with an assignment to create a macro that accepts an SQL-like syntax, and optionally sorts and filters a collection. I realized that while their instructor is insisting on ...
1
vote
0answers
320 views

Infix to RPN converter using the Shunting-Yard Algorithm

I need to be able to parse simple equations in an app I'm writing, and decided to try writing my own parser. I ended up using the Shunting-Yard Algorithm to convert from infix notation to RPN as the ...
2
votes
2answers
64 views

Program follows sequence of instructions to arrive at destination

I'm warming up with Clojure to try my hand at the advent of code challenge that starts in December. This is my attempt at the first challenge from last year. This is my first attempt at a non trivial ...
0
votes
3answers
217 views

Binary search algorithm in Clojure

I'm absolutely new to Clojure (started learning it yesterday). After I went through some tutorials and checked out the basics I implemented the following Binary search algorithm: ...
2
votes
0answers
133 views

Simple client/server library

I'm writing a Tamagotchi clone, and decided to try making an online version. Since I don't do a lot of networking projects, I decided to try and go off on a tangent and screw around with sockets and ...
1
vote
1answer
41 views

Macro that generates a defn

I need to save nested data to disk for a project. Right now, my state is a nested record, and has proven to be a pain to serialize. I tried compressing it to a map, but after testing it, I realized my ...
3
votes
2answers
82 views

Code Chef RAINBOW Palindrome

Problem Determine whether an array is "Rainbow", i.e. it has the following structure: First a1 elements equal 1. Next a2 elements equal 2. Next a3 elements equal 3. Next a4 elements ...
3
votes
1answer
94 views

Flattening a nested record to its leaves

Note, I discovered a bug after I posted this. The current implementation drops any fields that have an associative value, which is not the intended behavior. I'm writing a Tamagotchi clone, and need ...
1
vote
1answer
41 views

Reducing golfed redundancy

For the "First they came" golfing challenge, I wrote the following: ...
5
votes
1answer
137 views

Depth-first Search Non-Reursive Implementation in Clojure

I've created a non-recursive dfs implementation in Clojure. I'm using the wikipedia article on dfs as a guide. I'm very new to Clojure and functional programming in general. Any tips to improve ...
4
votes
1answer
74 views

Picking a random state from a set based on probabilities

I'm writing a Markov Chain implementation, and need to be able to pick a random state from a set of states, where each state has a different probability of being chosen. In my caffeine-high, I wrote ...