Piet Souris

Bartender
+ Follow
since Mar 08, 2009
Merit badge: grant badges
Forum Moderator
Piet Souris currently moderates these forums:
For More
Netherlands
Cows and Likes
Cows
Total received
212
In last 30 days
0
Total given
152
Likes
Total received
1217
Received in last 30 days
0
Total given
191
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Piet Souris

I put some println's in your code, so that you can see what's going on:
3 weeks ago
@Mohammed

in your opening post you wrote:

This is very likely not the annual payment.
1 month ago
Also a nice one is:
2 months ago
Here is an example of what I described. It is a very rough version, though
Day 2 was straightforward, with the only problem (well, problem) to make something nice out of the input. Day 1B was not fully specified: should "twone" give us 22, 21 or 11? I took 21 and that worked.
3 months ago
Well, my first thoughts would be:

1) determine the size of your equilateral triangle, say W and H.

2) create the triangle as a Path2D.Double, with coordinates (W/2, 0), (0, H), (W, H) and close it.

3) create a BufferedImage buf, type INT_ARGB, with width W and height H

4) get its g2d, set the triangle as clip and draw all the colours and shapes to it that you want.

5) create the main BufferedImage mainBuf, with height 2*H, and sufficient width. We now draw 6 times buf to its g2d, the first one at (0, H), then rotate mainBuf PI/3 around its center (as Tim said, there are methods in the g2d that make this possible) and draw buf again, at (), H). By doing this six times, mainBuf has now 6 copies of the triangle, all neatly rotated around mainBuf's center.

6) draw mainBuf in your JPanel

7) global health warning: I typed this out of my head, and therefore there are no guarantees! If it doesn't work like I had in mind, let us know what problem you emcountered.
If you have a Graphics2D (for instance from a BufferedImage) you can give it a clip (see the api) and that clip can be any shape, like a triangle. Anyrhing you draw in that G2D will be clipped inside that shape.
Brilliant, Mike, have a cow! Never worked with spliterators, but this is a good starting place.
3 months ago
It is time again for the brainteasers. Enjoy!
3 months ago
Can't think of anything useful, so your reduce looks fine, but beware of infinite streams
3 months ago
First thought: intstream iterate from size - 1 to 0, map to the list and limit 1
3 months ago
Fair enough, but I was concentrating on the 'MyInterface'. So the full story would then become
3 months ago

Campbell Ritchie wrote:Nice, Piet, but please explain a bit more in case OP isn's familiar with a Collector like “all Gaul,” “divided into three parts.”


OP posted another topic about how to get a frequency table, where OP got some clear answers. So if he (or she) likes an explanation, then (s)he can ask for it.

Campbell Ritchie wrote:Would you have any  misgivings about precision if you are doing multiple floating‑point additions?


Yes indeed, But it is sufficient to get the first four decimals oke.

My intention was to draw attention to some other possibilities: merge and summingInt (or here: Double);
3 months ago
There are a few problems with your code.

First of all, lets simplify the code a little. In your main method, start with

and then you must do:

Second problem is that your List is a List of Objects, and so you get an error, because your interface expects a String to be printed, but instead it gets an Object. In Carey's snippet you see that he uses a List<String>, to remedy this problem.

Third problem is that you define a String as parameter in the display-method of your interface. So if you have a List of, say, Integers, the above will not work. So you could have your interface to be

and then do

and do:

or with a method reference:
3 months ago
OP uses arr.stream(), and since arr is a List, that code will work    

For the sake of some (not very efficient) alternatives:
3 months ago