List Commands Library for 50g
|
08-06-2018, 05:59 PM
(This post was last modified: 08-06-2018 06:04 PM by pier4r.)
Post: #377
|
|||
|
|||
RE: List Commands Library for 50g
I don't know if what I am going to post belongs here or in the little explorations (n1). I post it here to raise the chance to get even more better commands. Read it as "I want commands that think for you!".
Let's expose the problem. Last week I played a cooperative board game, massive darkness. The game is not bad, although it may be too in favor of the players after level 3. The dice of the game, though, are not the common d6. They have elements that cannot be added to the others, therefore I wanted to know their distribution. For example pick the Yellow dice for attacks. It has: Blank 1 Sword 1 Sword 1 Sword 1 Sword 2 Swords / 1 Bam (n3) Of course I said "I can do it! Pen and paper and the sharp el506w and a bit of theory will not fail me". Of course they did not fail me, I failed myself once I tried to compute the distribution for 3 dice. Until 2 dice I got it right. As usual when I fail I resort to automation to save my situation. Good math people solve everything on their paper sheets, poor ones use their calculators. That's my motto (n2), but hey at least I get an answer! Thinking a bit how could I model quantities that cannot be added together, I ended up with a list of lists. So a yellow dice is modeled as follows Code:
I was relatively happy thinking I could roll the two dice, add the results, and then use the awesome LRPCT . LRPCT: it gets a list in input and the result are two sublists. The first with the elements of the list in input, without duplicates (well, it is not exactly that, see below), and the second list with the occurrences of the elements of the first list in the input list. But then I discovered it didn't work as the list in input should be sorted first, otherwise LRPCT doesn't achieve what I want. So I tried SORT or LSORT on the result list, result list being something like the list describing the yellow dice. Well both failed me (I also had no big expectations being my case an edge case), as for example the sublist { 2 1 0 } was sorted before { 2 0 0 } and then again {2 1 0} was listed. Therefore I couldn't use LRPCT. I was in total despair. What I did was a workaround. First getting the elements of the result list, without duplicates (it works), and then counting the occurrences of each element with LCNT (it works). Below there is the code. The interesting part is at the end. What I ask is: Could we have a LRPCT that does first LDDUP and then LCNT , to avoid sorting problems in the input list? If I would have used vectors instead of sublist, would it have worked? (I didn't test) Ok I tested, vectors are unsortable. Another point for a LRPCT where a LDDUP is done first and then LCNT. Code:
n1: http://www.hpmuseum.org/forum/thread-7955.html n2: of course if the problem is large, then good ones use their calculators, poor ones use a beefy computer. And so on. The point being: some people are efficient the others use brute force, if their approach is correct at all. n3: more here - https://www.reddit.com/r/MassiveDarkness...ributions/ Wikis are great, Contribute :) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 17 Guest(s)