Oxaric’s Blog

A compendium of amazing things…

Archive for the ‘Scheme’ Category

Euler Project Problem #97 Solution

Posted by oxaric on November 24, 2008

It uses Scheme.


Click to directly download euler-solution-97.sc

; filename 'euler-solution-97.sc'
; By: Louis Casillas, oxaric@gmail.com

; Euler Problem #97
; Find the last ten digits of the non-Mersenne prime: 28433 \u00d7 27830457 + 1.

(define (ToTheSecondPower n) 
        (* n n)
)

(define (Power x n)
        (if (= n 0)
            1
            (if (= (modulo n 2) 0)
                (ToTheSecondPower (Power (/ n 2)))
                (* (Power (- n 1)))
            )
        )
)

(+ (* (Power 2 7830457) 28433) 1)

Posted in Programming, Project Euler, Scheme | Tagged: , , , , , , | Leave a Comment »

Euler Project Problem #48 Solution

Posted by oxaric on November 24, 2008

It uses Scheme.


Click to directly download euler-solution-48.sc

; filename 'euler-solution-48.sc'
; By: Louis Casillas, oxaric@gmail.com

; Euler Problem #48
; Find the last 10 digits of the series: 1^1 + 2^2 + 3^3 ... + 1000^1000
  
(define (tothepower n count)
    (if (= count 0)
        1        
        (* (tothepower (- count 1)))
    )
)

(define (pow n)
    (if (= n 1)
        1
        (+ (tothepower n n) (pow (- n 1)))
    )
 )

(pow 1000)

Posted in Programming, Project Euler, Scheme | Tagged: , , , , , , | Leave a Comment »