Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,207,951 members, 8,000,915 topics. Date: Tuesday, 12 November 2024 at 05:46 PM |
Nairaland Forum / Science/Technology / Programming / Trivia Coding Questions (euler Project) (10268 Views)
Learn Coding!!! Weekdays And Weekend / Are You A Programmer? Answer This NCT Coding Questions! / Naija Coder: Test Your Coding Skills Now (2) (3) (4)
(1) (2) (3) (4) (Reply) (Go Down)
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 3:26am On May 02, 2015 |
WhiZTiM: Thanks for reminding me of Sieve of Eratosthenes. That will work fine for the example test case but not for natural number that is as big as 600851475143, it wont work in java since the largest lenght of array or Set(and Set implementation) you can have is 2^31 (int precision) and Sieve of Eratosthenes reqires boolean flagging over such array. |
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 3:29am On May 02, 2015 |
WhiZTiM: Nice meeting you Bro 1 Like |
Re: Trivia Coding Questions (euler Project) by WhiZTiM(m): 3:48am On May 02, 2015 |
olyjosh: ...oh right... You guys don't have bitarrays in Java? ...Ouchhh ....Another optimization (rough thought) ... Its quite expensive, but you can split up the generation process. Generate them in chunks: then restart using higher values... First 30 primes, next 30 primes, next 30 primes... ...and so on.... so, after 90, for example. You can order this 90, and when a search for prime is needed, just do a binary search on this 90. (easier said than done, #haha) |
Re: Trivia Coding Questions (euler Project) by Nobody: 11:56am On May 02, 2015 |
kudaisi:in php function getSum($u){ for ($uu = 0 ; $uu < 1000 ; $uu++){ if ($uu % 3 === 0 || $uu % 5 === 0 ){ $u += $uu ; } } return $u } echo getSum(0) ; // 233168 |
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 3:59pm On May 02, 2015 |
WhiZTiM: Cool. I will tryimplementing this with DP. Haaaa, but I doubt if i understand most of this python Types and sytax correctly. |
Re: Trivia Coding Questions (euler Project) by WhiZTiM(m): 5:23pm On May 02, 2015 |
olyjosh:Nice... simple and elegant. We could do a little more better... ...requires more code though... Still a bit of a DP problem... My implementation (inefficient) works in about 11.78seconds On my PC, a 1.7Ghz CPU (Core i5 4210U). On an interesting note, I ported the implementation to Python... and its been running for the past 15 minutes! ...I am still yet to get an answer. . . ..lolz. ... ...Despite using C array type... I can only offer sympathy to what Ruby will be like.... ...ok, here's it http://ideone.com/6Iu0fJ (13.44 seconds) Edit: See the efficient version in my next comment https://www.nairaland.com/2286523/trivia-coding-questions-euler-project/1#33393053 |
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 12:44am On May 03, 2015 |
@WhiZTiM check this out Runs for 10seconds on 4gb RAM, 1.65GHz Duo Core processor
|
Re: Trivia Coding Questions (euler Project) by WhiZTiM(m): 12:54am On May 03, 2015 |
olyjosh: The division sequence.... A bit more clever solution! +1. |
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 9:07am On May 03, 2015 |
Jregz: Welcome to the show |
Re: Trivia Coding Questions (euler Project) by Nobody: 10:36am On May 03, 2015 |
olyjosh: wow you guys really rocks please any links to jazz up my algorithm skills. Might need to branch out from the business development and do some Maths related ish for 3D on Web my maths is abit bad. keep it up guys. |
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 10:53am On May 03, 2015 |
kudaisi:
Difference is 25164150 |
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 11:30am On May 03, 2015 |
kudaisi:
10001st prime number: 103575 I out for now - Gat exams to write tommorow. BRB After. |
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 12:34pm On May 03, 2015 |
Sorry I wish I could delete the above implementation, It's buggy, BRB when I fix it |
Re: Trivia Coding Questions (euler Project) by WhiZTiM(m): 11:12pm On May 03, 2015 |
olyjosh: Sieve of Eratosthenes is actually the best for this problem. A colleague of mine pointed that out to me. It works in 0.01 seconds on my PC. C++. Checkout: http://ideone.com/n0CVvD ... |
Re: Trivia Coding Questions (euler Project) by blueyedgeek(m): 12:00am On May 04, 2015 |
kudaisi:
|
Re: Trivia Coding Questions (euler Project) by blueyedgeek(m): 12:29am On May 04, 2015 |
kudaisi:
|
Re: Trivia Coding Questions (euler Project) by WhiZTiM(m): 1:47am On May 04, 2015 |
kudaisi: Python 2.7x >>> (50*(2+99))**2 - reduce(lambda x, y: x + y**2, range(101)) Ans: 25164150 One liner ...:-) .... The magic values to the left of the subtraction are from the AP series summation formula |
Re: Trivia Coding Questions (euler Project) by WhiZTiM(m): 1:47am On May 04, 2015 |
deleted! |
Re: Trivia Coding Questions (euler Project) by kudaisi(m): 9:44am On May 04, 2015 |
The sum of the squares of the first ten natural numbers is, (see image for inserts) The square of the sum of the first ten natural numbers is, (see image for inserts) Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640. Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
|
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 11:19am On May 04, 2015 |
blueyedgeek: Cool implementation bro. But the best approach to this isn't greedy approach. The sum arithmetic progression is what you can use in both case. These are formula you can easily derive using mathematical inductions. Sn = {n(1+n)}/2 Sum of squres in AP is = {n(n+1)(2*n+1)}/6 where one 1 can alway be the first term if your series does not start from 1 and n is the last term |
Re: Trivia Coding Questions (euler Project) by kudaisi(m): 12:03pm On May 04, 2015 |
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? |
Re: Trivia Coding Questions (euler Project) by kudaisi(m): 12:26pm On May 04, 2015 |
The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832. 73167176531330624919225119674426574742355349194934 96983520312774506326239578318016984801869478851843 85861560789112949495459501737958331952853208805511 12540698747158523863050715693290963295227443043557 66896648950445244523161731856403098711121722383113 62229893423380308135336276614282806444486645238749 30358907296290491560440772390713810515859307960866 70172427121883998797908792274921901699720888093776 65727333001053367881220235421809751254540594752243 52584907711670556013604839586446706324415722155397 53697817977846174064955149290862569321978468622482 83972241375657056057490261407972968652414535100474 82166370484403199890008895243450658541227588666881 16427171479924442928230863465674813919123162824586 17866458359124566529476545682848912883142607690042 24219022671055626321111109370544217506941658960408 07198403850962455444362981230987879927244284909188 84580156166097919133875499200524063689912560717606 05886116467109405077541002256983155200055935729725 71636269561882670428252483600823257530420752963450 Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product? |
Re: Trivia Coding Questions (euler Project) by Borwe: 2:47pm On May 04, 2015 |
kudaisi: What does this question mean LOL |
Re: Trivia Coding Questions (euler Project) by kudaisi(m): 4:29pm On May 04, 2015 |
Borwe:The set of numbers are part of single 1000-digit number. if you look through carefully, on the thirteenth row you'll notice a combination of 9989 together within the 1000-digit number and they have the greatest product because no other product (multiplication) of 4 adjacent digits(numbers that appear side by side) is greater that 5832. Now, your required to find 13 adjacent numbers with the highest product. Clear now ? |
Re: Trivia Coding Questions (euler Project) by kudaisi(m): 4:35pm On May 04, 2015 |
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, (see image for inserts) For example, (see image for inserts) There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc.
|
Re: Trivia Coding Questions (euler Project) by andreT(m): 6:38pm On May 04, 2015 |
python def pythagoras(limit): |
Re: Trivia Coding Questions (euler Project) by WhiZTiM(m): 7:04pm On May 04, 2015 |
kudaisi: Full, working program here: http://ideone.com/0S6NVj Largest value at index: 503 Sequence is: 9 x 7 x 8 x 1 x 7 x 9 x 7 x 7 x 8 x 4 x 6 x 1 x 7 = 2091059712 [s]Runtime: 0.000199762 seconds; Memory: 3.28MB[/s] |
Re: Trivia Coding Questions (euler Project) by WhiZTiM(m): 8:18pm On May 04, 2015 |
kudaisi: Here, a non-optimal solution... but it works http://ideone.com/qxpoTH http://ideone.com/upxEf2 Answer: 200, 375, 425; Product: 31875000 Runtime: 0.1 second Memory: 3.0MB Side Note: I initially implemented it in Python, but it ran for 2 minutes... :-) So, I was pretty sure that other than machine code, the C++ compiler will emit vectorized instructions.... and some other optimizations, loop unrolling... blah nlah blah.... |
Re: Trivia Coding Questions (euler Project) by WhiZTiM(m): 8:23pm On May 04, 2015 |
andreT: Now that is a perfect cubic runtime.... Don't do that!. .....at least in Python.... :-) ....(this is gonna run for minutes) PS: Don't take me too serious.... Ehmm... there should be known methods or algorithm that generates pythagorean triples... Google that.... ...implement it and woolala... it will run under a second. 1 Like |
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 12:18am On May 05, 2015 |
kudaisi:
product: 31875000 |
Re: Trivia Coding Questions (euler Project) by olyjosh(m): 2:20am On May 05, 2015 |
author=olyjosh post=33427863]
product: 31875000[/quote] Quite effective, check it out here http://ideone.com/Y3B3wP Runtime: 0seconds Memory; 0kb |
Re: Trivia Coding Questions (euler Project) by kudaisi(m): 9:31am On May 05, 2015 |
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. |
Which Is Recommended For IT Startup? Mikrotik Vs Cisco (MTCNA Vs CCNA) / How Good Is Software Engineering Study In India? / How To Become A Successful Programmer?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 64 |