Solutions to the L-99: Ninety-Nine Lisp Problems
Solutions to Ninety-Nine Lisp Problems
Here are solutions to the
L-99: Ninety-Nine Lisp Problems, (which themselves are derived from
a list of prolog problems).
Working with lists
- p01.lisp P01 (*) Find the last box of a list.
- p02.lisp P02 (*) Find the last but one box of a list.
- p03.lisp P03 (*) Find the K'th element of a list.
- p04.lisp P04 (*) Find the number of elements of a list.
- p05.lisp P05 (*) Reverse a list.
- p06.lisp P06 (*) Find out whether a list is a palindrome.
- p07.lisp P07 (**) Flatten a nested list structure.
- p08.lisp P08 (**) Eliminate consecutive duplicates of list elements.
- p09.lisp P09 (**) Pack consecutive duplicates of list elements into sublists.
- p10.lisp P10 (*) Run-length encoding of a list.
- p11.lisp P11 (*) Modified run-length encoding.
- p12.lisp P12 (**) Decode a run-length encoded list.
- p13.lisp P13 (**) Run-length encoding of a list (direct solution).
- p14.lisp P14 (*) Duplicate the elements of a list.
- p15.lisp P15 (**) Replicate the elements of a list a given number of times.
- p16.lisp P16 (**) Drop every N'th element from a list.
- p17.lisp P17 (*) Split a list into two parts; the length of the first part is given.
- p18.lisp P18 (**) Extract a slice from a list.
- p19.lisp P19 (**) Rotate a list N places to the left.
- p20.lisp P20 (*) Remove the K'th element from a list.
- p21.lisp P21 (*) Insert an element at a given position into a list.
- p22.lisp P22 (*) Create a list containing all integers within a given range.
- p23.lisp P23 (**) Extract a given number of randomly selected elements from a list.
- p24.lisp P24 (*) Lotto: Draw N different random numbers from the set 1..M.
- p25.lisp P25 (*) Generate a random permutation of the elements of a list.
- p26.lisp P26 (**) Generate the combinations of K distinct objects chosen from the N elements of a list
- p27.lisp P27 (**) Group the elements of a set into disjoint subsets.
- p28.lisp P28 (**) Sorting a list of lists according to length of sublists
Arithmetic
- p31.lisp P31 (**) Determine whether a given integer number is prime.
- p32.lisp P32 (**) Determine the greatest common divisor of two positive integer numbers.
- p33.lisp P33 (*) Determine whether two positive integer numbers are coprime.
- p34.lisp P34 (**) Calculate Euler's totient function phi(m).
- p35.lisp P35 (**) Determine the prime factors of a given positive integer.
- p36.lisp P36 (**) Determine the prime factors of a given positive integer (2).
- p37.lisp P37 (**) Calculate Euler's totient function phi(m) (improved).
- p38.lisp P38 (*) Compare the two methods of calculating Euler's totient function.
- p39.lisp P39 (*) A list of prime numbers.
- p40.lisp P40 (**) Goldbach's conjecture.
- p41.lisp P41 (**) A list of Goldbach compositions.
Logic and Codes
- p46.lisp P46 (**) Truth tables for logical expressions.
- p47.lisp P47 (*) Truth tables for logical expressions (2).
- p48.lisp P48 (**) Truth tables for logical expressions (3).
- p49.lisp P49 (**) Gray code.
- p50.lisp P50 (***) Huffman code.
Binary Trees
- p54a.lisp P54A (*) Check whether a given term represents a binary tree
- p55.lisp P55 (**) Construct completely balanced binary trees
- p56.lisp P56 (**) Symmetric binary trees
- p57.lisp P57 (**) Binary search trees (dictionaries)
- p58.lisp P58 (**) Generate-and-test paradigm
- p59.lisp P59 (**) Construct height-balanced binary trees
- p60.lisp P60 (**) Construct height-balanced binary trees with a given number of nodes
- p61.lisp P61 (*) Count the leaves of a binary tree
- p61a.lisp P61A (*) Collect the leaves of a binary tree in a list
- p62.lisp P62 (*) Collect the internal nodes of a binary tree in a list
- p62b.lisp P62B (*) Collect the nodes at a given level in a list
- p63.lisp P63 (**) Construct a complete binary tree
- p64.lisp P64 (**) Layout a binary tree (1)
- p65.lisp P65 (**) Layout a binary tree (2)
- p66.lisp P66 (***) Layout a binary tree (3)
- p67.lisp P67 (**) A string representation of binary trees
- p68.lisp P68 (**) Preorder and inorder sequences of binary trees
- p69.lisp P69 (**) Dotstring representation of binary trees
Multiway Trees
- p70b.lisp P70B (*) Check whether a given term represents a multiway tree
- p70c.lisp P70C (*) Count the nodes of a multiway tree
- p70.lisp P70 (**) Tree construction from a node string
- p71.lisp P71 (*) Determine the internal path length of a tree
- p72.lisp P72 (*) Construct the bottom-up order sequence of the tree nodes
- p73.lisp P73 (**) Lisp-like tree representation
Graphs
- p80.lisp P80 (***) Conversions
- p81.lisp P81 (**) Path from one node to another one
- p82.lisp P82 (*) Cycle from a given node
- p83.lisp P83 (**) Construct all spanning trees
- p84.lisp P84 (**) Construct the minimal spanning tree
- p85.lisp P85 (**) Graph isomorphism
- p86.lisp P86 (**) Node degree and graph coloration
- p87.lisp P87 (**) Depth-first order graph traversal (alternative solution)
- p88.lisp P88 (**) Connected components (alternative solution)
- p89.lisp P89 (**) Bipartite graphs
Miscellaneous Problems
- p90.lisp P90 (**) Eight queens problem
- p91.lisp P91 (**) Knight's tour
- p92.lisp P92 (***) Von Koch's conjecture
- p93.lisp P93 (***) An arithmetic puzzle
- p94.lisp P94 (***) Generate K-regular simple graphs with N nodes
- p95.lisp P95 (**) English number words
- p96.lisp P96 (**) Syntax checker (alternative solution with difference lists)
- p97.lisp P97 (**) Sudoku
- p98.lisp P98 (***) Nonograms
- p99.lisp P99 (***) Crossword puzzle