Skip to content

Commit 47a9ef7

Browse files
committed
Add problems up to 1.26
1 parent 3de0d36 commit 47a9ef7

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

problems/lists.org

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,42 @@ Of course, your results will be random.
337337

338338
Hint: Use the built-in random number generator random.int/2 and the result of
339339
problem 1.20.
340+
341+
* 1.24 (*) Lotto: Draw N different random numbers from the set 1..M.
342+
343+
The selected numbers shall be put into a result list.
344+
Example:
345+
346+
#+begin_src teyjus-edit
347+
> lotto 6 49 L.
348+
349+
Success:
350+
L = [23,1,17,33,21,37]
351+
#+end_src
352+
353+
Hint: Combine the solutions of problems 1.22 and 1.23.
354+
355+
* 1.25 (*) Generate a random permutation of the elements of a list.
356+
357+
Example:
358+
#+begin_src teyjus-edit
359+
> rnd_permu [1,2,3,4,5,6] L.
360+
361+
Success:
362+
363+
L = [4,3,6,1,2,5]
364+
#+end_src
365+
366+
Hint: Use the solution of problem 1.23.
367+
368+
* 1.26 (**) Generate the combinations of K distinct objects chosen from the N elements of a list
369+
370+
In how many ways can a committee of 3 be chosen from a group of 12 people? We all know that there are C(12,3) = 220 possibilities (C(N,K) denotes the well-known binomial coefficients). For pure mathematicians, this result may be great. But we want to really generate all the possibilities (via backtracking).
371+
372+
Example:
373+
374+
> combination(3,[a,b,c,d,e,f],L).
375+
L = [a,b,c] ;
376+
L = [a,b,d] ;
377+
L = [a,b,e] ;
378+
...

solutions/lists.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,9 @@ select-rnd N Ls Xs :-
269269
) => select-rnd.aux 0 {len Ls} Ls []
270270
.
271271
272+
% TODO: 1.24
273+
% TODO: 1.25
274+
272275
}
273276
274277

0 commit comments

Comments
 (0)