My New Year's resolution for 2014: I am going to solve 99 Clojure problems inspired by "S-99: Ninety Nine Scala Problems" and "P-99: Ninety Nine Prolog Problems". It might be a bit ambitious, but we will see.
I thought it would be a good idea to cover each problem and its solution in a short blog post. I will try to do it in a format that does not reveal the solution right away (there will be a link to the solution in each post).
Another word of warning: I am really just starting my Clojure adventure and the code presented here does not claim to be correct or idiomatic Clojure. I hope to see continuous improvement throughout the process though. If you have suggestions or more elegant solutions to one of the problems, please let me know.
The classification of the problems works as follows: * means easy, ** means 60-90 minutes if you are a skilled programmer, *** means difficult. The levels of difficulty are not based on my own experience but taken from the original Prolog problems.
Lists
- P01 (*): Find the last element of a list
- P02 (*): Find the penultimate element of a list
- P03 (*): Find the kth element of a list
- P04 (*): Find the number of elements of a list
- P05 (*): Reverse a list
- P06 (*): Find out whether a list is a palindrome
- P07 (**): Flatten a nested list structure
- P08 (**): Eliminate consecutive duplicates of list elements
- P09 (**): Pack consecutive duplicates of list elements into sublists
- P10 (*): Run-length encoding of a list
- P11 (*): Modified run-length encoding
- P12 (**): Decode a run-length encode list
- P13 (**): Run-length encoding of a list (direct solution)
- P14 (*): Duplicate the elements of a list
- P15 (**): Duplicate the elements of a list a given number of times
- P16 (**): Drop every nth element of a list
- P17 (*): Split a list into two parts
- P18 (**): Extract a slice from a list
- P19 (**): Rotate a list N places to the left
- P20 (*): Remove the Kth element from a list
- P21 (*) Insert an element at a given position into a list.
- P22 (*): Create a list containing all integers within a given range
- P23 (**): Extract a given number of randomly selected elements from a list
- P24 (*): Lotto: Draw N different random numbers from the set 1...M
- P25 (*): Generate a random permutation of the elements of a list
- P26 (**) Generate the combinations of K distinct objects chosen from the N elements of a list
- P27 (**) Group the elements of a set into disjoint subsets
- P28 (**) Sorting a list of lists according to length of sublists
Arithmetic
- P31 (**) Determine wether a given number is prime
- P32 (**) Determine the greatest common divisor of two positive integers
- P33 (*) Determine whether two positive integer numbers are coprime.
- P34 (**) Calculate Euler's totient function phi(m)
- P35 (**) Determine the prime factors of a given positive integer
- P36 (**) Determine the prime factors of a given positive integer (2)
- P37 (**) Calculate Euler's totient function phi(m) (improved)
- P38 (*) Compare the two methods of calculating Euler's totient function
- P39 (*) A list of prime numbers
- P40 (**) Goldbach's conjecture
- P41 (**) A list of Goldbach compositions
Logic and Codes
- P46 (**) Truth tables for logical expressions
- P47 (**) Truth tables for logical expressions (2)
- P48 (**) Truth tables for logical expressions (3)
- P49 (**) Gray code
- P50 (***) Huffman Code
Binary Trees
- P54 (*) Is this a binary tree?
- P55 (**) Construct completely balanced binary trees
- P56 (**) Symmetric binary trees
- P57 (**) Binary search trees
- P58 (**) Generate-and-test paradigm
- P59 (**) Construct height-balanced binary trees
- P60 (**) Construct height-balanced binary trees with a given number of nodes
- P60 (Alternative Solution) Construct height-balanced binary trees with a given number of nodes
- P61 (*) Count the leaves of a binary tree
- P61A (*) Collect the leaves of a binary tree in a list
- P62 (*) Collect the internal nodes of a binary tree in a list.
- P62A (*) Collect the nodes at a given level in a list
- P63 (**) Construct a complete binary tree
2 comments:
Have you seen 4Clojure? foreclojure could also be interesting to have a good workflow.
I knew 4Clojure, but hadn't heard of foreclojure. Thanks!
Post a Comment