Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: d7fcbfff0c
Fetching contributors…

Cannot retrieve contributors at this time

file 26 lines (24 sloc) 0.971 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#lang racket
(require "common.rkt")

(define (solve)
  (define (condense lst)
    (define (helper lst last seen)
      (cond [(empty? lst) (list (list last seen))]
            [(= (car lst) last) (helper (cdr lst) last (add1 seen))]
            [else (cons (list last seen) (helper (cdr lst) (car lst) 1))]))
    (helper lst (car lst) 0))
  (define (merge-factors a b)
    (cond [(and (empty? a) (empty? b)) '()]
          [(empty? a) b]
          [(empty? b) a]
          [(= (caar a) (caar b))
           (cons (list (caar a) (max (cadar a) (cadar b)))
                 (merge-factors (cdr a) (cdr b)))]
          [(< (caar a) (caar b))
           (cons (car a) (merge-factors (cdr a) b))]
          [else (cons (car b) (merge-factors a (cdr b)))]))
  (define (expand-out n)
    (foldr (lambda (x y) (* (expt (first x) (second x)) y)) 1 n))
  (expand-out (foldr merge-factors '()
                     (map condense (map prime-factor (range 1 20))))))

(provide solve)
Something went wrong with that request. Please try again.