Skip to main content
Golfed 18 bytes
Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Pip -rS, 7171 53 bytes

YRPg^sw:C`"\w+"`Wy~w.';.wY$`R$1$2.{IaNI@ZllPB[a0](lY@Zl@?a1)+:$2.$'RVSNbI+bNEb(ly0):{[_@1MS@_QaFIya]b}MUQ@Z V:yMUg^sRVSNl

Try it online!Try it online!

I'm gonna golf this some more before writing a thorough explanation. The basic idea:

  • Repr the input so it's one big string with the names areKeep a list of [name score] pairs in quotes but the numbers notl
  • Loop while there's a pair of names; replace every instancethrough the lines of input, split on spaces, using MU (for each line, the first name withitem is a and the second name in everything before the pairitem is b):
    • If a is not one of the names in l, append [a 0] to l
    • Add b to the score in l associated with the name a (if b is a name, this adds 0*)
    • If b is not a number, change the name a in l to b
  • Eval to turnOnce the string back into a list again
  • Do a bunch of mapping and filtering to extractloop is done, sort l in descending numerical order (since all the names are 0 in numeric context*, this sorts by the scores for each name; sort and print)

* Assuming that no names start with a digit, which I argue is the best Pip-specific interpretation of "whatever the input is, it won't be able to be parsed as a number."

Pip -rS, 71 bytes

YRPg^sw:C`"\w+"`Wy~w.';.wY$`R$1$2.:$2.$'RVSN:{[_@1MS@_QaFIya]}MUQ@Z V:y

Try it online!

I'm gonna golf this some more before writing a thorough explanation. The basic idea:

  • Repr the input so it's one big string with the names are in quotes but the numbers not
  • Loop while there's a pair of names; replace every instance of the first name with the second name in everything before the pair
  • Eval to turn the string back into a list again
  • Do a bunch of mapping and filtering to extract the scores for each name; sort and print

Pip -rS, 71 53 bytes

{IaNI@ZllPB[a0](lY@Zl@?a1)+:bI+bNEb(ly0):b}MUg^sRVSNl

Try it online!

I'm gonna golf this some more before writing a thorough explanation. The basic idea:

  • Keep a list of [name score] pairs in l
  • Loop through the lines of input, split on spaces, using MU (for each line, the first item is a and the second item is b):
    • If a is not one of the names in l, append [a 0] to l
    • Add b to the score in l associated with the name a (if b is a name, this adds 0*)
    • If b is not a number, change the name a in l to b
  • Once the loop is done, sort l in descending numerical order (since all the names are 0 in numeric context*, this sorts by the scores)

* Assuming that no names start with a digit, which I argue is the best Pip-specific interpretation of "whatever the input is, it won't be able to be parsed as a number."

Source Link
DLosc
  • 39.2k
  • 5
  • 83
  • 141

Pip -rS, 71 bytes

YRPg^sw:C`"\w+"`Wy~w.';.wY$`R$1$2.:$2.$'RVSN:{[_@1MS@_QaFIya]}MUQ@Z V:y

Try it online!

I'm gonna golf this some more before writing a thorough explanation. The basic idea:

  • Repr the input so it's one big string with the names are in quotes but the numbers not
  • Loop while there's a pair of names; replace every instance of the first name with the second name in everything before the pair
  • Eval to turn the string back into a list again
  • Do a bunch of mapping and filtering to extract the scores for each name; sort and print