# Which side has more?

The challenge is to golf a program when given a string composed of any number of asterisks, then a comma, than any number of asterisks, say which side has more.

The asterisk-strings can be empty.

# Output

0 for ties.

1 for the left.

2 for the right.

# Examples

Input: ***,**** Output: 2

Input: ***, Output: 1

Input: ***,*** Output: 0

Input: , Output: 0

# Scoring

This is . Shortest answer wins.

• It seems this would be improved by loosening the output format—for example, allowing -1, 0, and 1 for the three possibilities, or really any three consistent outputs. Jun 8 '20 at 8:06
• I'm not sure that this is Ok at this stage (already 25 answers). Some of the existing answers (including my own) already made some effort to adhere to the originally-specified output format. Jun 8 '20 at 10:21
• @DominicvanEssen Alright, I will remove this option,
– nph
Jun 8 '20 at 10:22

# AWK-F,, 2422 20+3 = 23 bytes

$0=$2>$1?2:($1>$2)""  Try it online! Edit: amazingly, golfing-away 2 bytes has actually made it (a bit) more readable Commented version: $0=             # set the line to
$2>$1 ?     # if $2>$1 (alphabetic comparison)
2   # 2
:           # otherwise
($1>$2)   # logical: 1 for $1>$2, 0 if not
"" # append "" to force text output
# otherwise awk won't print zero

# use default behaviour to print line


# Befunge-93, 48 bytes

>~:1+!#v_","-!#v_1+
^ p 0 +$#99 "-"< +1_: #<.@.  Try it online! Adds one for each character it encounters, until it sees a ,; in that case, the program self modifies to start subtracting one for each character it encounters. After seeing the end of the string, it checks whether the tally is 0, less than 0, or something else, and prints 0, 2 or 1 accordingly. # R, 46 45 bytes (or 42 bytes using TRUE/FALSE instead of 1/0) d=scan(,'',,,',');if(d[2]>d,2,1-!d[2]<d[1])  Try it online! Edit: -1 byte thanks to Giuseppe • You can use ,, in place of se= (forcing R to use the argument order rather than the names) to save a byte. Might also be able to use a sign(diff(* lengths))%%3 like I've seen in other answers to golf off some bytes. Jun 8 '20 at 14:36 • Thanks for the ,,! Updated with acknowledgment... (again!) Jun 8 '20 at 15:32 • ...and you should post the other approach (which is much better than mine and beats it by at least 7 bytes)... Jun 8 '20 at 15:34 # SimpleTemplate, 66 bytes This was quite fun! Uses the most basic and naive approach, but the shortest one i can come up with as well. {@ifargv.0 is equalargv.1}0{@elseifargv.0 is lowerargv.1}2{@else}1  That's quite a mess, lets explore it: {@if argv.0 is equal to argv.1} {@echo 0} {@else if argv.0 is lower than argv.1} {@echo 2} {@else} {@echo 1} {@/}  Should be self-explanatory. A string is considered lower or higher depending on it's length and the characters on it are lower numerically (e.g.: b > a). To turn into a function, all it needs is that the {@echo} is converted to {@return}. Due to a bug (version 0.83), you can't return 0, but you can return "0". # R, 38 bytes sign(-diff(nchar(scan(,'',,,','))))%%3  Try it online! Credit to Dominic van Essen for the sep argument to scan(), which I probably use less often than I should. Ports the mod 3 approach found in a few other answers. # Golfscript, 22 bytes ','/).@).@;@>@@>2 0if+  Try it online! code | explanation | example ','/ | split input at ',' into list | "*,**" -> ["*", "**"] ). | uncons from the right and double | ["*", "**"] -> ["*"] "**" "**" @). | put list on tos and do it again | ["*"] "**" "**" -> "**" "**" [] "*" "*" @; | discard empty list | "**" "**" [] "*" "*" -> "**" "**" "*" "*" @> | pull up a "right" and compare | "**" "**" "*" "*" -> "**" "*" 0 @@ | pull up remaining elements | "**" "*" 0 -> 0 "**" "*" >2 0if | compare, if 1 replace with two | 0 "**" "*" -> 0 2 + | add the results | 0 2 -> 2  # Pyth, 16 bytes %_._h.+mldcQ","3  Try it online! • 12 bytes: Try it online! Jun 10 '20 at 22:14 # Python 3.8, 32 bytes lambda s:((r:=s[::-1])!=s)+(r<s)  Try it online! It is just one byte shorter than other Python 3.x lambda s:(s[::-1]!=s)+(s[::-1]<s)  # Charcoal, 18 bytes ⊞υθ⊞υ⮌θＩ⁻²↨⮌⌕Ａυ⌈υ²  Try it online! Link is to verbose version of code. Based on @JonathanAllen's answer. Explanation: ⊞υθ⊞υ⮌θ  Push the input and its reverse to the predefined empty list.  υ List of input and reverse ⌈ Take the maximum ⌕Ａυ Get the indices of that in the list ⮌ Reverse the list of indices ↨ ² Convert from base 2 ⁻² Subtract from 2 Ｉ Cast to string Implicitly print  When the input equals its reverse, both indices 0, 1 are returned, and 10 equals 2 in base 2, while if the left side has more then the maximum is at index 1, while if the right side has more then the maximum is at index 0. Subtracting this from 2 results in the desired value. # 05AB1E, 14 bytes [ÂQ#',¡ć@>,q}0  Try it online! A weird program method, I know, but hey, it works! The ÂQ part is from this answer regarding 05AB1E golfing tips # T-SQL, 43 bytes DECLARE @ varchar(max)='*,**' PRINT(3+sign(charindex(',',@)*2+~len(@)))%3  # Octave / MATLAB, 41 38 bytes @(x)mod(sign(2*find(x-42)-nnz(x)-1),3)  Try it online! # PowerShell, 59 bytes $a,$b=$i.split(',');if($a-gt$b){1}elseif($a-eq$b){0}else{2}


Try it online!

# Stax, 9 7 bytes

üJN☺ïS♂


Run and debug it

Unpacked:

',/E|\$3%


-2 bytes thanks to recursive

• You can omit {%m, as comparisons work on strings too. Jun 18 '20 at 23:41

# FEU, 30 26 bytes

Saved 4 bytes by using map instead of multiple substitutes

m/(\**),\1/0/\*+0/1/0\*+/2


Try it online!

## Explanation

m                          # Map mode, execute multiple substitutions
/(\**),\1/0               # Replaces the balance of the sides with 0
/\*+0/1        # If there are asterisks on the left of 0, replace with 1
/0\*+/2 # If there are asterisks on the right of 0, replace with 2
`