fork download
  1. (defun fibseq (length &optional (a0 0) (a1 1))
  2. (loop repeat length
  3. collect (shiftf a0 a1 (+ a0 a1))))
  4.  
  5. (defun remove-nth (n list)
  6. (if (eql n 0)
  7. (cdr list)
  8. (nconc (subseq list 0 n)
  9. (nthcdr (1+ n) list))))
  10.  
  11. (defun odai-pt8-617 (n s)
  12. (if (eql n 0)
  13. (list 0)
  14. (labels ((rec (s)
  15. (if (= (apply #'+ s) n)
  16. s
  17. (loop for i from (- (length s) 1) downto 0
  18. for a = (rec (remove-nth i s))
  19. when a
  20. do (return a)))))
  21. (rec s))))
  22.  
  23. (let ((seq (fibseq 42 1))
  24. (start 1)
  25. (end 1000))
  26. (loop for n from start to end
  27. do (format t "~D ---> ~{~D~^,~}~%" n (odai-pt8-617 n seq))))
  28.  
Time limit exceeded #stdin #stdout 5s 535040KB
stdin
Standard input is empty
stdout
1 ---> 1
2 ---> 1,1
3 ---> 1,2
4 ---> 1,1,2
5 ---> 1,1,3
6 ---> 1,2,3
7 ---> 1,1,2,3
8 ---> 1,2,5
9 ---> 1,1,2,5
10 ---> 1,1,3,5
11 ---> 1,2,3,5
12 ---> 1,1,2,3,5
13 ---> 1,1,3,8
14 ---> 1,2,3,8
15 ---> 1,1,2,3,8
16 ---> 1,2,5,8
17 ---> 1,1,2,5,8
18 ---> 1,1,3,5,8
19 ---> 1,2,3,5,8
20 ---> 1,1,2,3,5,8
21 ---> 1,2,5,13
22 ---> 1,1,2,5,13
23 ---> 1,1,3,5,13
24 ---> 1,2,3,5,13
25 ---> 1,1,2,3,5,13
26 ---> 1,1,3,8,13
27 ---> 1,2,3,8,13
28 ---> 1,1,2,3,8,13
29 ---> 1,2,5,8,13
30 ---> 1,1,2,5,8,13
31 ---> 1,1,3,5,8,13
32 ---> 1,2,3,5,8,13
33 ---> 1,1,2,3,5,8,13
34 ---> 1,1,3,8,21
35 ---> 1,2,3,8,21
36 ---> 1,1,2,3,8,21
37 ---> 1,2,5,8,21
38 ---> 1,1,2,5,8,21
39 ---> 1,1,3,5,8,21
40 ---> 1,2,3,5,8,21
41 ---> 1,1,2,3,5,8,21
42 ---> 1,2,5,13,21
43 ---> 1,1,2,5,13,21
44 ---> 1,1,3,5,13,21
45 ---> 1,2,3,5,13,21
46 ---> 1,1,2,3,5,13,21
47 ---> 1,1,3,8,13,21
48 ---> 1,2,3,8,13,21
49 ---> 1,1,2,3,8,13,21
50 ---> 1,2,5,8,13,21
51 ---> 1,1,2,5,8,13,21
52 ---> 1,1,3,5,8,13,21
53 ---> 1,2,3,5,8,13,21
54 ---> 1,1,2,3,5,8,13,21
55 ---> 1,2,5,13,34
56 ---> 1,1,2,5,13,34
57 ---> 1,1,3,5,13,34
58 ---> 1,2,3,5,13,34
59 ---> 1,1,2,3,5,13,34
60 ---> 1,1,3,8,13,34
61 ---> 1,2,3,8,13,34
62 ---> 1,1,2,3,8,13,34
63 ---> 1,2,5,8,13,34
64 ---> 1,1,2,5,8,13,34