Piet Souris

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

Recent posts by Piet Souris

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.
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.
6 days ago
It is time again for the brainteasers. Enjoy!
Can't think of anything useful, so your reduce looks fine, but beware of infinite streams
1 week ago
First thought: intstream iterate from size - 1 to 0, map to the list and limit 1
1 week ago
Fair enough, but I was concentrating on the 'MyInterface'. So the full story would then become
2 weeks 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);
2 weeks 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:
2 weeks ago
OP uses arr.stream(), and since arr is a List, that code will work    

For the sake of some (not very efficient) alternatives:
2 weeks ago
Nothing wrong with OPs code, even though you may not like it.

The only problem was (at least on my windows machine) that that user.dir thing gives a string with double backslashes. Adding the rest of the path with forwardslashes does not work. It takes a simple action to correct this.
1 month ago
And did you check the value of 'basePath' (if you are using Windows)?
1 month ago
And have you checked that the images are indeed where you think they are?
1 month ago