Skip to content

Commit 1357df5

Browse files
author
Abhijit Sarkar
committed
Update README
1 parent 9cd9881 commit 1357df5

File tree

15 files changed

+272
-75
lines changed

15 files changed

+272
-75
lines changed

README.md

Lines changed: 210 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,231 @@
22

33
[![](https://github.com/asarkar/99-haskell/workflows/CI/badge.svg)](https://github.com/asarkar/99-haskell/actions)
44

5-
Some problems are intentionally unsolved, because they
6-
are uninteresting/improbable in the context of Haskell.
7-
- These are the problems 38, 47, and 54.
8-
95
A number of problems were added to fill out 99 problems.
106
- These are the problems 29, 30, 42, 43, 44, 45, 51, 52, 53, 74, 75, 76, 77, 78, and 79.
117

12-
## The problems
8+
## Working with lists
9+
10+
[P01](src/List/P01.hs) (*) Find the last element of a list.
11+
12+
[P02](src/List/P02.hs) (*) Find the last but one element of a list.
13+
14+
[P03](src/List/P03.hs) (*) Find the Kth element of a list.
15+
16+
[P04](src/List/P04.hs) (*) Find the number of elements of a list.
17+
18+
[P05](src/List/P05.hs) (*) Reverse a list.
19+
20+
[P06](src/List/P06.hs) (*) Find out whether a list is a palindrome.
21+
22+
[P07](src/List/P07.hs) (**) Flatten a nested list structure.
23+
24+
[P08](src/List/P08.hs) (**) Eliminate consecutive duplicates of list elements.
25+
26+
[P09](src/List/P09.hs) (**) Pack consecutive duplicates of list elements into sublists.
27+
28+
[P10](src/List/P10.hs) (*) Run-length encoding of a list.
29+
30+
[P11](src/List/P11.hs) (*) Modified run-length encoding.
31+
32+
[P12](src/List/P12.hs) (**) Decode a run-length encoded list.
33+
34+
[P13](src/List/P13.hs) (**) Run-length encoding of a list (direct solution).
35+
36+
[P14](src/List/P14.hs) (*) Duplicate the elements of a list.
37+
38+
[P15](src/List/P15.hs) (**) Duplicate the elements of a list a given number of times.
39+
40+
[P16](src/List/P16.hs) (**) Drop every Nth element from a list.
41+
42+
[P17](src/List/P17.hs) (*) Split a list into two parts.
43+
44+
[P18](src/List/P18.hs) (**) Extract a slice from a list.
45+
46+
[P19](src/List/P19.hs) (**) Rotate a list N places to the left.
47+
48+
[P20](src/List/P20.hs) (*) Remove the Kth element from a list.
49+
50+
[P21](src/List/P21.hs) (*) Insert an element at a given position into a list.
51+
52+
[P22](src/List/P22.hs) (*) Create a list containing all integers within a given range.
53+
54+
[P23](src/List/P23.hs) (**) Extract a given number of randomly selected elements from a list.
55+
56+
[P24](src/List/P24.hs) (*) Lotto: Draw N different random numbers from the set 1..M.
57+
58+
[P25](src/List/P25.hs) (*) Generate a random permutation of the elements of a list.
59+
60+
[P26](src/List/P26.hs) (**) Generate the combinations of K distinct objects chosen from the N elements of a list.
61+
62+
[P27](src/List/P27.hs) (**) Group the elements of a set into disjoint subsets.
63+
64+
[P28](src/List/P28.hs) (**) Sorting a list of lists according to length of sublists.
65+
66+
[P29](src/List/P28.hs) (*) Write a function to compute the nth Fibonacci number.
67+
68+
[P30](src/List/P30.hs) (**) Write a function to compute the nth Fibonacci number.
69+
70+
## Arithmetic
71+
72+
[P31](src/Arithmetic/P31.hs) (**) Determine whether a given integer number is prime.
73+
74+
[P32](src/Arithmetic/P32.hs) (**) Determine the greatest common divisor of two positive integer numbers.
75+
76+
[P33](src/Arithmetic/P33.hs) (*) Determine whether two positive integer numbers are coprime.
77+
78+
[P34](src/Arithmetic/P34.hs) (**) Calculate Euler’s totient function ϕ(m).
79+
80+
[P35](src/Arithmetic/P35.hs) (**) Determine the prime factors of a given positive integer.
81+
82+
[P36](src/Arithmetic/P36.hs) (**) Determine the prime factors of a given positive integer (2).
83+
84+
[P37](src/Arithmetic/P37.hs) (**) Calculate Euler’s totient function ϕ(m) (improved).
85+
86+
[P38](src/Arithmetic/P38.hs) (*) Compare the two methods of calculating Euler’s totient function.
87+
88+
[P39](src/Arithmetic/P39.hs) (*) A list of prime numbers.
89+
90+
[P40](src/Arithmetic/P40.hs) (**) Goldbach's conjecture.
91+
92+
[P41](src/Arithmetic/P41.hs) (**) A list of Goldbach compositions.
93+
94+
[P42](src/Arithmetic/P42.hs) (**) Modular multiplicative inverse.
95+
96+
[P43](src/Arithmetic/P43.hs) (*) Gaussian integer divisibility.
97+
98+
[P44](src/Arithmetic/P44.hs) (**) Gaussian primes.
99+
100+
[P45](src/Arithmetic/P45.hs) (*) Gaussian primes using the two-square theorem.
101+
102+
## Logic and Codes
103+
104+
[P46](src/Logic/P46.hs) (**) Truth tables for logical expressions.
105+
106+
[P47](src/Logic/P47.hs) (*) Truth tables for logical expressions (2).
107+
108+
[P48](src/Logic/P48.hs) (**) Truth tables for logical expressions (3).
109+
110+
[P49](src/Logic/P49.hs) (**) Gray code.
111+
112+
[P50](src/Logic/P50.hs) (***) Huffman code.
113+
114+
[P51](src/Logic/P51.hs) (*) Error correction codes.
115+
116+
[P52](src/Logic/P52.hs) (***) Conjunctive normal form.
117+
118+
[P53](src/Logic/P53.hs) (***) Resolution rule.
119+
120+
## Binary Trees
121+
122+
P54A omitted; our tree representation will only allow well-formed trees.
123+
124+
[P55](src/BinaryTree/P55.hs) (**) Construct completely balanced binary trees.
125+
126+
[P56](src/BinaryTree/P56.hs) (**) Symmetric binary trees.
127+
128+
[P57](src/BinaryTree/P57.hs) (**) Binary search trees (dictionaries).
129+
130+
[P58](src/BinaryTree/P58.hs) (**) Generate-and-test paradigm.
131+
132+
[P59](src/BinaryTree/P59.hs) (**) Construct height-balanced binary trees.
133+
134+
[P60](src/BinaryTree/P60.hs) (**) Construct height-balanced binary trees with a given number of nodes.
135+
136+
[P61](src/BinaryTree/P61.hs) (*) Count the leaves of a binary tree.
137+
138+
[P61A](src/BinaryTree/P61a.hs) (*) Collect the leaves of a binary tree in a list.
139+
140+
[P62](src/BinaryTree/P62.hs) (*) Collect the internal nodes of a binary tree in a list.
141+
142+
[P62B](src/BinaryTree/P62b.hs) (*) Collect the nodes at a given level in a list.
143+
144+
[P63](src/BinaryTree/P63.hs) (**) Construct a complete binary tree.
145+
146+
[P64](src/BinaryTree/P64.hs) (**) Layout a binary tree (1).
147+
148+
[P65](src/BinaryTree/P65.hs) (**) Layout a binary tree (2).
149+
150+
[P66](src/BinaryTree/P66.hs) (***) Layout a binary tree (3).
151+
152+
[P67A](src/BinaryTree/P67a.hs) (**) A string representation of binary trees.
153+
154+
[P68](src/BinaryTree/P68.hs) (**) Preorder and inorder sequences of binary trees.
155+
156+
[P69](src/BinaryTree/P69.hs) (**) Dotstring representation of binary trees.
157+
158+
## Multiway Trees
159+
160+
P70B omitted; we can only create well-formed trees.
161+
162+
[P70C](src/MultiwayTree/P70c.hs) (*) Count the nodes of a multiway tree.
163+
164+
[P70](src/MultiwayTree/P70.hs) (**) Tree construction from a node string.
165+
166+
[P71](src/MultiwayTree/P71.hs) (*) Determine the internal path length of a tree.
167+
168+
[P72](src/MultiwayTree/P72.hs) (*) Construct the postorder sequence of the tree nodes.
169+
170+
[P73](src/MultiwayTree/P73.hs) (**) Lisp-like tree representation.
171+
172+
173+
## Monads
174+
175+
[P74](src/Monad/P74.hs) (**) Monads without do notation.
176+
177+
[P75](src/Monad/P75.hs) (*) Maybe monad.
178+
179+
[P76](src/Monad/P76.hs) (*) Either monad.
180+
181+
[P77](src/Monad/P77.hs) (*) List monad.
182+
183+
[P78](src/Monad/P78.hs) (*) Collatz conjecture.
184+
185+
[P79](src/Monad/P79.hs) (**) Postfix notation.
186+
187+
## Graphs
188+
189+
[P80](src/Graph/P80.hs) (***) Conversions.
190+
191+
[P81](src/Graph/P81.hs) (**) Path from one node to another one.
192+
193+
[P82](src/Graph/P82.hs) (*) Cycle from a given node.
194+
195+
[P83](src/Graph/P83.hs) (**) Construct all spanning trees.
196+
197+
[P84](src/Graph/P84.hs) (**) Construct the minimal spanning tree.
198+
199+
[P85](src/Graph/P85.hs) (**) Graph isomorphism.
200+
201+
[P86](src/Graph/P86.hs) (**) Node degree and graph coloration.
202+
203+
[P87](src/Graph/P87.hs) (**) Depth-first order graph traversal.
204+
205+
[P88](src/Graph/P88.hs) (**) Connected components.
13206

14-
* Questions 1 to 10: [Lists](src/Lists.hs)
207+
[P89](src/Graph/P89.hs) (**) Bipartite graphs.
15208

16-
* Questions 11 to 20: [Lists, continued](src/Lists2.hs)
209+
## Miscellaneous Problems
17210

18-
* Questions 21 to 30: [Lists again](src/Lists3.hs)
211+
[P90](src/Misc/P90.hs) (**) Eight queens problem.
19212

20-
* Questions 31 to 45: [Arithmetic](src/Arithmetic.hs)
213+
[P91](src/Misc/P91.hs) (**) Knight’s tour.
21214

22-
* Questions 46 to 53: [Logic and codes](src/Logic.hs)
215+
[P92](src/Misc/P92.hs) (***) Von Koch’s conjecture.
23216

24-
* Questions 54A to 60: [Binary trees](src/BinaryTrees.hs)
217+
[P93](src/Misc/P93.hs) (***) An arithmetic puzzle.
25218

26-
* Questions 61 to 69: [Binary trees, continued](src/BinaryTrees2.hs)
219+
[P94](src/Misc/P94.hs) (***) Generate K-regular simple graphs with N nodes.
27220

28-
* Questions 70B to 73: [Multiway trees](src/MultiwayTrees.hs)
221+
[P95](src/Misc/P95.hs) (**) English number words.
29222

30-
* Questions 74 to 79: [Monads](src/Monads.hs)
223+
[P96](src/Misc/P96.hs) (**) Syntax checker.
31224

32-
* Questions 80 to 89: [Graphs](src/Graphs.hs)
225+
[P97](src/Misc/P97.hs) (**) Sudoku.
33226

34-
* Questions 90 to 94: [Miscellaneous problems](src/Misc.hs)
227+
[P98](src/Misc/P98.hs) (***) Nonograms.
35228

36-
* Questions 95 to 99: [Miscellaneous problems, continued](src/Misc2.hs)
229+
[P99](src/Misc/P99.hs) (***) Crossword puzzle.
37230

38231
## Running tests
39232

ninety-nine-haskell.cabal

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ library
3636
Arithmetic.P44
3737
Arithmetic.P45
3838
BinaryTree.BinaryTree
39+
BinaryTree.P54a
3940
BinaryTree.P55
4041
BinaryTree.P56
4142
BinaryTree.P57
@@ -92,10 +93,8 @@ library
9293
List.P24
9394
List.P25
9495
List.P26
95-
List.P27a
96-
List.P27b
97-
List.P28a
98-
List.P28b
96+
List.P27
97+
List.P28
9998
List.P29
10099
List.P30
101100
Logic.Logic
@@ -112,6 +111,7 @@ library
112111
Misc.P91
113112
Misc.P92
114113
Misc.P93
114+
Misc.P94
115115
Misc.P95
116116
Misc.P96
117117
Misc.P97
@@ -216,9 +216,8 @@ test-suite ninety-nine-test
216216
List.P24Spec
217217
List.P25Spec
218218
List.P26Spec
219-
List.P27bSpec
220-
List.P28aSpec
221-
List.P28bSpec
219+
List.P27Spec
220+
List.P28Spec
222221
List.P29Spec
223222
List.P30Spec
224223
Logic.LogicSpec

src/BinaryTree/P54a.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module BinaryTree.P54a where
2+
3+
-- Problem 54A: (*) Check whether a given term represents a binary tree.
4+
-- ANSWER: Creating an invalid tree is not possible in Haskell.

src/BinaryTree/P55.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ module BinaryTree.P55 (cbalTree) where
22

33
import BinaryTree.BinaryTree (Tree (..))
44

5-
-- Problem 54A: (*) Check whether a given term represents a binary tree.
6-
-- ANSWER: Creating an invalid tree is not possible in Haskell.
7-
85
{-
96
Problem 55: (**) Construct completely balanced binary trees.
107

src/BinaryTree/P64.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module BinaryTree.P64 where
1+
module BinaryTree.P64 (layout) where
22

33
import BinaryTree.BinaryTree (Tree (..))
44

src/List/P23.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module List.P23 where
1+
module List.P23 (rndSelect) where
22

33
import qualified Control.Monad as M
44
import Data.Functor ((<&>))

src/List/P27b.hs renamed to src/List/P27.hs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
module List.P27b where
1+
module List.P27 where
22

33
import Data.List ((\\))
44
import List.P26
55

6+
{-
7+
Problem 27a: (**) In how many ways can a group of 9 people
8+
work in 3 disjoint subgroups of 2, 3 and 4 persons?
9+
Write a function that generates all the possibilities
10+
and returns them in a list.
11+
-}
12+
group3 :: (Eq a) => [a] -> [[[a]]]
13+
group3 = group [2 .. 4]
14+
615
{-
716
Problem 27b: (**) In how many ways can a group of 9 people
817
work in disjoint subgroups of the given sizes?

src/List/P27a.hs

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/List/P28b.hs renamed to src/List/P28.hs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
module List.P28b where
1+
module List.P28 where
22

33
import qualified Data.List as L
44

5+
-- Problem 28a: (**) Sort the elements of this list according to their length;
6+
-- i.e short lists first, longer lists later.
7+
lsort :: [[a]] -> [[a]]
8+
lsort = L.sortOn length
9+
510
-- Problem 28b: (**) Sort the elements of this list according to their length frequency;
611
-- i.e., lists with rare lengths are placed first, others with a more frequent length come later.
712
lfsort :: [[a]] -> [[a]]

src/List/P28a.hs

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)