This blog is an account of Jacob and Mike's (Skippy) cross-country trip to move Jacob from Chicago, IL to Irvine, CA. We decided we'd document the trip by making a blog post for every hundred miles we drove, in addition to anything else of interest. There is a map that I made with a thumb tack in each place where we wrote a blog post.

Thursday, May 31, 2007

Primal Ages or how to know when you and your girlfriend are a power couple

5:20PM CDT | N41°40'54" W92°58'54"

I mentioned to Jacob how this year the prime factors in my age are greater now than they were last year. I just celebrated my 2*13th birthday. Jacob then mentioned how he does these types of calculations all the time as well. Particularly that last year would be probably the only time when his ages would be a perfect cube and Molly's a perfect square. I graphed y=X^3-2 and y=X^2 on the laptop and they do indeed only intersect once.

Jacob then decided a more interesting question was when are his and Molly's ages both of the form X^Y and P^Q respectively where X,Y,P, and Q are integers and Y>1 and Q>1. I wrote a program to calculate this for all possible differences in ages so that our readers and their mates can know when to celebrate their own primeversaries.

(lib "")
(lib ""))

(define (factors n)
(let loop ([fact 2])
[(> fact n) '()]
[(zero? (modulo n fact))
(cons fact (loop (add1 fact)))]
[else (loop (add1 fact))])))

(list 'factors
(equal? (factors 2) '(2))
(equal? (factors 10) '(2 5 10))
(equal? (factors 27) '(3 9 27)))

(define (filter-for-prime lon)
[(null? lon) '()]
[else (cons (car lon)
(filter (lambda (x) (not (zero? (modulo x (car lon)))))

(define (has-one-prime-factor n)
(let ([prime-factors (filter-for-prime (factors n))])
(and (= 1 (length prime-factors))
(not (equal? n (car prime-factors))))))

(list 'has-one-prime-factor
(eq? (has-one-prime-factor 2) #t)
(eq? (has-one-prime-factor 27) #t)
(eq? (has-one-prime-factor 25) #t)
(eq? (has-one-prime-factor 10) #f))

(define *age-expectancy* 120)

(define ages-with-one-prime-factor
(let loop ([n 0])
(if (>= n *age-expectancy*)
(if (has-one-prime-factor n)
(cons n (loop (add1 n)))
(loop (add1 n))))))

(define (find-differences lon)
[(empty? lon) '()]
[else (append (map (lambda (x) (list (- x (car lon)) 'at (car lon) 'and x)) (cdr lon))
(find-differences (cdr lon)))]))

(find-differences ages-with-one-prime-factor)
(lambda (a b) (< (car a) (car b))))

1 comment:

Harpie said...

Skippy, you're either going to need to get a new girlfriend, or teach me math.