Common Lisp, or ANSI Common Lisp, is a standardized version of the Lisp programming language intended for production-strength power and libraries.
3
votes
2answers
65 views
Invert the bits of a non-negative integer in Common Lisp (SBCL)
I'm doing code challenges to learn Common Lisp. I'm trying to invert all the bits in any given positive integer.
My current solution does it the math way, by recursing on a number, dividing it by two,...
3
votes
1answer
37 views
A heart.lisp I wrote with my 6 year old daughter
Is it possible to improve this program somehow? It will probably be more convenient to suggest edits as forks of this Gist.
...
8
votes
2answers
74 views
Project Euler #2 (classic) - Sum of even fibonacci numbers below 4 million
I'm looking to use LISP as best I can, not just get the right answer. This is very early on in my LISP career so feedback is welcome and exciting! Recently asked about Project Euler #1, got some ...
4
votes
2answers
168 views
Sum of all multiples of 3 or 5 below 1000 (Project Euler #1 - typical)
I'm learning LISP and am starting with Project Euler. I would love some initial feedback on my LISP code for this simple task.
I know it spits out the correct answer, but what I'm not sure about is ...
7
votes
5answers
263 views
FizzBuzz - officially now in CLISP
I had to jump on the bandwagon for this one. The task does a great job of helping you learn a language you're unfamiliar with.
So today I present you with my version of the infamous FizzBuzz game in ...
1
vote
1answer
53 views
Sort 3 numbers in Common Lisp with the minimum number of operations
I’m wondering is the following function returns a list of three numbers sorted in ascending order with the minimum possible number of operations, or if there is some more efficient or elegant method (...
4
votes
3answers
181 views
Mergesort with an inversion counter
I'm new to Lisp and I'm yet to wrap my head around the lisp way of writing programs. Any comments regarding approach, style, missed opportunities appreciated:
In particular, please advice if I build ...
3
votes
2answers
67 views
Netstring parser in common lisp
Below is a netstring parser I wrote in Common Lisp. The docstring contains the usage and return.
...
11
votes
2answers
131 views
Advent of Code: “Not Quite Lisp”
I have solved this simple challenge on Advent of Code:
Santa is trying to deliver presents in a large apartment building, but
he can't find the right floor - the directions he got are a little
...
13
votes
2answers
753 views
A LISP version of the Schwartzian Transform
Randal Schwartz stole LISP's decorate-sort-undecorate idiom when he came up with what we'd later call the Schwartzian Transform. With all of my LISP knowledge disappeared through nine half lives, but ...
7
votes
1answer
227 views
Functional tree iteration in Common Lisp
I'm adding some functionality to an existing library of data structures in Common Lisp, with a view to asking the original author if I can take over maintenance and development of it. While the ...
6
votes
1answer
106 views
Unit test macro
I have written a couple of macros (? and ??) for performing unit tests, but I'm having some difficulty with modifying it, so I ...
2
votes
1answer
48 views
Once-only macro
I have been learning common lisp and am a newbie, using the great book Practical Common Lisp. There is a once-only macro in the book that I spent a lot of time figuring out how it works. Even after I ...
3
votes
2answers
158 views
Tail recursive FizzBuzz in Common Lisp
I solved FizzBuzz using tail recursion. Is it efficient enough?
...
6
votes
2answers
2k views
Simple web-scraper in Common Lisp (SBCL)
I have written a simple web-scraper in Common Lisp, & would greatly appreciate any feedback:
...
4
votes
2answers
236 views
Project Euler #35 in Common Lisp
To start with Common Lisp I am doing Project Euler using this language. Usually I manage to solve problems but I am quite sure that my code is not as efficient as it could be in Common Lisp. That is ...
3
votes
2answers
104 views
Insertion sort in Common Lisp
This is my first bit of significant code in Common Lisp, an implementation of insertion sort. Being new to Lisp in general, I'm wondering if this code follows best Lisp practices in regards to program ...
2
votes
1answer
74 views
Golden Section Search in Lisp
I implemented the golden section search algorithm recursively in Lisp. My code is:
...
6
votes
1answer
948 views
Generating and using a list of prime numbers
Here is some code I've created to generate and use a list of prime numbers. This is some of the first Common Lisp code I've written, and I'd be grateful for any comments regarding style and its use ...
4
votes
2answers
2k views
Print an integer and its digits reversed
This Common Lisp program is an exercise to print an integer and its digits reversed to the screen:
...
3
votes
1answer
95 views
Producing all allocations by n items from a list
I have strong feeling that the code below is ugly at least as there are 2 same "cons".
I would appreciate if you advise me ways to improve it.
The code produces all allocation by n items from list ...
3
votes
4answers
600 views
Generic sequence splitter in Common Lisp
I wrote a function split-seq-by-n which accepts a sequence and a number and splits the sequence into subsequences of length n (the last subsequence getting the ...
2
votes
2answers
150 views
“Skewed” average in Lisp
I set myself the task to calculate the average of a list, but with two conditions:
negative numbers are ignored
numbers greater than 100 are counted as if they were 100
So the "skewed" average of ...
1
vote
2answers
129 views
Standard deviation of hourly temperatures of 2 days
It seems that when I program in Lisp my brain goes on auto pilot and I end up solving the problem somehow. I don't even think I just do and it works out.
That said, this is some horrible Lisp code ...
5
votes
1answer
55 views
Finding capitalized characters and printing their position & ASCII value
I was trying to find out if a string contained a capitalized letter and if it did I wanted to know the position of the character and its ASCII code. I might have refactored a little to much.
Given an ...
5
votes
1answer
642 views
Solving the 'Vietnamese school maths problem'
Having read Can you do the maths puzzle for Vietnamese eight-year-olds that has stumped parents and teachers?, which presented the problem of filling in numbers 1 to 9 to satisfy
$$ a + 13 \frac{b}{c}...
2
votes
1answer
372 views
Determinant calculation of a matrix of any degree
My program calculates the determinant of a matrix of any degree. If you really can't understand my comments or indentifiers please let me know.
...
5
votes
1answer
516 views
ANFIS network based on Sugeno model I
I've been learning Common Lisp lately and I've implemented ANFIS network based on Sugeno model I.
Network layout and details can be read in these slides by Adriano Oliveira Cruz.
I use sigmoid as the ...
2
votes
3answers
271 views
Recursion vs. iteration in Lisp macro
I've been programming Clojure for a little while and recently started learning Common Lisp. One of my favorite things about Clojure is the threading operator ->, ...
3
votes
2answers
186 views
Creating a repetitive string in Common Lisp
I needed to have a Lisp function that could produce a string of a certain length, created by repeated concatenations of a another string given as argument (so for example by giving 10 and "abc" I ...
2
votes
2answers
112 views
Using reduce twice in a row for Run Length Encoding
First of all, I'm new to Lisp (I currently use CLISP and SBCL). There probably are huge mistakes in this code so any guidelines are welcome :)
I'm very confused about how to do this. It's just about ...
3
votes
2answers
111 views
Written numbers to numerical representation
So I took a stab at this task to begin learning common lisp.
The idea is that you give it a written representation of a number such as "three thousand and forty nine" and it will output 3049.
I was ...
5
votes
3answers
618 views
Calculate the weekday from a date (M-D-Y)
This Common Lisp exercise is to write a program that can calculate the weekday given a string of the format "M-D-Y." It was more challenging than I expected. If you have suggestions about how to ...
6
votes
2answers
536 views
Determining if f(n) = n^2 + 3n + 5 is ever divisible by 121
Given the following problem:
It is conjectured that for any \$n > 0\$, \$n^2 + 3n + 5\$ is never
divisible by 121. Test this conjecture for \$n = 1,2,...,9999,10000\$.
I wrote the following ...
4
votes
1answer
573 views
Finding a cryptoarithmetic solution
This code is intended to find all possible solutions to a cryptoarithmetic problem. The description of the problem I was trying to solve is here:
In cryptoarithmetic problems, we are given a ...
5
votes
3answers
2k views
Lisp quicksort code
I would really appreciate it if someone could review my quicksort implementation. Additionally, I generated my list dynamically and wrote a couple of tests. Of course, I realize that the tests are ...
3
votes
2answers
1k views
Testing input integers for the palindrome property
3.23 Palindromes
A palindrome is a number that reads the same forwards
and backwards, like 12321. Write a
program that tests input integers for
the palindrome property.
Hint: This ...
3
votes
1answer
289 views
Compute arithmetic sum of a constant difference sequence
3.1
Write a program that computes the arithmetic sum of a constant
difference sequence:
D0 = A
Dn+1 = Cdn + B
Run the following values and compare to ...
2
votes
1answer
320 views
Abstract the (duplicate?) behavior between “sort” and “replace”
I have written these two functions that have a similar process. The first is meant to "split" a string on a given character and the second is meant to "replace-all" instances of a character in a ...
2
votes
1answer
96 views
Tabulate k = 2^n minimizing multiplication
Given the following problem:
;3.3 Tabulate the function k = 2^n for n = 1..50.
;Do this for the fewest possible multiplications.[3]
I wrote this answer:
...
2
votes
1answer
203 views
Machine epsilon - find epsi
4.2 Machine Epsilon
Find the floating point number epsi that has
the the following properties:
1.0+epsi is greater than 1.0 and
Let m b e any number less than epsi. Then 1.0+m is ...
2
votes
1answer
105 views
Rewrite apply function to use recursion instead
Probably the hardest part of learning lisp has been to think in the "lisp way" which is elegant and impressive, but not always easy. I know that recursion is used to solve a lot of problems, and I am ...
4
votes
1answer
150 views
First Common Lisp vector math code
I'm studying Common Lisp on my own. Coming from C++, Common Lisp feels kind of strange sometimes. I'd like to get some feedback on what I understood so far.
For learning purposes, I wrote this simple ...
10
votes
1answer
173 views
Generating hard to guess session tokens
Does this code create sufficiently hard-to-guess session tokens, assuming the server and client are communicating over HTTPS?
Take 2 (thanks to this crypto.SE answer):
...
6
votes
4answers
1k views
Finding the sum of all the multiples of 3 or 5 below 1000
As a Lisp (and functional programming) newbie, I wrote the following code that finds the sum of all the multiples of 3 or 5 below 1000, and I suspect that it is lousy:
...
4
votes
1answer
255 views
Did I convert this C++ class to Common Lisp correctly?
Here is the original C++ class I converted to Lisp at the very bottom of this post.
...
2
votes
1answer
482 views
Simple octal reader macro in Common Lisp
As an exercise, I've implemented a simple reader macro in Common Lisp (using SBCL). It converts Octal (unsigned integers only) into numbers.
Usage:
* #z1234
668
...
2
votes
1answer
58 views
Finding optimal row sequence for a melody on 5-row Bayan Accordion, v2.0
Another try at this problem in LISP. This time rather than generating every possible row combination for the melody I tried to calculate the best combination directly. Unfortunately there's a problem -...
5
votes
1answer
296 views
iterative copy-tree in lisp
The common lisp function copy-tree is often implemented in a recursive way,
and thus is prone to stack overflow.
Here is my attempt at writing an iterative version, one-pass, no stack,
no ...
4
votes
2answers
73 views
Calculating series of rows to use to play a melody on 5-row Bayan Accordion
This was my first attempt at writing a program in LISP. Can anyone give any guides as to how it could be improved? The multiple loops in best-pattern seem awkward (I'd normally do that in just one ...