16
\$\begingroup\$

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
\$\endgroup\$
  • \$\begingroup\$ so what exactly does reputation do in the context of the challenge? \$\endgroup\$ – OrangeCherries Jun 20 at 12:26
  • 3
    \$\begingroup\$ @OrangeCherries Mechanically, nothing. It inspired the challenge because I had 1447 rep and 4 silvers, 17 bronzes at the time of writing. \$\endgroup\$ – Veskah Jun 20 at 12:28
  • 1
    \$\begingroup\$ 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? \$\endgroup\$ – Kevin Cruijssen Jun 20 at 13:43
  • 1
    \$\begingroup\$ @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. \$\endgroup\$ – Veskah Jun 20 at 13:47
  • \$\begingroup\$ Are any truthy/falsy values allowed for output or does it have to be two consistent ones? \$\endgroup\$ – Nick Kennedy Jun 20 at 14:39

13 Answers 13

11
\$\begingroup\$

05AB1E, 16 14 13 11 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.

Try it online or verify all test cases.

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)
\$\endgroup\$
  • 1
    \$\begingroup\$ 3L -> for -1. \$\endgroup\$ – Grimy Jun 21 at 10:53
  • 1
    \$\begingroup\$ @Grimy Sometimes it's useful that lists are truncated to the smallest one. :) Thanks! \$\endgroup\$ – Kevin Cruijssen Jun 21 at 10:57
  • \$\begingroup\$ This is 19 bytes in utf-8, not 10 bytes. \$\endgroup\$ – Lie Ryan Jun 22 at 8:19
  • \$\begingroup\$ @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). \$\endgroup\$ – Kevin Cruijssen Jun 22 at 9:50
  • \$\begingroup\$ @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. \$\endgroup\$ – Kevin Cruijssen Jun 22 at 9:52
7
\$\begingroup\$

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!

\$\endgroup\$
7
\$\begingroup\$

MATL, 28 bytes 20 bytes 16 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!

\$\endgroup\$
6
\$\begingroup\$

Ruby, 69 bytes

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

Try it online!

\$\endgroup\$
5
\$\begingroup\$

J, 38 34 31 bytes

-:&(/:~)&":3 2 1;@#*#&.><@":"0 

Try it online!

\$\endgroup\$
5
\$\begingroup\$

Japt, 14 13 12 bytes

íp fn ¬á øUg

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

Try it or Verify all test cases

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? 
\$\endgroup\$
  • \$\begingroup\$ I've taken a few stabs at this from a couple of different angles but can't do better than 13 either. \$\endgroup\$ – Shaggy Jun 21 at 22:38
  • \$\begingroup\$ @Shaggy Turns out the Å was unnecessary, since fn would get rid of the first value. Removing Å makes it 12 bytes \$\endgroup\$ – Embodiment of Ignorance Jun 22 at 3:39
  • \$\begingroup\$ This is 16 bytes in utf-8, not 12 bytes. \$\endgroup\$ – Lie Ryan Jun 22 at 8:21
  • \$\begingroup\$ @LieRyan Some golfing languages use their own encodings; Japt uses ISO-8859-1` \$\endgroup\$ – Embodiment of Ignorance Jun 22 at 9:37
  • \$\begingroup\$ @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. \$\endgroup\$ – Shaggy Jun 22 at 22:28
4
\$\begingroup\$

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.

\$\endgroup\$
4
\$\begingroup\$

Jelly, 10 bytes

xJ$¹ƇV,Ṣ€E

Try it online!

Argument 1: [Bronze, Silver, Gold]
Argument 2: Rep

\$\endgroup\$
4
\$\begingroup\$

Racket, 149 107 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
        ""))))
\$\endgroup\$
2
\$\begingroup\$

Charcoal, 24 bytes

1F⁴F↨NχFι⊞υκFχ¿⁻№υι№θIι⎚

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.

F⁴F↨NχFι⊞υκ

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.

Fχ¿⁻№υι№θIι⎚

Check the count of each digit in the array matches that in the first input. If any differ, clear the canvas.

\$\endgroup\$
  • \$\begingroup\$ This is 60 bytes in utf-8, not 24 bytes. \$\endgroup\$ – Lie Ryan Jun 22 at 8:29
  • \$\begingroup\$ @LieRyan I didn't say they were UTF-8 bytes. \$\endgroup\$ – Neil Jun 22 at 10:12
2
\$\begingroup\$

Jelly, 18 bytes

DẋṠƊ€ẋ"3RU¤FṢ⁼⁴DṢ¤

Try it online!

this is a bit bad

\$\endgroup\$
  • \$\begingroup\$ This is 37 bytes in utf-8, not 18 bytes. \$\endgroup\$ – Lie Ryan Jun 22 at 8:22
  • \$\begingroup\$ @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. \$\endgroup\$ – HyperNeutrino Jun 22 at 13:04
1
\$\begingroup\$

Python 2, 80 79 77 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.

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.