power_digit_sum.gsp 605 B

123456789101112131415161718
  1. (ns main
  2. "fmt"
  3. "strconv"
  4. "math/big"
  5. "github.com/jcla1/gisp/core")
  6. (def main (fn []
  7. (fmt/println "The sum of the digits of 2^1000 is:"
  8. (let [[two (big/new-int 2)]
  9. [thousand (big/new-int 1000)]
  10. [n (big/new-int 0)]]
  11. (n/exp two thousand nil)
  12. (loop [[acc 0.0]
  13. [s (n/string)]]
  14. (if (>= 0 (len s))
  15. (int acc)
  16. (let [[d _ (strconv/parse-int (assert string (get 0 1 s)) 10 0)]]
  17. (recur (+ acc (int d)) (assert string (get 1 -1 s))))))))))