Did you mention Haskell?
helper t = sum . (filter t ) . ((flip take) [1..])
sum35 = helper (n-> (n `mod` 3 == 0) || (n `mod` 5 == 0 ))
helper t n: take test(t) and now add all numbers satisfying t form the range 1..n
sum35 n: add all numbers form {k in [1..n]: 3|k or 5|k}
which can be written in Haskell as
sum35' n = sum [ k | k<-[1..n], (k `mod` 3 == 0) || (k `mod` 5 == 0 ) ]
;)
And a solution as general as yours
tt l = or . (map (k-> l `mod` k == 0))
sumT pr n = sum [ k | k<-[1..(n-1)], tt k pr ]
sum35 = sumT [3,5]
Well, it took me a few years, have like 6 books, but I never imagined it is so hard to learn this language (It's a bit more rigorous than M381).
ps.
(bellow 1000)
sum35 1000 = 233168
Sorry to butt in here but isn't the aim of M381 a basic introduction to mathematical logic and number theory with a first crack at Godel's theoerm. Why should that have anything to do with learining an obscure programming language. I guess I don't understand the claim it's like comparing apples with oranges.
If you were to claim that M381 is not as rigorous as other comparable courses in Logic and Number theory such as say Cambridge you would have a point, unfortunately we are stuck with what we can get and as far as I know the OU is the only place where you can do a distance course in mathematical logic or will be until October 2012.
The past presentations of M381 were using Turing machines, this one is using Unlimited Register Machines... Haskell is using lamnda calcus(which is only mentioned in units) but all of them are equivalent(thus one could express all theorems in it)
When one needs to write some advanced stuff(say use monads) one needs to understend a great deal about composing functions and groups ;)
Classes in haskell are like a promise what given object can do... and it type is infered by rules very simmilar to fomal prof units.
Haskell is not an obscure language it is used among others uses to develop new conceps in Computer Science... Java has bits from it, New perl has only implementation in it.
the main compiler is called Glasgow Haskell Compiler ghc
Yes, I needed a break from revising too .. and owed Chris a reply to his post in First Class, Maths & Comp Chat.
I've played with Project Euler in the past using Haskell. Firing up the Hugs interpreter is very quick and easy. Solved 16 problems so far but haven't had time to play with it since starting OU studies.
Σi=1[999/3] 3i + Σi=1[999/5] 5i - Σi=1[999/15] 15i
= 3Σi=1[999/3] i + 5Σi=1[999/5] i - 15Σi=1[999/15] i =
= (zum 999 3) + (zum 999 5) - (zum 99 15)
where
zum k m = m ((1+k')k') `div` 2
where k' = k `div` m --??
Comments
New comment
Did you mention Haskell? helper t = sum . (filter t ) . ((flip take) [1..]) sum35 = helper (n-> (n `mod` 3 == 0) || (n `mod` 5 == 0 )) helper t n: take test(t) and now add all numbers satisfying t form the range 1..n sum35 n: add all numbers form {k in [1..n]: 3|k or 5|k} which can be written in Haskell as sum35' n = sum [ k | k<-[1..n], (k `mod` 3 == 0) || (k `mod` 5 == 0 ) ] ;)New comment
Marcyn
Haskell it is!! I want to be able to do that.
Ta. And Ta, for all your posts/responses. Good luck with the exam.
arb
neil
New comment
And a solution as general as yours tt l = or . (map (k-> l `mod` k == 0)) sumT pr n = sum [ k | k<-[1..(n-1)], tt k pr ] sum35 = sumT [3,5] Well, it took me a few years, have like 6 books, but I never imagined it is so hard to learn this language (It's a bit more rigorous than M381). ps. (bellow 1000) sum35 1000 = 233168New comment
(It's a bit more rigorous than M381). !!!
New comment
Sorry to butt in here but isn't the aim of M381 a basic introduction to mathematical logic and number theory with a first crack at Godel's theoerm. Why should that have anything to do with learining an obscure programming language. I guess I don't understand the claim it's like comparing apples with oranges.
If you were to claim that M381 is not as rigorous as other comparable courses in Logic and Number theory such as say Cambridge you would have a point, unfortunately we are stuck with what we can get and as far as I know the OU is the only place where you can do a distance course in mathematical logic or will be until October 2012.
New comment
The past presentations of M381 were using Turing machines, this one is using Unlimited Register Machines... Haskell is using lamnda calcus(which is only mentioned in units) but all of them are equivalent(thus one could express all theorems in it) When one needs to write some advanced stuff(say use monads) one needs to understend a great deal about composing functions and groups ;) Classes in haskell are like a promise what given object can do... and it type is infered by rules very simmilar to fomal prof units. Haskell is not an obscure language it is used among others uses to develop new conceps in Computer Science... Java has bits from it, New perl has only implementation in it. the main compiler is called Glasgow Haskell Compiler ghcNew comment
Yes, computing is number theory, but number theory doesn't have to be computing.New comment
Hi Neil,
Yes, I needed a break from revising too .. and owed Chris a reply to his post in First Class, Maths & Comp Chat.
I've played with Project Euler in the past using Haskell. Firing up the Hugs interpreter is very quick and easy. Solved 16 problems so far but haven't had time to play with it since starting OU studies.
For this problem, try
Σi=1[999/3] 3i + Σi=1[999/5] 5i - Σi=1[999/15] 15i
Runs in O(1) and no recursive functions required, though I'm sure you had fun writing them.
cheers, Phil
New comment
Hi Phil
Brilliant! Just brilliant. I'll play around with this soon.
Good luck for Thursday.
arb
neil
New comment
Σi=1[999/3] 3i + Σi=1[999/5] 5i - Σi=1[999/15] 15i = 3Σi=1[999/3] i + 5Σi=1[999/5] i - 15Σi=1[999/15] i = = (zum 999 3) + (zum 999 5) - (zum 99 15) where zum k m = m ((1+k')k') `div` 2 where k' = k `div` m --??