#!/bin/sh
#|
exec csi -s "$0" "$@"
|#
(require-extension (only srfi-1 last unfold))
(import (chicken process-context)
(chicken format))
(define (Func num max)
(modulo
(last
(unfold (lambda (x) (> (* x (modulo x 10)) max))
(lambda (x) x)
(lambda (x) (+ x 1))
num)) 10))
(define (main args)
(handle-exceptions exn
(begin
(display "bad argument count")
(newline))
(format #t "N = ~a~%" (apply Func (map string->number args))))
0)
(cond-expand
(chicken-script
(main (command-line-arguments)))
(else))
IyEvYmluL3NoCiN8CmV4ZWMgY3NpIC1zICIkMCIgIiRAIgp8IwoKKHJlcXVpcmUtZXh0ZW5zaW9uIChvbmx5IHNyZmktMSBsYXN0IHVuZm9sZCkpCihpbXBvcnQgKGNoaWNrZW4gcHJvY2Vzcy1jb250ZXh0KQogICAgICAgIChjaGlja2VuIGZvcm1hdCkpCgooZGVmaW5lIChGdW5jIG51bSBtYXgpCiAgKG1vZHVsbwogICAobGFzdAogICAgKHVuZm9sZCAobGFtYmRhICh4KSAoPiAoKiB4IChtb2R1bG8geCAxMCkpIG1heCkpCiAgICAgICAgICAgIChsYW1iZGEgKHgpIHgpCiAgICAgICAgICAgIChsYW1iZGEgKHgpICgrIHggMSkpCiAgICAgICAgICAgIG51bSkpIDEwKSkKCihkZWZpbmUgKG1haW4gYXJncykKICAoaGFuZGxlLWV4Y2VwdGlvbnMgZXhuCiAgICAgIChiZWdpbgogICAgICAgIChkaXNwbGF5ICJiYWQgYXJndW1lbnQgY291bnQiKQogICAgICAgIChuZXdsaW5lKSkKICAgIChmb3JtYXQgI3QgIk4gPSB+YX4lIiAoYXBwbHkgRnVuYyAobWFwIHN0cmluZy0+bnVtYmVyIGFyZ3MpKSkpCiAgMCkKCihjb25kLWV4cGFuZAogIChjaGlja2VuLXNjcmlwdAogICAobWFpbiAoY29tbWFuZC1saW5lLWFyZ3VtZW50cykpKQogIChlbHNlKSkKCg==