Is my Rep in Stack-Exchange Form?

16

3

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

Veskah

Posted 2019-06-20T12:19:43.443

Reputation: 3 580

so what exactly does reputation do in the context of the challenge? – OrangeCherries – 2019-06-20T12:26:45.767

3@OrangeCherries Mechanically, nothing. It inspired the challenge because I had 1447 rep and 4 silvers, 17 bronzes at the time of writing. – Veskah – 2019-06-20T12:28:09.120

1Is the input flexible besides the order? So could I for example take an input-list [bronze, silver, gold] and a separated second input reputation? – Kevin Cruijssen – 2019-06-20T13:43:50.747

1@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. – Veskah – 2019-06-20T13:47:19.503

Are any truthy/falsy values allowed for output or does it have to be two consistent ones? – Nick Kennedy – 2019-06-20T14:39:55.203

@NickKennedy Two consistent values. (response now sans snark) – Veskah – 2019-06-20T14:48:57.273

It'd be nice to have an example that isn't just 1s and 0s, I thought the challenge dealt with binary until I read it through a few times. Maybe I'm just slow tho :) – Conor O'Brien – 2019-06-21T03:03:02.827

@ConorO'Brien But the first example is [1,2,3]? I changed the 2nd to [20,0,20] just so it's more clear at a glance – Veskah – 2019-06-21T12:06:29.647

@Veskah It is, but the other two examples were 1s and 0s. I was caught up on those lol – Conor O'Brien – 2019-06-21T22:42:41.470

Answers

11

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)

Kevin Cruijssen

Posted 2019-06-20T12:19:43.443

Reputation: 67 575

13L -> for -1. – Grimmy – 2019-06-21T10:53:58.173

1@Grimy Sometimes it's useful that lists are truncated to the smallest one. :) Thanks! – Kevin Cruijssen – 2019-06-21T10:57:09.447

This is 19 bytes in utf-8, not 10 bytes. – Lie Ryan – 2019-06-22T08:19:04.983

@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).

– Kevin Cruijssen – 2019-06-22T09:50:55.760

@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.

– Kevin Cruijssen – 2019-06-22T09:52:37.383

7

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!

Arnauld

Posted 2019-06-20T12:19:43.443

Reputation: 111 334

7

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!

OrangeCherries

Posted 2019-06-20T12:19:43.443

Reputation: 321

6

Ruby, 69 bytes

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

Try it online!

Value Ink

Posted 2019-06-20T12:19:43.443

Reputation: 10 608

5

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? 

Embodiment of Ignorance

Posted 2019-06-20T12:19:43.443

Reputation: 7 014

I've taken a few stabs at this from a couple of different angles but can't do better than 13 either. – Shaggy – 2019-06-21T22:38:06.557

@Shaggy Turns out the Å was unnecessary, since fn would get rid of the first value. Removing Å makes it 12 bytes – Embodiment of Ignorance – 2019-06-22T03:39:07.227

This is 16 bytes in utf-8, not 12 bytes. – Lie Ryan – 2019-06-22T08:21:19.167

@LieRyan Some golfing languages use their own encodings; Japt uses ISO-8859-1` – Embodiment of Ignorance – 2019-06-22T09:37:53.237

@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. – Shaggy – 2019-06-22T22:28:32.330

5

J, 38 34 31 bytes

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

Try it online!

Jonah

Posted 2019-06-20T12:19:43.443

Reputation: 8 729

4

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.

Neil

Posted 2019-06-20T12:19:43.443

Reputation: 95 035

4

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
        ""))))

Doorknob

Posted 2019-06-20T12:19:43.443

Reputation: 68 138

4

Jelly, 10 bytes

xJ$¹ƇV,Ṣ€E

Try it online!

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

Erik the Outgolfer

Posted 2019-06-20T12:19:43.443

Reputation: 38 134

This is 16 bytes in utf-8, not 10 bytes. – Lie Ryan – 2019-06-22T08:21:51.617

1

@LieRyan Jelly uses a custom code page.

– Erik the Outgolfer – 2019-06-22T09:55:58.320

2

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.

Neil

Posted 2019-06-20T12:19:43.443

Reputation: 95 035

This is 60 bytes in utf-8, not 24 bytes. – Lie Ryan – 2019-06-22T08:29:05.117

@LieRyan I didn't say they were UTF-8 bytes. – Neil – 2019-06-22T10:12:39.737

2

Jelly, 18 bytes

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

Try it online!

this is a bit bad

HyperNeutrino

Posted 2019-06-20T12:19:43.443

Reputation: 26 575

This is 37 bytes in utf-8, not 18 bytes. – Lie Ryan – 2019-06-22T08:22:23.437

@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. – HyperNeutrino – 2019-06-22T13:04:43.153

1

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.

Chas Brown

Posted 2019-06-20T12:19:43.443

Reputation: 8 959

1

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

Xcali

Posted 2019-06-20T12:19:43.443

Reputation: 7 671