Piet Souris

Saloon Keeper
+ Follow
since Mar 08, 2009
Forum Moderator
Piet Souris currently moderates these forums:
Netherlands
Cows and Likes
Cows
Total received
146
In last 30 days
18
Total given
85
Likes
Total received
628
Received in last 30 days
19
Total given
66
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Piet Souris

You're welcome!

And don't worry about the mrs: my experience is that they will accept that Euler thing, as long as the dishwashing and vacuumcleaning are still done in time. And, most important: do not forget the wedding anniversaries while doing Euler...
14 hours ago
hi Afke,

I did use my IDE intensively. When I came to an exercise I wasn't sure of, or I found it interesting enough, I opened my IDE, wrote my answers as comments upfront, an then I typed in the exercise. Quite laborious, but also quite exiting: would it give a compiler error, when I had predicted a Runtime error? Would it run normally? Well, I had given my answer first, so there was no cheating here. And typing in the exercise was also a good way to get the syntax under control. Well, it was pretty laborious as said, but I found it a very nice way to test myself.

And expecially with the Enthuware training: I learned a lot from it. Especially the second exam training was an eye opener for me: I failed that test with less than 59%. Shocking, and I figured that I needed another way to study. That's how I came to using the IDE.

Last thing I want to remark: in the end I paid extensively attention to the many trick questions, from Enthuware. I did this to train myself to recognize these trick questions as soon as possible.

Well, this is my experience. You can find my report on the OCAJP in the OCAJP wall of fame, it was in March 2017 (can't find the topic right now).

All the best for the next time, and we are all here to help you with all the questions you might have!
hi Brecht,

Yes, I can elaborate a little. As I wrote, I compare it to drawing from an urn filled with white and red balls. If I have 2 white and two red balls in the urn, then if I draw them, I could get say WRRW, meaning down-right-right-down. In other words, one such drawing is equivalent to a path. Now, the question is then: having 2 white and 2 red balls, hoe many sequences are there? Well, that is a well known formula from the Combinatorics. It is the Binomial Coefficient (4 over 2) = 4! / (2! * 2!) = 6.

Likewise, for a 20x20 grid, we would have 20 white and 20 red balls. I will stop now, since I do not want to reveal more details. But no doubt you can fill in the rest. I used a spreadsheet for this.
15 hours ago
hi DJ,

no, I don't hate Python,  I followed two courses 5 years ago, but classes were hardly used. And this self thing I always found confusing. But I did want to help, I was just reading some articles on the internet about classes in Python. It strikes me that in the definitions within the class, self is always used, but not when invoked. Another problem is that testing what you think is requiring a decent IDE. I've just downloaded PyCharm from JetBrains, now trying to find my way in it.

So, we do want to help, but in my case it's going to take some time! And this teacher of yours....
1 day ago
hi Brecht,

the way I did that exercise (and similar, more complicated, to follow), was to compare this exercise to drawing without replacement from an urn with white and red balls. A white ball was for going down, a red ball for going right. Now, how many red and white balls do you have here, and how many different ways are there to draw all these balls?
Is this useful for the general case?

Here's what I would do. First, determine where to start. I suppose you have a List A of all the Deals that must be processed, now make a second List B of all the Deals that are present in all the followdBy Lists of every Deal in List A. Then determine what Deals are in A that are not in the followdBy List B. Look at the removeAll-method of Lists for an easy way to do this. Normally, the resulting List of starting Deals will not be empty. But, life ain't that simple, decide what to do if you do find this starting list to be empty.

For this to work you must override the equals method in the Deal class. When are two Deals equal?

Now you can form, say, a Queue<Deal>, where you put the starting Deals in. Then, while the Queue is not empty, remove the head, execute it, put the follwedBy Deals into the Queue, and proceed until the Queue becomes empty.
1 day ago
hi Arwa,

a very nice way would be to use a Comparator<double[]>. For instance:

Then you can have something like:

You can use: comparator.reversed() if you want to sort it from high to low.

Warning: I have not tested this, so there might be a tiny error in it!
3 days ago
hi john,

your Comparator is not correct. Does it always hold that compare(o1, o2) == compare(o2, o1)?

And: your Comparator (when fixed) will put all the Healers at the back, but will leave the relative positions unchanged. So I would suggest that before you do the sorting, you first shuffle your list. See The Collections API.
3 days ago
hi Dave,

I'm not sure about this. It is true what you write, and I see the effect when I run the code. I did not know this. But if I look at the Java 8 documentation I am unable to find any of this documented (I do see it in the Java 10 API). So, it is probably something that was built into Java 9+. I have deleted my java 8, so can't test, but have a cow for your interesting remark.
hi Alfa,

okay.

I do not like the idea to use an instance of an Employee as indication in what order it should be processed, unless you can show me the real usecase. I must admit that I still do not understand how the real thing operates.

Suppose the rules are given in the form (x, y), meaning "x must be processed after y". It is a straightforward task to turn that into the list that I was talking about. If this list of Rules is a valid one, then there must be an y in this list of Rules that does not appear as x. For instance: if we have these Rules:

(3, 5), (5, 12), (2, 3)

then the x-list is {3, 5, 2} and the y-list is {5, 12, 3}.

As we see, 12 is the value in the y-list that does not appear lin the x-list, so that's our starting point. Now, look up the Rule that has 12 as y value. We find (5, 12). That means that 5 is our next "victim". Look up 5 as right element in the rules. We find the Rule (3, 5). So, 3 is next. And in the same fashion, we find 2 as our last number. So the processlist = {12, 5, 3, 2}. And then you can proceed in the way I described.

If all this is still not correct, then probably Norm is understanding your mission better than I do. Can you give an example of the original list, and what the external users do to this list (i. e. the rules), and when the moment arrives for you to do the processing? A small example would be fine.

1 week ago
For the last two or three weeks CodeRanch has been very unstable. Fetching a page takes quite some time, and every other fetch gives me a Time Out error, or similar.
And when replying to a post: if I do not submit a reply within say 10 seconds, then a submit requires me to log in again. It makes working with the site pretty unpleasat, I must say. Am I the only one?
1 week ago
I see. I apologize for having missed the last part of the JavaForum topic.

Well, sorting based on the index of an employee in the original list, or sorting based on a given id-order is equivalent qua complexity, but the second one seems more reliable, since the sorting then does not depend on some initial order of the list.

But if the user is able to supply a list of rules, like (1 after 2, 4 after 8, et ceera), then why not let the user give just one list like (8, 3, 7, 1, 0,...), to indicate that 3 comes after 8, 7 after 3, et cetera. That would be much less work and is much less errorprone.

Then you could have something like:
1 week ago
Thanks for the info, Norm.

That raises a couple of questions:

1) why is the discussion continued here at CodeRanch?
2) is there some usecase that makes all this a little comprehensible? First of all, the rules like "one comes after three" depends on some order of the list. and secondly, it is a very labourious way of doing. Three, the user must have full control over the Employee list, in order to invoke the method "processAfter()".

So, this seems unrealistic to me. Normally, you would have one or more fields in the Employee class, on which employees can be compared, for instance salary, function, department, service years, age, whatever. There must be a way to keep the employees up to date. Then all that the user needs to specify is on what field(s) the employees should be sorted.

If there IS a clear usecase, then please specify.

Since Norm is very involved in this, I will leave further replying to him, if that's okay.
1 week ago
I think so. But in oder for the function to do a correct sort, it must know these rules. Are the rules in question specified as shown in your first post? If not, how are these specified?
1 week ago