Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,21 @@
#lang racket
(provide hailstone)
(define hailstone
(let ([t (make-hasheq)])
(hash-set! t 1 '(1))
(λ(n) (hash-ref! t n
(λ() (cons n (hailstone (if (even? n) (/ n 2) (+ (* 3 n) 1)))))))))
(module+ main
(define h27 (hailstone 27))
(printf "h(27) = ~s, ~s items\n"
`(,@(take h27 4) ... ,@(take-right h27 4))
(length h27))
(define N 100000)
(define longest
(for/fold ([m #f]) ([i (in-range 1 (add1 N))])
(define h (hailstone i))
(if (and m (> (cdr m) (length h))) m (cons i (length h)))))
(printf "for x<=~s, ~s has the longest sequence with ~s items\n"
N (car longest) (cdr longest)))

View file

@ -0,0 +1,12 @@
#lang racket
(require "hs.rkt")
(define N 100000)
(define t (make-hasheq))
(define best
(for/fold ([best #f]) ([i (in-range 1 (add1 N))])
(define len (length (hailstone i)))
(define freq (add1 (hash-ref t len 0)))
(hash-set! t len freq)
(if (and best (> (car best) freq)) best (cons freq len))))
(printf "Most frequent sequence length for x<=~s: ~s, appearing ~s times\n" N
(cdr best) (car best))