# Is my Rep in Stack-Exchange Form?

## Premise:

Your reputation is in Stack-Exchange Form if it can be represented by decomposing your medal counts (gold, silver, and bronze counted separately) into their base-10 digits and joining them in any given order, with a few caveats.

While decomposing, each

• Gold medal digit is worth three digits.
• Silver is worth two digits.
• Bronze is one digit.
• Additionally, since SE does not display a medal type if you do not have any, a count of 0 medals for a type will not yield a [0].

Example:

• [1 Gold, 2 Silvers, 3 Bronzes] will decompose into [1,1,1,2,2,3]. 321112 and 213121 are two examples of an SE-form number for these medals.
• [20 Golds, 0 Silvers, 20 Bronzes] will decompose into [2,2,2,0,0,0,2,0]. 20002022 is an SE-form number.
• [11 Golds, 0 Silvers, 0 Bronzes] will decompose into [1,1,1,1,1,1]. 111111 is the only SE-form number for this.

There will be no leading 0's when considering a SE number. E.g., in the 2nd example above, 00002222 -> 2222 would not be considered a SE-form number for [20,0,20].

## Input/Output:

Input is a list/tuple/array/whatever of [reputation, gold_medals, silver_medals, bronze_medals] which are all non-negative integers. This is the assumed order but can be changed. Just make a note in your answer if you do.

Output is any two consistent values for true and false.

## Rules:

• Input will always be valid
• You will always have at least 1 Rep
• You can have no medals at all, which should always return false then.
• The medal counts have no bearing on reality. Having several hundred golds and no bronzes is fine.
• This is so shortest answer in bytes wins.

## Test Cases:

#[Rep, Gold, Silver, Bronze] -> Output
[4, 0, 0, 4]       -> True
[1447, 0, 4, 17]   -> True
[74414, 4, 0, 17]  -> True
[4444, 4, 0, 4]    -> True
[4455, 0, 54, 0]   -> True
[5355, 5, 0, 3]    -> True
[53535, 5, 3, 0]   -> True
[4444, 0, 0, 4444] -> True
[444, 4, 0, 0]     -> True
[1234, 0, 0, 1234] -> True
[1234, 0, 0, 4321] -> True

[4444, 1, 0, 1]      -> False
[5555, 5, 0, 55]     -> False
[1234, 1, 23, 4]     -> False
[1, 0, 0, 0]         -> False
[1001001, 0, 10, 10] -> False

• so what exactly does reputation do in the context of the challenge? Jun 20, 2019 at 12:26
• @OrangeCherries Mechanically, nothing. It inspired the challenge because I had 1447 rep and 4 silvers, 17 bronzes at the time of writing. Jun 20, 2019 at 12:28
• Is the input flexible besides the order? So could I for example take an input-list [bronze, silver, gold] and a separated second input reputation? Jun 20, 2019 at 13:43
• @KevinCruijssen Yeah that's fine. The only thing I'd say is disallowed is taking input as a list of lists of chars/digits that make up each number. Jun 20, 2019 at 13:47
• Are any truthy/falsy values allowed for output or does it have to be two consistent ones? Jun 20, 2019 at 14:39

# 05AB1E, 16141311 10 bytes

∞×0KJ‚€{íË


Takes the medals input in the order [bronze, silver, gold] as first input, and reputation as second input.

-1 byte thanks to @Grimy.

Explanation:

∞           # Push an infinite positive list: [1,2,3,...]
×          # Repeat the values in the (implicit) input-list that many times as string
# (since the input-list contains just 3 values, the rest of the infinite
#  list is ignored)
0K        # Remove all 0s (so all "0", "00" and "000")
J       # Join the strings in the list together
‚      # Pair this string with the (implicit) second input
€{í   # Sort the digits in both strings in descending order
Ë  # And check if both are now equal
# (after which the result is output implicitly as result)

• 3L -> ∞ for -1. Jun 21, 2019 at 10:53
• @Grimy Sometimes it's useful that lists are truncated to the smallest one. :) Thanks! Jun 21, 2019 at 10:57
• This is 19 bytes in utf-8, not 10 bytes. Jun 22, 2019 at 8:19
• @LieRyan You're correct, it's indeed 19 bytes in UTF-8. 05AB1E uses (just for example Jelly and Charcoal) a custom codepage, where every 256 characters it knows is encoded in 1 byte each. The bytes in this 10-byte version in hexadecimal are \x19\xd7\x30\x4b\x4a\x82\x80\x7b\xec\xcb: It should be possible to run these hexadecimal bytes with the --osabie flag, but I'm not sure how to do so in the 05AB1E Elixir version to be completely honest (but I will ask some others to verify and get back to you with the answer). Jun 22, 2019 at 9:50
• @LieRyan In the 05AB1E (legacy) Python version it could be done like this (it's a different program for another challenge of course), but it should give you the idea of how the hexadecimal bytes are run. Jun 22, 2019 at 9:52

# JavaScript (ES6),  92  74 bytes

Takes input as (['gold','silver','bronze'])('rep'). Returns a Boolean value.

b=>r=>[...b.map((n,i)=>n.repeat(+n&&3-i)).join].sort()+''==[...r].sort()


Try it online!

# JavaScript (ES6), 74 bytes

Takes input as (gold, silver, bronze, 'rep'). Returns a Boolean value.

(g,s,b,r)=>(F=s=>[...s].sort()+0)(r)==F([g,g,g,s,s,b].filter(x=>x).join)


Try it online!

# MATL, 28 bytes20 bytes16 bytes 13 bytes

Returns 0 for false and 1 for true. This can definitely be golfed down.

[1,3,2,1]Y"t2:7)XzVXzY@Ums0>


Down to 16 bytes if the reputation score can be taken in separately, and the order is [bronze, silver, gold], reputation
Down to 13 bytes thanks to Luis Mendo

3:Y"XzVXzY@Um


Try it online!

# J, 383431 20 bytes

-:&(\:~&.":)]#~#\.**


Try it online!

-11 bytes thanks to FrownyFrog!

• 20 bytes Apr 7, 2020 at 14:06
• well 19, since you can take the medals reversed. Apr 7, 2020 at 14:12
• That is a seriously nice golf. Tyvm! I especially like the use of &. to remove the spaces. Great trick. Apr 7, 2020 at 16:19

# Ruby, 69 bytes

->r,g,s,b{([g,g,g,s,s,b]-[0]).flat_map(&:digits).sort==r.digits.sort}


Try it online!

# Retina 0.8.2, 45 bytes

,0
,
,(\d*),(\d*),
¶$1$1$1$2$2 %O. ^(.+)¶\1$


Try it online! Link includes test suite. Explanation:

,0
,


Delete zero scores.

,(\d*),(\d*),
¶$1$1$1$2$2  Expand the gold and silver scores, and convert the separator to a newline. %O.  Sort the reputation and the expanded scores separately. ^(.+)¶\1$


Compare the sorted digits.

# Japt, 1413 12 bytes

íp fn ¬á øUg


Takes input as [rep, bronze, silver, gold]

Sample input: U = [1447, 17, 4, 0]
íp            Repeats each value of U by it's index amount e.g. ["","17","44","000"]
fn          Remove all falsy values when converted to a number e.g. ["17","44"]
¬         Concatenate e.g. "1744"
á        All permutations e.g. ["1744","1744","1474","1447","1474","1447","7144","7144","7414","7441","7414","7441","4174","4147","4714","4741","4417","4471","4174","4147","4714","4741","4417","4471"]
øUg     Does it contain the first item of the input?

• I've taken a few stabs at this from a couple of different angles but can't do better than 13 either. Jun 21, 2019 at 22:38
• @Shaggy Turns out the Å was unnecessary, since fn would get rid of the first value. Removing Å makes it 12 bytes Jun 22, 2019 at 3:39
• This is 16 bytes in utf-8, not 12 bytes. Jun 22, 2019 at 8:21
• @LieRyan Some golfing languages use their own encodings; Japt uses ISO-8859-1 Jun 22, 2019 at 9:37
• @EmbodimentofIgnorance, Ah, goddamnit, why didn't I spot that?! I really do feel so out of practice since I took that month off for my open bounty for Japt. Jun 22, 2019 at 22:28

## Racket, 149107 98 bytes

(λ(r b s g[h(λ x(sort(string->list(apply ~a(remq*'(0)x)))char<?))])(equal?(h r)(h b s s g g g)))


Try it online!

First time golfing in Racket, so still looking for improvements...

Explanation (of the original longer version, but same idea):

(λ(r b                              ; take rep and badges as arguments
[g(λ(x)                        ; helper function g which takes a string
(sort                      ; and returns the sorted
(string->list x)         ; list of characters
char<?))])               ; (sort by ascii code)
(equal?                           ; compare...
(g(~a r))                       ; g called on the rep converted to string
(g                              ; and g called on...
(string-join                  ; the concatenation of
(map ~a                     ; the stringified elements of
(append*               ; the flattened list given by
(filter              ; the elements of the following list where
(λ(x)(>(car x)0))  ; the badge count is nonzero:
(map make-list     ; repeat the badge counts
'(1 2 3)b)))) ; 1, 2, and 3 times respectively
""))))


# Jelly, 10 bytes

xJ$¹ƇV,Ṣ€E  Try it online! Argument 1: [Bronze, Silver, Gold] Argument 2: Rep • This is 16 bytes in utf-8, not 10 bytes. Jun 22, 2019 at 8:21 • @LieRyan Jelly uses a custom code page. Jun 22, 2019 at 9:55 # Charcoal, 24 bytes 1Ｆ⁴Ｆ↨ＮχＦι⊞υκＦχ¿⁻№υι№θＩι⎚  Try it online! Link is to verbose version of code. Takes input in the order rep, bronze, silver, gold and outputs 1 if the rep is valid. Explanation: 1  Assume the rep is valid. Ｆ⁴Ｆ↨ＮχＦι⊞υκ  Loop over the four input values. Push each digit of each value i times where i is the 0-indexed index of the value. Numeric base conversion is used here as that converts 0 to an empty array. Ｆχ¿⁻№υι№θＩι⎚  Check the count of each digit in the array matches that in the first input. If any differ, clear the canvas. • This is 60 bytes in utf-8, not 24 bytes. Jun 22, 2019 at 8:29 • @LieRyan I didn't say they were UTF-8 bytes. – Neil Jun 22, 2019 at 10:12 # Jelly, 18 bytes DẋṠƊ€ẋ"3RU¤FṢ⁼⁴DṢ¤  Try it online! this is a bit bad • This is 37 bytes in utf-8, not 18 bytes. Jun 22, 2019 at 8:22 • @LieRyan Jelly (and many other golfing languages) use their own code page such that all 256 1-byte codes correspond to one of the characters used by the language. Jun 22, 2019 at 13:04 # Python 2, 807977 68 bytes lambda r,g,s,b:S((g>0)*3*g+(s>0)*2*s+(b>0)*b)==S(r) S=sorted  Try it online! Takes input as rep, gold, silver, bronze. # Perl 5-lF, 62 bytes map{@r=sort/./g,@r if($_=<>x$_)>0}1..3;@F=sort@F;say"@r"eq"@F"  Try it online! Takes input on separate lines as reputation bronze silver gold  # Husk, 10 bytes €mdPfIṁdṘN  Try it online! Similar to the Japt answer. Takes [bronze,silver,gold] as first argument, rep as second argument. ## Explanation €mdPfIṁdṘN N natural numbers Ṙ repeat medals that many times ṁd get all their digits as a single array fI filter out zeroes P permutations md mapped to their base-10 numbers € is rep in the list?  # PowerShell, 66 69 bytes -3 bytes thanks to mazzy ''+($args|%{"$_"*$i++*!!$_}|% t*y|sort)-eq(''+$args[0]|% t*y|sort)


Try it online!

Takes input at (Rep, Bronze, Silver, Gold)

Figure I'll take a crack at my own question. Converts the numbers toCharArrays and sorts them. Appends an empty string so the sorted arrays are converted back to space-separated strings which can then be compared.

We handle 0 medal counts with !!\$_ which doubly negates the number, making it go non-zero number-> 0 -> 1 or 0 -> 1 -> 0 which is used to blank the repeat counter.

• you can remove second ''+. because Powershell implicitly brings the type of second operand to the type of first operand. Apr 4, 2020 at 22:43

# Wolfram Language (Mathematica), 69 68 bytes

i=IntegerDigits
Sort@i@#==Sort[Join@@i/@Select[{##2,##3,#4},#!=0&]]&


Defines an anonymous function; takes inputs to function as [reputation, bronze, silver, gold].

I think this method for repeating silver and gold is interesting (and unique among these answers): in an anonymous function, #n represents argument n and ##n represents a sequence of arguments from argument n to the end, so if one were to expand {##2,##3,#4}, it would become {#2,#3,#4,#3,#4,#4}`, which repeats each the necessary number of times while being 7 bytes less than the expanded form.