
SCJP
Visit my download page
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
SCJP
Visit my download page
Stephan van Hulst wrote:I'm going to try to solve the problems using the Haskell language, since I'd like to practice it a bit.
SCJP
Visit my download page
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
SCJP
Visit my download page
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Bert Bates wrote:It seems to me that if I'm going to keep doing this I'm going to need some utility stuff, e.g. it strikes me that a big old ArrayList filled with prime numbers is going to come in handy :smile:
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
It seems to me that if I'm going to keep doing this I'm going to need some utility stuff, e.g. it strikes me that a big old ArrayList filled with prime numbers is going to come in handy :smile:
SCJP
Visit my download page
SCJP
Visit my download page
Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Bert Bates wrote:It seems to me that if I'm going to keep doing this I'm going to need some utility stuff, e.g. it strikes me that a big old ArrayList filled with prime numbers is going to come in handy :smile:
Stephan van Hulst wrote:
Bert Bates wrote:It seems to me that if I'm going to keep doing this I'm going to need some utility stuff, e.g. it strikes me that a big old ArrayList filled with prime numbers is going to come in handy :smile:
Haha, actually I made a utility class called Primes which determines if an integer is a prime number, does prime factorization, and some other stuff, because I have the feeling I'm going to need them a lot
Matthew Brown wrote:Yeah, that won't cut it when you get onto some of the more computationally expensive questions. Mine uses a Sieve of Eratosthenes (either all in one if I know how high I need to go, or incremental if I don't). For problems where I have to work out if something is a prime number I generate them in advance and shove them in a HashSet for quick lookup.
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
fred rosenberger wrote:If the largest i've found is 19, i'd test 21 to see if it is divisible by 2, then 3, at which point i'd quit since 21%3 == 0.
then i'd test 23 to see if it is divisible by 2, then 3, then quit since 5*5 > 23. since 23 has no divisors, it must be prime.
Matthew Brown wrote:My incremental sieve works by looking at the next chunk of 100 numbers, and using the usual sieve technique using the prime numbers I've already generated.
As an example, let's say I was looking for the 60th prime number. I'd do a sieve on 1100. That gives me 25 prime numbers, so I know I need to keep going. So I look at 101200  but I just need to eliminate multiples of primes I've already found up to sqrt(200). I've now got 46 primes, so I look at the next 100. And so on, until I've got enough. So I'll (probably) generate more than I need, but not by much.
SCJP
Visit my download page
There are only two hard things in computer science: cache invalidation, naming things, and offbyone errors
SCJP
Visit my download page
fred rosenberger wrote:15 isn't too hard, once you know the secret. it is relatively simple calculation. I can give a hint, if you want...
Stephan van Hulst wrote:Since there has been some talk of prime numbers, I figured it'd be fun to make a fluent interface version of my Primes utility in Java.
static Iterable<Integer> greaterThan(int value)
Returns all prime numbers greater than or equal to a specified value.
Dennis Deems wrote:
static Iterable<Integer> greaterThan(int value)
Returns all prime numbers greater than or equal to a specified value.
How is this possible?
I am not young enough to know everything.  Oscar Wilde This tiny ad thinks it knows more than Oscar:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
