| Bytes | Lang | Time | Link |
|---|---|---|---|
| nan | AWK | 250303T182908Z | xrs |
| nan | Perl 5 plF | 250303T184539Z | Xcali |
| nan | Forth gforth | 240730T150755Z | reffu |
| nan | Uiua | 240730T121032Z | Europe20 |
| nan | Thunno 2 GB | 230720T084337Z | The Thon |
| nan | Vyxal 2.4.1 K | 230720T113843Z | lyxal |
| nan | Nekomata | 230720T103252Z | alephalp |
| nan | Raku Perl 6 rakudo | 230720T074215Z | bb94 |
| nan | PowerShell | 230604T184855Z | James Fl |
| nan | Arturo | 230604T181146Z | chunes |
| nan | C clang | 221128T194236Z | c-- |
| nan | Wolfram Language Mathematica | 230406T001454Z | 138 Aspe |
| nan | Python 3 | 230405T193320Z | Creative |
| nan | Vyxal | 221128T195648Z | naffetS |
| nan | Go | 230330T180048Z | bigyihsu |
| nan | Stax | 230310T185714Z | emirps |
| nan | MATL | 230310T194437Z | beaker |
| nan | KamilaLisp v0.2 | 230310T194222Z | Kamila S |
| 143 | Lua | 230309T200720Z | emirps |
| 106 | Java 8 | 230210T181616Z | Fhuvi |
| 008 | GolfScript | 230209T202428Z | emirps |
| nan | Python 3 | 221219T120029Z | U13-Forw |
| nan | APL | 221130T195302Z | Mark Ree |
| nan | PHP | 221130T163343Z | Kaddath |
| 9818 | C# Visual C# Interactive Compiler | 221129T172446Z | TheLetha |
| nan | Factor | 221130T060219Z | chunes |
| nan | K ngn/k | 221130T022212Z | doug |
| 039 | Alumin | 221129T212746Z | Conor O& |
| nan | Burlesque | 221130T002258Z | DeathInc |
| nan | Pyth | 221129T205534Z | isaacg |
| 033 | Perl 5 plF'' | 221129T121043Z | Kjetil S |
| 048 | Excel | 221128T213601Z | jdt |
| nan | Java 8 | 221129T144436Z | Kevin Cr |
| 035 | Charcoal v | 221128T190231Z | Neil |
| 7016 | J | 221129T095715Z | m90 |
| 025 | Raku | 221129T133444Z | hkdtam |
| nan | Julia | 221129T140001Z | Kirill L |
| 3850 | Nibbles | 221128T210024Z | Dominic |
| nan | ><> | 221129T095249Z | Emigna |
| nan | Ly | 221129T104340Z | cnamejj |
| nan | JavaScript Node.js | 221129T095122Z | Arnauld |
| 006 | MathGolf | 221129T090517Z | Kevin Cr |
| 1244 | 05AB1E | 221129T084711Z | Kevin Cr |
| nan | Husk | 221129T083758Z | Dominic |
| nan | R | 221129T072823Z | pajonk |
| nan | J | 221129T013647Z | south |
| 019 | q | 221129T003637Z | cillianr |
| nan | Juby | 221129T000306Z | Jordan |
| nan | Terse | 221128T231516Z | Gymhgy |
| nan | Haskell | 221128T212409Z | corvus_1 |
| nan | Bash + GNU utilities | 221128T202447Z | Digital |
| nan | Ruby | 221128T184650Z | Jordan |
| 050 | Octave | 221128T195447Z | Luis Men |
| 030 | MATL | 221128T194827Z | Luis Men |
| nan | Pip | 221128T191848Z | DLosc |
| nan | Jelly | 221128T181303Z | Jonathan |
| nan | Python | 221128T182113Z | Mukundan |
| nan | Sequences | 221128T173017Z | The Thon |
AWK, 71 bytes + 115 range = 186
@load "ordchr"
{for(m=1e9;i++<NF;x<m&&m=x){x=ord($i);x>M&&M=x}}1,$0=M-m
Forth (gforth), 62 bytes + 56 range = 118
: F BOUNDS 0 128 2SWAP DO I C@ MIN SWAP I C@ MAX SWAP LOOP - ;
Explanation
Loops through the string, keeping track of the min and max ascii code on the stack, then subtracts them at the end. Forth words are case insensitive, so using all uppercase saved some range in the score without affecting the functionality.
Code Explanation
: f (addr len -- n) \ Start new word definition
bounds \ get the start and end address of the string
0 128 \ create default max (0) and min (126) variables on the stack
2swap do \ move the addresses back into position and start a loop
i c@ min \ get the current char and compare with the min
swap \ move result back on the stack
i c@ max \ get the current char and compare with the max
swap \ move result back on the stack
loop \ end the loop
- \ subtract the min from the max
; \ end the word definition
Uiua, 23 bytes + 20 range = 43
subbotfironrevselrisdup
Explanation
-∩⊢⟜⇌⊏⍏.
⊏⍏. sort the array (by codepoints)
⟜⇌ get its reverse but keep the original on top
∩⊢ get the first element of both arrays, resulting in the first and last elements
- get their difference
Thunno 2 GB, 2 + 24 = 26
G_
Port of lyxal's Vyxal answer.
Explanation
G_ # Implicit input
# Convert to codepoints
G # Maximum codepoint
_ # Subtract each input codepoint
# Find the maximum
# Implicit output
Vyxal 2.4.1 K, 4 bytes + 26 range = Score 30
G?-G
If I knew what I was doing in 2021, this could have been 3 bytes with the G flag, but I never did figure out how to make the K flag play nice with other flags.
Explained
G?-G
G # Greatest character in the input
?- # With each character code subtract from it
G # Greatest of those
💎
Created with the help of Luminespire.
Nekomata, 6 bytes + 66 = 72
eo:h-l
eo:h-l
e Convert to codepoints
o Sort
: Duplicate
h Head
- Subtract
l Last
PowerShell, 58 bytes + 93 = 151
$args|%{$a=($_|% t*y)|%{[byte][char]$_}|sort;$a[-1]-$a[0]}
C (clang), 79 bytes + 28 = 145 138 129 112 111 107
-7 score thanks to @Digital Trauma
-9 -10 score thanks to @jdt
A,B;D(*C)??<*C<A?A=*C:*C>B?B=*C:0;*++C?D(C):0;??>C(*C)??<A=B=*C;D(C);*C=B-A;??>
Explanation
??< and ??> are trigraphs for { and } respectively
A,B; // A will track the minimum, B will track the maximum
D(*C){ // D() will traverse C updating the values of A and B
*C<A? // if current character < A
A=*C // update A with it's value
:*C>B? // else if current character > B
B=*C // update B with it's value
:0; // else, do nothing
*++C? // if we're not at the end of the string
D(C) // call D recursively with the next character
:0; // else, do nothing
} // end D()
C(*C){ // C() takes the string, which is also where we'll store the output
A=B=*C; // initialize A and B with the first character in C
D(C); // call D
*C=B-A; // store the range (max - min) in the out argument
} // end C()
Python 3, 39 bytes + 80 range = 119
print(ord(max(a:=input()))-ord(min(a)))
A full program is one point better here because it avoids the minimum character " " (32) for "(" (40).
Go, 95 bytes + 93 = 188
func(s string)int{m:=rune(s[0]);n:=m;for _,r:=range s{if m<r{m=r};if n>r{n=r}};return int(m-n)}
MATL, 3 bytes + 32 = 35
Sds
Explanation
Sds
S % Sort implicit input
d % Difference between adjacent elements
s % Sum the values
KamilaLisp v0.2, 88 + 35 = 123
[- $(foldl1 max) $(foldl1 min)]@ucs
Lua, 66 57 bytes + 89 86 = score 155 143
s=...print(math.max(s:byte(1,#s))-math.min(s:byte(1,#s)))
Program which takes command line argument for the strings.
Java 8, 106 108 bytes + 80 range = score 186 188
-2 bytes thanks to @ceilingcat
s->(s.chars().reduce(0,(a,b)->a>0?b>a>>16?b*65792-a%256*255:b<a%256?a/65536*65792-b*255:a:b*65537)>>8)%256
There is a better Java solution already posted, but maybe my answer could interest some people.
I'm not sure how to properly explain it, but by trying to keep only 1 inline Java stream, my goal was to carry 3 numbers < 256 inside only 1 integer ("a", the accumulator of the stream reduction) using this structure:
[_____max_value_____] [difference_between_max_and_min] [____min_value____]
<- 65 536 and over -> <- from 256 to 65 535 -> <- from 0 to 255 ->
GolfScript, 8 bytes, score 64
$(\)@-\;
Explanation
char : usage : stack
$ : ($)ort the (implicit) input : <sorted input>
( : take the first element out : <sorted input> <first item>
\ : swap the top two values of the stack : <first item> <sorted input>
) : last item : <first item> <sorted input> <last item>
@ : rotate the stack : <sorted input> <last item> <first item>
- : subtract, giving us the range : <sorted input> <range>
\ : swap the top two values on the stack : <range> <sorted input>
; : discard the top of the stack : <range>
(after which the stack is implicitly output)
APL, 11 chars + 9069-codepoint range = 9080.
(In Dyalog one-byte encoding, range is 186 for a total of 197.)
(⌈/-⌊/)⎕UCS
PHP, 39 bytes + 84 -> 123
fn($s)=>max($a=unpack('C*',$s))-min($a)
EDIT: OK this time I admit functional approach is way better :P
OLD VERSION:
PHP, -F 67 bytes + 78 -> 145
for($n=INF;$c=ord($argn[$i++]);$c<$m?:$m=$c)$c>$n?:$n=$c;echo$m-$n;
I wanted to give it a shot without arrays / min / max, in my traditional horrific-full of dollars-for loop Style and try to optimize for ASCII range rather. Stupid $argn cannot be in full caps. funny that it gives the same score like this (caps and no space nor brackets was the original plan):
PHP, -F 88 bytes + 57 -> 145
FOR($N=INF;$C=ORD($GLOBALS[STRTOLOWER(ARGN)][$I++]);$C<$M?:$M=$C)$C>$N?:$N=$C;ECHO$M-$N;
C# (Visual C# Interactive Compiler), 98 score (18 bytes)
ASCII range: 80
Length: 18
Total score: 98
s=>s.Max()-s.Min()
- -27 score thanks to Kevin Cruijssen for the tip to use C# Interactive
C# (Visual C# Compiler), 125 score (36 bytes)
ASCII range: 89
Length: 36
Total score: 125
s=>s.Max()-s.Min()
If we're going traditional through the compiler then we have to include an extra 18 bytes for using System.Linq;
Factor, 70 range + 21 bytes = 91 score
math.statistics:range
Requires modernish Factor for fully-qualified word syntax, hence nothing online will suffice.
Alumin, 36 19 bytes + 22 20 = 58 39
idiqdhhhwrvsruripkc
Both the right language for the job, and horribly inefficient at it! Turns out, I'm just an inefficient thinker!
Explanation
idiqdhhhwrvsruripkc
explanation | stack
id take input, duplicate | MAX MIN
iq ip while input > 0 | MAX MIN in
d duplicate | MAX MIN in in
hhhw grab top 3 | MAX [ MIN in in ]
r reverse stack | MAX [ in in MIN ]
v get lesser of two | MAX [ in MIN' ]
s ungrab | MAX in MIN'
r reverse stack | MIN' in MAX
u get greater of two | MIN' MAX'
r reverse stack | MAX' MIN'
(this gives us a better score than using `y` to swap 2)
loop finishes | MAX MIN -1
k discard eof | MAX MIN
c subtract | MAX-MIN
Explanation (Old)
hqidrlhcwrspkrklhhgwfufsykrlhcwfvfsc
h push 1 (to start loop)
q p input loop
id take input, duplicate
r reverse stack
lhc stack length - 1
wrs reverse that many elements off the stack
this has the effect of pushing two copies of the input
krk pop trailing EOF twice
lhhg stack length / 2
w grab that many elements into a new stack
fuf fold over maximum
sykr place on bottom stack, remove initial 1
lhc stack length - 1
w grab that many elements as before
fvf fold over minimum
sc push and subtract
Burlesque, 12 bytes + 52 = 64
)**J>]\/<].-
)** # Map to char code
J # Duplicate
>] # Maximum
\/ # Swap
<] # Minimum
.- # Difference
Pyth, 8 bytes + 34 = 42
+F.+CDCM
CM: Map to ASCII valueCD: Sort (equivalent toS).+: Deltas (Differences between consecutive elements, all nonegative because of sort)+F: Sum (equivalent tos)
Using .+ is golfier than h and e, and also stays within the established ASCII value range.
Excel, score = 103 94 (length 46, range 48)
-9 score thanks to Engineer Toast
=LET(A,CODE(RIGHT(A1,ROW(A:A))),MAX(A)-MIN(A))
Java 8, score: 134 (54 bytes)
s->s.chars().max().orElse(0)-s.chars().min().orElse(0)
Try it online (also contains code to extract the lambda function from the code-block and calculate its score: (max_codepoint - min_codepoint) + length).
Not too much too improve unfortunately.
- We could change the
xto\u0078, but unfortunately the next highest codepoint then becomesuwhich isn't too much lower thanx, so the +5 in byte-count is higher than the -3 in codepoint, giving a +2 in score instead of decrease: Try it online. - Using a regular for-loop requires both
{}and a space, so the difference of the max-min codepoints would widen on both ends. And in addition it's longer anyway: Try it online.
Explanation:
s-> // Method with String parameter and integer return-type
s.chars() // Convert the String to an IntStream of codepoint integers
.max() // Get the maximum of these codepoints
.orElse(0) // Convert the OptionalInt to an int
// (`.orElse(0)` is 1 byte shorter than `.getAsInt()`)
- // And subtract
s.chars().min().orElse(0)
// The same to get the minimum codepoint
Charcoal -v, 35 bytes, score 61
castminusordceilceil[q]ordminmin[q]
Try it online! Abusing Charcoal's verbose parser again. In order for it to recognise q as a variable name I can't follow it with a letter, so the next nearest suitable characters are the list delimiters. I've also used ceil instead of max to avoid using an x; this costs 2 bytes but overall saves 1 from my score. Normally the program would be written like this:
Print(Cast(Minus(Ordinal(Maximum(q)), Ordinal(Minimum(q)))));
The best I could do in succinct Charcoal was a score of 10135:
⭆ψ⁻℅⌈θ℅⌊θ
Try it online! Link is to verbose version of code. Explanation: The limiting factors here are the Greek letter θ needed for the two occurrences of the input variable (the only other input method uses S which has a ridiculously high Unicode code point of 65531) and the ⭆ used to stringify the result (again, I would have had far too high a code point).
ψ Predefined string null character
⭆ Map over characters and join
θ Input string
⌈ Maximium
℅ Ordinal
⁻ Minus
θ Input string
⌊ Minimum
℅ Ordinal
Implicitly print
If using bytes from Charcoal's code page was allowed, its score would "only" be 210:
SαI⁻℅⌈α℅⌊α
Try it online! Link is to verbose version of code. Explanation: The limiting factors here are that ⌊ (Minimum) is byte index 25 while α (variable a) is byte index 225, although I did reduce my score by 14 by taking the input into α rather than the default input of θ (variable q, byte index 241).
S Input as a string
α Store in variable `a`
α Input string
⌈ Maximum
℅ Ordinal
⁻ Subtract
α Input string
⌊ Minimum
℅ Ordinal
I Cast to string
Implicitly print
J, score 70 (16 bytes, range 54)
[:+/2-/\a.I.]\:]
]\:]: Pass the input (using the identity function]) on both sides of\:to sort it in descending order.a.I.: For each character of the sorted input, find its index in the "alphabet"; at least on TIO's setup, this contains all of ISO-8859-1 in order, which includes ASCII. Thus, this produces the ASCII values of the characters, while keeping the highest used character lower than the straightforward method of3u:would.
(I.would also take the following index if a character is not found, but that never happens; it was chosen overi.to reduce the highest used character.)2-/\: For each length-2 subarray (from the2and\), subtract the second value from the first (-/).[:+/: Take the sum (+/) of the values, using[:to do so monadically.
Nibbles, 9 12 bytes + 56 49 38 = 50
;*;-;o;/;\;`<@@o;/_$;`$$
This corresponds to the Nibbles program with nibbles:
6 a 6 9 6 e 6 a 6 b 6 e 4 d 4 e 6 a 5 3 6 d 7 3
Which, paired-up into bytes, gives
6a 69 6e 6a 6b 6e 4d 4e 6a 53 6d 73
which can be read-out as a string (with the same ASCII values)
jinjknMNjSms
with ASCII range 115 (73) - 77 (4d) = 38.
How?
We start from a straightforward code-golf solution to the question: -o/\;`<$$o/ (5.5 bytes, 11 nibbles):
-o/\;`<$@o/
- # subtract
o # character value of
/ # fold over
\ # reverse of
; # (save)
`< # sorted
@ # input
$ # returning left element each time
# (so the fold returns the first element)
# from
o # character value of
/ # fold over
# (implicit) saved sorted input
# (implicit) returning left element each time
The nibbles are slightly re-arranged in the final program, since the 2-nibble 'sort' function ( `<) wraps around its argument (here $). Thus, the paired-up nibbles from this are:
-o /\ ;` @< $o / # program code (in final order)
9e ab 6e 4d 3e a # nibbles
We can reduce the range of bytes by inserting 'save' operators (;, nibble 6) to shift high-valued nibbles into the least-significant-nibble position of each byte.
This doesn't affect the output, but we need to override the final implicit variable to account for the saved (but ignored) values. Hence:
;- ;o ;/ ;\ ;` @< $o ;/ ;$ # program code (in final order), with final variable changed to ;$
69 6e 6a 6b 6e 4d 3e 6a 63 # nibbles
Modifying both folds (so returning right element @ instead of left element $) avoids the lowest byte 3e, but unfortunately outputs a negated value.
So we multiply (and save: ;*) the negated value by its own sign (also saved: ;`$): this corrects the output, introducing a new highest byte of 73, but the overall score is still reduced.
><>, Score: 50 bytes + 74 = 124
0ff*i:0(ee+*98++0.:@:@$:@)?$?>@$:@$:@(?$?>$30.@-n;
Explanation
Initialize max = 0 and min = 225.
Then go through the input and update these values as needed.
At the end, print max - min.
Range Max: n = 110
We need n to print a number, so there isn't much we can do about this.
Range Min: $ = 36
$ swaps the top 2 values of the stack. Replacing it could save 6 on the range, but since we are using it in 6 places it seems unlikely that could we could save on the score by the reducing the range.
Code
We've replaced ~ = 126 with ? and r = 114 with @$ which saves 16 on the range at the cost of 3 bytes.
We've replaced the line feed = 10 with jumps . = 46 which saves 26 on the range at the cost of 6 bytes.
Ly, 8 bytes + 70 = 78
ia0I-s>l
I found a shorter program, but the character range of the code was big enough that it had a higher total score.
ia - read STDIN onto stack as codepoints, sort the stack
0I - copy the bottom of the stack to the top
- - subtract to get the range
s>l - save result, switch to clean stack, load result
MathGolf, score: 200 191 (4 6 bytes†)
†: MathGolf uses Code page 437.
$_╙\╓-
Increased the byte-count to slightly improve the score, but this is pretty hopeless.. The ord builtin $ is too far apart from most of the other useful builtins like min(╓)/max(╙)/sum(Σ)..
Input as a list of characters.
Explanation:
$ # Get the codepoint integers of each character in the (implicit) input-list
_ # Duplicate it
╙ # Pop and push its maximum
\ # Swap
╓ # Pop and push its minimum
- # Subtract this minimum from the maximum
# (after which the entire stack is output implicitly)
05AB1E, score: 158 124 (4 bytes)
Ç{¥O
Try it online or verify all test cases or verify its score.
Explanation:
Ç # Get a list of codepoint integers of the (implicit) input-string
{ # Sort them
¥ # Get the forward differences/deltas
O # Sum those together
# (after which the result is output implicitly)
Husk, 11 bytes + 63 = 74
ASz>o;FYOmc
ASz>o;FYOmc
m # map over input
c # getting character values
O # and sort into ascending order;
z # now, zip together
> # getting differences
S # the sorted list itself
# and
o; # the single-element list of
F # fold over the sorted list
Y # getting pairwise maxima
A # finally, get the average
# of the resulting single-element list.
R, 29 bytes + 77 = 106
\(a)diff(range(utf8ToInt(a)))
Seems that most golfy approach has also the lowest score, since we need to use utf8ToInt() and it has the range of 77 by itself.
J, score = 15 + 79 = 94
[:(>./-<./)3&u:
[:(>./-<./)3&u:
[: NB. enforce f (g y)
3&u: NB. convert string to list of char codes
( ) NB. monadic fork
<./ NB. min
>./ NB. max
- NB. subtract
Terse, 7 bytes + 6769 = 6776
找没最手样找到
Could be worse.
找 Char codes
没 Maximum, after
最手 Squaring and then square root (identity)
样 Subtract
找到 Minimum
Bash + GNU utilities, 52 bytes + 92 range = 144
od -An -w1 -td1 -v|sort -n|sed -n '1p;$p'|dc -e??r-p
MATL, score 37 (length 7, range 30)
X>GX<ZP
Try it online! Or verify all test cases and source code.
X> % Implicit input. Maximum
G % Push input again
X< % Minimum
ZP % Distance (of code points). Implicit display
Pip, 13 bytes + 39 = 52
a:A^aMXaADMNa
Explanation
A straight code-golf solution to the challenge might look like this:
A*:a;Ma-Na
a First command-line argument
A* Get ASCII value of each character
: and assign that list of integers back to a
; Statement separator
Na Minimum of a
a- Subtract that from each element in a
M and take the maximum of the resulting list
This gets a score of 65. The a for getting the command-line argument and A for taking ASCII values are both necessary, so to improve the score we'll need to look at the characters with ASCII values less than A.
The smallest character is *, which we can get rid of by splitting the string into a list of characters with ^ and passing that list to A directly:
A*:a
->
a:A^a
The next-smallest character is -, which we can get rid of by using the absolute difference operator AD instead. Then we have to rearrange a bit more to avoid needing a space; we'll use the old MX and MN operators for max and min instead of the newer M and N.
Ma-Na
->
MXaADMNa
(We could also keep using M, but since it also requires a semicolon to parse correctly, the score is the same if we replace it with MX which doesn't need the semicolon.)
Jelly, 5 bytes + 149 = 154
I think this is about as good as it's going to get in Jelly due to the distance between O (unavoidable as it's the only way to get the ordinals of the input string) and the large ordinals of Unicode characters representing the bytes for mapping and getting maximums and minimums, index into a list etc.
OÞOIS
A monadic Link that accepts a list of characters and yields the range size as an integer.
How?
OÞOIS - Link: list of characters (ordinal)
Þ - sort by: (222)
O - ordinal value (79)
O - ordinal values (79)
I - forward differences (73)
S - sum (83)
----
222
- 73
====
149
Sequences, score = 73 + 4.12 = 77.12
(Sequences uses the 96 printable ASCII characters as its codepage, so the byte count of this program is \$5\log_{256}(96) \approx 4.12\$)
`vMm-
Explanation
`vMm- # Implicit input as a string
`v # Get the ASCII values of the input string in a list
M # Get the maximum value of that list
m # Get the minimum value of that list
- # And subtract to find the range
# (implicit output)


