2
votes
1answer
41 views

LISP - Modify string

I have to write a program that changes a string's vowels, consonants and other symbols into C, V respectively 0. I've done this but I wonder if there is a more efficient and elegant way to do it. ...
0
votes
2answers
56 views

Improving readability of non-recursive depth first search function in Lisp

As a free-time activity in order to learn some Lisp I had to implement depth first directed graph search. Due to large graph size (800K nodes, 5M arcs) recursion-based approach I could devise didn't ...
0
votes
1answer
52 views

Proper use of reduce, nested loops

Below is an implementation of Dijkstra's shortest path algorithm. It's input graph is represented as an association list of source nodes to assoc of target node and arc weight. My question is about ...
1
vote
1answer
64 views

How to improve readability of a big lisp function

My main method (remove-random-edge) looks quite difficult to read. I'm new to list, so would appreciate any advice on how to improve the code. (defun find-node (node graph) (find-if #'(lambda (i) ...
4
votes
1answer
103 views

Seeking advice on lispiness of style and approach

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

Looking for any improvements to my Common Lisp code

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 ...
2
votes
0answers
116 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 ...
1
vote
2answers
101 views

with-alist-bind

Take 4 (alteration based on feedback from Rainer Joswig): (defmacro with-gensyms ((&rest names) &body body) `(let ,(loop for n in names collect `(,n (gensym))) ,@body)) (defmacro ...
2
votes
4answers
738 views

(Common Lisp) Finite State Machine code

I have been making this FSM today. However, as this is probably the biggest practical program I have ever written in CL, I don't know if there are some things that could be improved, or if using a ...
1
vote
2answers
323 views

(Common Lisp) Is f(n) = n^2 + 3n + 5 not ever divisible by 121?

Given the following problem: ;3.4 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.[3] I wrote the following ...
1
vote
1answer
77 views

(Common Lisp) 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: (defun k (n) (ash 2 (1- n))) (loop for n ...
2
votes
2answers
649 views

(Common Lisp) Palindrome-p

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 should ...
1
vote
1answer
134 views

(Common Lisp) 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
195 views

Compute Arithmetic Sum of a Constant Difference Sequence

3.1 Write a program that computes the arithmetic sum of a constant difference sequence. I. e.: D0 = A Dn+1 = Cdn + B Run the following values and compare to the closed form solution. Maximum index = ...
1
vote
1answer
266 views

Common Lisp - 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 ...
3
votes
1answer
471 views

Common Lisp - Solve a Cryptoarithmetic Problem

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: ;;Cryptoarithmetic. In cryptoarithmetic problems, we ...
2
votes
3answers
865 views

(Common Lisp) 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. (defun read-number () (format t "Enter a number: ~%") (read)) (defun reverse-string ...
4
votes
2answers
389 views

Common Lisp - 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 ...
4
votes
5answers
549 views

Determine type of triangle in LISP

This is a simple LISP program to read in three sides of a triangle and report what kind of triangle it is (or isn't). Any feedback would be much appreciated. (defun read-side (side) (format t "Enter ...
4
votes
3answers
545 views

Sorting numbers in LISP

I am doing a CS practice exercise in which you are supposed to sort exactly three numbers using only if statements. I wrote the following code in LISP and would appreciate any suggestions how to ...
3
votes
3answers
891 views

Code Review of my Lisp Quicksort code

I would really appreciate it if someone could review my LISP code. I was attempting to write a quicksort implementation. Additionally, I generated my list dynamically and wrote a couple of tests. ...