Factorions: Difference between revisions
Content deleted Content added
SqrtNegInf (talk | contribs) Added Perl example |
+Racket |
||
Line 397: | Line 397: | ||
The factorions for base 12 are: |
The factorions for base 12 are: |
||
1 2 |
1 2 |
||
</pre> |
|||
=={{header|Racket}}== |
|||
{{trans|C}} |
|||
<lang racket>#lang racket |
|||
(define fact |
|||
(curry list-ref (for/fold ([result (list 1)] #:result (reverse result)) |
|||
([x (in-range 1 20)]) |
|||
(cons (* x (first result)) result)))) |
|||
(for ([b (in-range 9 13)]) |
|||
(printf "The factorions for base ~a are:\n" b) |
|||
(for ([i (in-range 1 1500000)]) |
|||
(let loop ([sum 0] [n i]) |
|||
(cond |
|||
[(positive? n) (loop (+ sum (fact (modulo n b))) (quotient n b))] |
|||
[(= sum i) (printf "~a " i)]))) |
|||
(newline))</lang> |
|||
{{out}} |
|||
<pre> |
|||
The factorions for base 9 are: |
|||
1 2 41282 |
|||
The factorions for base 10 are: |
|||
1 2 145 40585 |
|||
The factorions for base 11 are: |
|||
1 2 26 48 40472 |
|||
The factorions for base 12 are: |
|||
1 2 |
|||
</pre> |
</pre> |
||