Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem 9 [Language] #17

Open
jamiephillips0000 opened this issue Dec 12, 2014 · 4 comments
Open

Problem 9 [Language] #17

jamiephillips0000 opened this issue Dec 12, 2014 · 4 comments
Labels

Comments

@jamiephillips0000
Copy link

Hi Guys
Really had fun with Problem 9

def divider(nr : Int) ={ 2000 - (2_nr)}
def numerator(nr :Int) = {1000_1000 - (2000 * nr)}
def isPos(nr : Int) = {1000*1000 - (2000 * nr) > 0}
val res = (1 to 1000).filter(x => x< 1000 && isPos(x) && numerator(x) % divider(x)==0)

println (res(0) + " --" + res(1)  + " -- " + math.sqrt(res(0)*res(0) + res(1)*res(1)).toInt)

res(0) * res(1) * math.sqrt(res(0)*res(0) + res(1)*res(1)).toInt

One suggestion though - It would be nice to know the format in which the answer should be given e.g. i had to infer from the answer of @LucDupAtGitHub that the product of all three was required. i had the correct solution but was not sure of the format of the answer. This is not a criticism just a remark ;-)

@eloots
Copy link
Contributor

eloots commented Dec 12, 2014

Hi Jamie,

Indeed a fun problem to tackle !

As for the problem statement; indeed: it seems I forgot to add the last sentence to the problem description which is: Find the product abc

Sorry for that ;-) Of course, in case of doubt, there’s always the source at https://projecteuler.net/problems https://projecteuler.net/problems.

Regards, Eric

On 12-dec.-2014, at 09:42, Jamie Phillips notifications@github.com wrote:

Hi Guys
Really had fun with Problem 9

def divider(nr : Int) ={ 2000 - (2nr)}
def numerator(nr :Int) = {10001000 - (2000 * nr)}
def isPos(nr : Int) = {1000*1000 - (2000 * nr) > 0}
val res = (1 to 1000).filter(x => x< 1000 && isPos(x) && numerator(x) % divider(x)==0)

println (res(0) + " --" + res(1) + " -- " + math.sqrt(res(0)_res(0) + res(1)_res(1)).toInt)

res(0) * res(1) * math.sqrt(res(0)_res(0) + res(1)_res(1)).toInt
One suggestion though - It would be nice to know the format in which the answer should be given e.g. i had to infer from the answer of @LucDupAtGitHub https://github.com/LucDupAtGitHub that the product of all three was required. i had the correct solution but was not sure of the format of the answer. This is not a criticism just a remark ;-)


Reply to this email directly or view it on GitHub #17.

@eloots
Copy link
Contributor

eloots commented Dec 12, 2014

Jamie,

By the way; a related problem to this one is:

https://projecteuler.net/problem=39 <https://projecteuler.net/problem=39>

It’s not in the set of problems include in the repo.

You may want to have a crack at it. The core stuff you need is already there.

If you’d like to have it in included in the repo, let me know and I’ll add it.

Cheers, Eric

On 12-dec.-2014, at 09:42, Jamie Phillips notifications@github.com wrote:

Hi Guys
Really had fun with Problem 9

def divider(nr : Int) ={ 2000 - (2nr)}
def numerator(nr :Int) = {10001000 - (2000 * nr)}
def isPos(nr : Int) = {1000*1000 - (2000 * nr) > 0}
val res = (1 to 1000).filter(x => x< 1000 && isPos(x) && numerator(x) % divider(x)==0)

println (res(0) + " --" + res(1) + " -- " + math.sqrt(res(0)_res(0) + res(1)_res(1)).toInt)

res(0) * res(1) * math.sqrt(res(0)_res(0) + res(1)_res(1)).toInt
One suggestion though - It would be nice to know the format in which the answer should be given e.g. i had to infer from the answer of @LucDupAtGitHub https://github.com/LucDupAtGitHub that the product of all three was required. i had the correct solution but was not sure of the format of the answer. This is not a criticism just a remark ;-)


Reply to this email directly or view it on GitHub #17.

@mverbist
Copy link

mverbist commented Jan 9, 2015

And this is just using brute-force, without Erics tip:

      (for {
          a <- 1 to 999
          b <- a to 999
          c <- b to 999 filter (c1 => a + b + c1 == 1000 && a*a + b*b == c1*c1)
      } yield (a * b * c)).head

A triple for-comprehension with the condition as a filter on the third.
We yield the product, and then take the first we find.

@eloots eloots added the Language label Jan 9, 2015
@ghost
Copy link

ghost commented Jan 9, 2015

very nice, Michel!

On Fri, Jan 9, 2015 at 11:00 AM, Verbist Michel notifications@github.com
wrote:

And this is just using brute-force, without Erics tip:

  (for {
      a <- 1 to 999
      b <- a to 999
      c <- b to 999 filter (c1 => a + b + c1 == 1000 && a*a + b*b == c1*c1)
  } yield (a * b * c)).head

A triple for-comprehension with the condition as a filter on the third.
We yield the product, and then take the first we find.


Reply to this email directly or view it on GitHub
#17 (comment)
.

__~O
-\ <,
()/ ()

reality goes far beyond imagination

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants