since Mar 08, 2009

Forum Moderator

Piet Souris currently moderates these forums:

Netherlands

Cows and Likes

Cows

Total received

163

In last 30 days

2

Total given

117

Likes

Total received

937

Received in last 30 days

11

Total given

114

Given in last 30 days

2

Forums and Threads

Scavenger Hunt

Rancher Scavenger Hunt

Ranch Hand Scavenger Hunt

Greenhorn Scavenger Hunt

I think that it has to do with boxing: an Integer can be boxed to a double, but not to a Double. And my terminology may be wrong...

18 hours ago

A big problem with your code is that you do not store the calculated primes. Are you familiar with Lists? If so, I would change the method 'public static void printPrimeFactors(int num)' to

Inside this method, you create a List like: List<Integer> primes = new ArrayList<>();

and for every i that you now print, just add that i to primes. In the end, return primes.

In main, you invoke that method with

and then you can print out this list.

If you also know about Sets, then an easy way to eliminate duplicates is:

And, by the way: if you have this List of primes for a certain number N, and the size of that List is 1, what does that say about N?

Inside this method, you create a List like: List<Integer> primes = new ArrayList<>();

and for every i that you now print, just add that i to primes. In the end, return primes.

In main, you invoke that method with

and then you can print out this list.

If you also know about Sets, then an easy way to eliminate duplicates is:

And, by the way: if you have this List of primes for a certain number N, and the size of that List is 1, what does that say about N?

19 hours ago

hi Sharwan,

welcome to the Ranch and enjoy the stay!

Do you mean the book in the title ("Math for programmers")? If so, I will transfer your question to a separate topic, so that you have a chance to win a copy of the book.

welcome to the Ranch and enjoy the stay!

Do you mean the book in the title ("Math for programmers")? If so, I will transfer your question to a separate topic, so that you have a chance to win a copy of the book.

4 days ago

Campbell Ritchie wrote:

Short, but good. I shall have to win that book; then I can have two copies.Piet Souris wrote:. . . Paul Orland gives a very short solution. . . .

Ho ho, I was first!!

4 days ago

it is the book "Learning Java with Math", and I think it was the bookpresentation second half 2019.

4 days ago

See this link (click here) where Paul Orland gives a very short solution.

Myself, I use a Map where the key is an integer, and the value is a List of all subsets of that length. That is how I implemented Paul Claphams algo.

Myself, I use a Map where the key is an integer, and the value is a List of all subsets of that length. That is how I implemented Paul Claphams algo.

4 days ago

hi Paul,

some time ago I "won" a book about math here, but that book was very basic indeed. What would you say is your most advanced topic of your book?

some time ago I "won" a book about math here, but that book was very basic indeed. What would you say is your most advanced topic of your book?

4 days ago

hi Paul,

it is always amazing how short these python codes are, given one is used to java!

I use a Map<Integer, List<List<Integer>>> where the key is the length of the lists in the value, and I fill it using recursion, although that is not required. You could start with key = 0.

To make it generic, I have a method that sees all the integers in the map as indices into some List<T>.

But the code is a "few" lines longer than yours...

it is always amazing how short these python codes are, given one is used to java!

I use a Map<Integer, List<List<Integer>>> where the key is the length of the lists in the value, and I fill it using recursion, although that is not required. You could start with key = 0.

To make it generic, I have a method that sees all the integers in the map as indices into some List<T>.

But the code is a "few" lines longer than yours...

4 days ago

hi JJ,

yes, that is it. My style is like yours, only I use static imports as much as I can to reduce typing and to make the code a bit shorter. So I would write:

Have you thought about part b?

yes, that is it. My style is like yours, only I use static imports as much as I can to reduce typing and to make the code a bit shorter. So I would write:

Have you thought about part b?

4 days ago

In this topic (ArrayList-Table-Sum) two methods were given to determine the sum per state.

But to judge what state performed best, it is more honest to determine the average time per state. Can you do that a) by modifying Campbells method and b) by using another method than map.merge? (It should still be a one-liner).

But to judge what state performed best, it is more honest to determine the average time per state. Can you do that a) by modifying Campbells method and b) by using another method than map.merge? (It should still be a one-liner).

4 days ago

Just had a look at that topic. It is unclear what OP wants: het starts off with having a Set and getting all possible combinations from it. and ends with two sets of which he wants a Cartesian product. The first is simply drawing from a Set with replacement and getting all possibilities when drawing 0, 1, 2, ... times. Paul mentiones a name, never knew that that had a name.

4 days ago

You should go one level deeper:

4 days ago