Skip to content

Commit

Permalink
added usage comment for MAX constant. i switched between 1000 for tes…
Browse files Browse the repository at this point in the history
…ting, 40,000 for benchmarking. 195,100 to reach #5 on the leaderboard :)
  • Loading branch information
bosky101 committed Oct 7, 2012
1 parent ffaa14c commit 112ef6e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
13 changes: 12 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,18 @@ Write a code in whichever language you are comfortable with to print as many pri
// 40000 elapsed: 0.194436, by studying upper bounds of max prime factor (was 691 for 40,000)
// TODO: use log/exp/proportions to give a lower number for 40,000 , higher number for 1000

Written in xcode
/**
* How many primes are you trying to find. useful to target which spot you want
* to get on the leaderboard. Made it to #5 with the last commit
*
* For benchmarking flip to 40,000
* For testing, flip to http://primes.utm.edu/lists/small/1000.txt and compare last
* For making it to #5 on the leaderboard on http://hackerrank.com, flipped to 195100 :)
*/

See main.c for actual code. written on a mac, on a weekend dedicated to C/C++.

Found this puzzle on http://hackerrank.com ( this solution hit #5 in the leaderboard finding 195101 primes )

~B

14 changes: 10 additions & 4 deletions primes/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// main.c
// primes
// primes - a weekend c exercise
//
// NOTES
// 40,000 elapsed: 13.410259 by skipping even numbers
Expand All @@ -20,7 +20,15 @@
#include <stdlib.h>
#include <time.h>

#define MAX 1000
/**
* How many primes are you trying to find. useful to target which spot you want
* to get on the leaderboard. Made it to #5 with the last commit
*
* For benchmarking flip to 40,000
* For testing, flip to http://primes.utm.edu/lists/small/1000.txt and compare last
* For making it to #5 on the leaderboard on http://hackerrank.com, flipped to 195100 :)
*/
#define MAX 40000
int bitmap[MAX];
int _index=0;
int _max_factor=0;
Expand All @@ -34,8 +42,6 @@ isPrime(int m){
//printf("\n\tis %d %% %d = %d ? so %d is not prime",m,bitmap[i], m % bitmap[i], m / bitmap[i]);
_max_factor = (_max_factor<n)?n:_max_factor;
res=0;break;
}else{

}
if(n > MAX/10){
break;
Expand Down

0 comments on commit 112ef6e

Please sign in to comment.