Very recently, I changed my SE username because I made this account some years ago and wanted to get back into asking questions. However, I’m still planning to post questions and potentially earn votes. We can imagine a site that has some issues dealing with name changes. The problem: given a list of names, reputation changes, and name changes, can you create a leaderboard of reputation? Assume everyone's reputation starts at 0.
Input comes in any reasonable format, and has two forms: a name change <String, String>
and a rep change <String, Number>
.
What does any reasonable format mean? When I write questions, it usually means the input can be rearranged or repackaged to work with the way your language takes in input (do you want a list of pairs? two lists? a string? that’s all fine) as long as it doesn’t add information or otherwise offload some of the computational work onto the human.
Name changes change a person’s username to any username not currently in use. For example, if A changes name to D, and B changes name to C, D (previously known as A) could still change their name to A or to B, even though these names have been used before. However, at any given moment the set of names are unique.
Rep changes represent something like getting up/down votes on a post, receiving a bounty, etc. All rep changes are guaranteed to be integers. They might come in the form <“Bob”, 5> or <“Alice”, -53000>. At the end, you must output all usernames that are currently in existence, and their rep counts, in descending order.
Test case:
Alice 5
Bob 7
Bob John
John 113
Alice Cheryl
Daniel 13
John Alice
Alice 12
Result:
Alice 132
Daniel 13
Cheryl 5
Test case, suggested by Unrelated String:
Jimmy Adam
Donald 12
Amelia -11
Result:
Donald 12
Adam 0
Amelia -11
Test case:
CodegoLfer65 12
Bluman 9
CodegoLfer65 n4me
n4me -3
Result:
Bluman 9
n4me 9 (note: these two can be in either order)
Usernames are composed of only [A-Za-z0-9], i.e. alphanumerics. However, the input will not be a number in your language. This means usernames like 144
, 015
, 0x0F
, 1e7
will not appear in the input. Numbers such as 1/3
, 2.8
do not appear due to the character specification in the first place.
This question seems heavy on data structures, so golfing languages may not perform as well. Maybe other languages will have a fighting chance? Scoring is by lowest number of bytes, i.e. tag:code-golf .
Bob 5, Bob John, Bob 10
. That should result inBob 10, John 5
, right? \$\endgroup\$Alice 1e4, Bob 0x123
. A few of the answers treat 1e4 as a number. \$\endgroup\$