fork(1) download
  1. ; nines and zeros
  2.  
  3. (define (digits n . args)
  4. (let ((b (if (null? args) 10 (car args))))
  5. (let loop ((n n) (d '()))
  6. (if (zero? n) d
  7. (loop (quotient n b)
  8. (cons (modulo n b) d))))))
  9.  
  10. (define (undigits ds . args)
  11. (let ((b (if (null? args) 10 (car args))))
  12. (let loop ((ds ds) (n 0))
  13. (if (null? ds) n
  14. (loop (cdr ds) (+ (* n b) (car ds)))))))
  15.  
  16. (define (f n)
  17. (define (nine x) (if (= x 1) 9 x))
  18. (let loop ((i 1))
  19. (let ((x (undigits (map nine (digits i 2)))))
  20. (if (zero? (modulo x n)) x (loop (+ i 1))))))
  21.  
  22. (do ((n 1 (+ n 1))) ((< 100 n))
  23. (display n) (display #\tab)
  24. (display (f n)) (newline))
Success #stdin #stdout 1.79s 9208KB
stdin
Standard input is empty
stdout
1	9
2	90
3	9
4	900
5	90
6	90
7	9009
8	9000
9	9
10	90
11	99
12	900
13	9009
14	90090
15	90
16	90000
17	99909
18	90
19	99009
20	900
21	9009
22	990
23	990909
24	9000
25	900
26	90090
27	999
28	900900
29	9909909
30	90
31	999099
32	900000
33	99
34	999090
35	90090
36	900
37	999
38	990090
39	9009
40	9000
41	99999
42	90090
43	9909909
44	9900
45	90
46	9909090
47	90099
48	90000
49	9900009
50	900
51	99909
52	900900
53	900099
54	9990
55	990
56	9009000
57	99009
58	99099090
59	99099999
60	900
61	900909
62	9990990
63	9009
64	9000000
65	90090
66	990
67	9909099
68	9990900
69	990909
70	90090
71	90099
72	9000
73	90009
74	9990
75	900
76	9900900
77	9009
78	90090
79	90090099
80	90000
81	999999999
82	999990
83	909099
84	900900
85	999090
86	99099090
87	9909909
88	99000
89	99090909
90	90
91	9009
92	99090900
93	999099
94	900990
95	990090
96	900000
97	99900009
98	99000090
99	99
100	900