Martin vs Dennis - Round 1: Who has more rep?
05AB1E, 65 64 bytes
Code:
•в=6{•5ôvy’ƒËŠˆ.‚‹º.ŒŒ/†š/ÿ’.w’„Ö="ˆ"’¡1èт£þ}})ZQā*O<“D M·‡“#è
Uses the 05AB1E encoding.
Explanation:
•в=6{•
converts the number в=6{
from base 255 to base 10, resulting in 1201208478. The first half being the ID of Dennis (12012) and the second half being the ID of Martin (8478). Split into pieces of 5 using 5ô
to get the following array:
['12012', '08478']
Luckily, we can leave the leading zero from Martin's ID, since this will still work (check the link before clicking to see the leading zero).
We now loop through this array using vy
and construct the following string from this 05AB1E code:
’ƒËŠˆ.‚‹º.ŒŒ/†š/ÿ’ --> codegolf.stackexchange.com/users/ÿ
Whereas ÿ
is the current element of the iterator (using string interpolation) Try it online!
After constructing the link, .w
reads all data from the link, resulting into a huge amount of text. To scrape the reputation from this, we need to split on the string title="reputation"
. Or in a more compressed version: ’„Ö="ˆ"’
. Split on this piece of string (with ¡
) and get the second element (with 1è
) and keep the first 100 characters (with т£
).
Now, our scraped text looks a bit like this:
>
139,883 <span class="label-uppercase">reputation</span>
</div>
<div class="ba
This part is easy, we just remove anything but digits to remain the reputation number, for which we have a builtin (þ
). We end the loop and wrap everything into an array }})
.
Finally, we can go on to processing the reputation numbers:
ZQā*O<“D M·‡“#è - On stack: an array in the format [Dennis rep, Martin rep]
Z # Get the maximum of the array
Q # Check for equality with the array
ā* # Multiply by it's index (1-indexed)
O< # Sum and decrement by 1
“D M·‡“# # Push the array ['D', 'M', 'tie']
è # Get the element on the index of the sum
Which results in either D
, M
or tie
.
PowerShell v3+, 147 123 119 103 101 96 Bytes
$a,$b=irm api.stackexchange.com/users/12012`;8478?site=codegolf|% I*|% r*n;$a-$b|% T*g "D;M;Tie"
Saved 24 bytes using true/false output instead of the names.
Saved another 4 by restructuring the final checks.
saved 16 by getting only the reputations of the two users from the request, saves having to use the |% r*n
more than once, also means we can get rid of like a million brackets, and two useless variables.
-2 thanks to TessellatingHeckler - using an escape char instead of two doublequotes for the url, also removed the @
from the array which was un-needed (oopsie)
used a weird .ToString
trick I never knew existed until now reccomended by TessellatingHeckler -5, and finally below 100.
Version which returns names:
$a,$b=irm "api.stackexchange.com/users/12012;8478?site=codegolf"|% I*
if(($c=$a|% r*n)-eq($d=$b|% r*n)){"tie"}else{@(($a|% d*),($b|% d*))[$c-lt$d]}
this looks pretty messy due to the shortening of parameter names.
anywhere |% r*n
appears we're getting the ReputatioN
, and |% d*
is the Display_name
uses Invoke-RestMethod
(alias irm
) to query the API, stores the result named Items
(gotten using |% I*
), into the two variables $a
& $b
, one for each pro golfer's, the ToString
(|% T*g
) trick results in one of the values D
,M
or Tie
if the number is odd/even/zero.
Python 2, 160 bytes
from requests import*
print cmp(*[get('http://api.stackexchange.com/users/12012;8478?%ssite=codegolf&filter=!9aK21rboZ'%s).text for s in'order=asc&',''])or'tie'
Not the shortest Python answer, but the shortest one so far that doesn't make any assumptions.
Prints 1
if Martin has more rep, -1
if I do.