Skip to main content
Commonmark migration
Source Link

R, 48 50 61 bytes

#R, 48 50 61 bytes AsAs an unnamed function

function(s)sd(range(sign(diff(utf8ToInt(s)))))<1 

Thanks to @guiseppe for a few extra bytes.

charToRaw takes s and splits into a raw vector. This is converted to integers and a diff applied. sign makes the diffs a single unit. range reduces the vector to it's minimum and maximum. Then if the standard deviation sd is less than 1 it is TRUE

Try it online!

#R, 48 50 61 bytes As an unnamed function

function(s)sd(range(sign(diff(utf8ToInt(s)))))<1 

Thanks to @guiseppe for a few extra bytes.

charToRaw takes s and splits into a raw vector. This is converted to integers and a diff applied. sign makes the diffs a single unit. range reduces the vector to it's minimum and maximum. Then if the standard deviation sd is less than 1 it is TRUE

Try it online!

R, 48 50 61 bytes

As an unnamed function

function(s)sd(range(sign(diff(utf8ToInt(s)))))<1 

Thanks to @guiseppe for a few extra bytes.

charToRaw takes s and splits into a raw vector. This is converted to integers and a diff applied. sign makes the diffs a single unit. range reduces the vector to it's minimum and maximum. Then if the standard deviation sd is less than 1 it is TRUE

Try it online!

deleted 307 characters in body
Source Link
MickyT
  • 12.3k
  • 2
  • 27
  • 49

#R, 5048 50 61 bytes As an unnamed function

function(s,d=diff)sd(range(sign(diff(utf8ToInt(s)))all(d<1)|all(d>=0)<1 

Thanks to @guiseppe for a few extra bytes.

charToRaw takes s and splits into a raw vector. This is converted to integers and a diff applied. Return true if all diffs are >= 0 or <= 0. Edited to use utf8ToInt rather than the extremely verbose way I was doing it.

Test

f= + function(s,d=diff(utf8ToInt(s)))all(d<1)|all(d>=0) > f('test') [1] FALSE > f('abc') [1] TRUE > f('cba') [1] TRUE > f('deer') [1] TRUE > f('reed') [1] TRUE > f('deed') [1] FALSE 

After being nudged into looking at this again there is also this version for the same bytes.

function(s)diff(range(sign(diff(utf8ToInt(s)))))<2 

It diffs and   signs makes the character ascii values to givediffs a vector of -1, 0, and 1'ssingle unit. range givereduces the min and max of thatvector to it's minimum and the diff ofmaximum. Then if the thatstandard deviation sd is tested.less than 1 it is TRUE

Try it online!

#R, 50 61 bytes As an unnamed function

function(s,d=diff(utf8ToInt(s)))all(d<1)|all(d>=0) 

charToRaw takes s and splits into a raw vector. This is converted to integers and a diff applied. Return true if all diffs are >= 0 or <= 0. Edited to use utf8ToInt rather than the extremely verbose way I was doing it.

Test

f= + function(s,d=diff(utf8ToInt(s)))all(d<1)|all(d>=0) > f('test') [1] FALSE > f('abc') [1] TRUE > f('cba') [1] TRUE > f('deer') [1] TRUE > f('reed') [1] TRUE > f('deed') [1] FALSE 

After being nudged into looking at this again there is also this version for the same bytes.

function(s)diff(range(sign(diff(utf8ToInt(s)))))<2 

It diffs and signs the character ascii values to give a vector of -1, 0, and 1's. range give the min and max of that and the diff of the that is tested.

#R, 48 50 61 bytes As an unnamed function

function(s)sd(range(sign(diff(utf8ToInt(s)))))<1 

Thanks to @guiseppe for a few extra bytes.

charToRaw takes s and splits into a raw vector. This is converted to integers and a diff applied.  sign makes the diffs a single unit. range reduces the vector to it's minimum and maximum. Then if the standard deviation sd is less than 1 it is TRUE

Try it online!

added 309 characters in body
Source Link
MickyT
  • 12.3k
  • 2
  • 27
  • 49

#R, 50 61 bytes As an unnamed function

function(s,d=diff(utf8ToInt(s)))all(d<1)|all(d>=0) 

charToRaw takes s and splits into a raw vector. This is converted to integers and a diff applied. Return true if all diffs are >= 0 or <= 0. Edited to use utf8ToInt rather than the extremely verbose way I was doing it.

Test

f= + function(s,d=diff(utf8ToInt(s)))all(d<1)|all(d>=0) > f('test') [1] FALSE > f('abc') [1] TRUE > f('cba') [1] TRUE > f('deer') [1] TRUE > f('reed') [1] TRUE > f('deed') [1] FALSE 

After being nudged into looking at this again there is also this version for the same bytes.

function(s)diff(range(sign(diff(utf8ToInt(s)))))<2 

It diffs and signs the character ascii values to give a vector of -1, 0, and 1's. range give the min and max of that and the diff of the that is tested.

#R, 50 61 bytes As an unnamed function

function(s,d=diff(utf8ToInt(s)))all(d<1)|all(d>=0) 

charToRaw takes s and splits into a raw vector. This is converted to integers and a diff applied. Return true if all diffs are >= 0 or <= 0. Edited to use utf8ToInt rather than the extremely verbose way I was doing it.

Test

f= + function(s,d=diff(utf8ToInt(s)))all(d<1)|all(d>=0) > f('test') [1] FALSE > f('abc') [1] TRUE > f('cba') [1] TRUE > f('deer') [1] TRUE > f('reed') [1] TRUE > f('deed') [1] FALSE 

#R, 50 61 bytes As an unnamed function

function(s,d=diff(utf8ToInt(s)))all(d<1)|all(d>=0) 

charToRaw takes s and splits into a raw vector. This is converted to integers and a diff applied. Return true if all diffs are >= 0 or <= 0. Edited to use utf8ToInt rather than the extremely verbose way I was doing it.

Test

f= + function(s,d=diff(utf8ToInt(s)))all(d<1)|all(d>=0) > f('test') [1] FALSE > f('abc') [1] TRUE > f('cba') [1] TRUE > f('deer') [1] TRUE > f('reed') [1] TRUE > f('deed') [1] FALSE 

After being nudged into looking at this again there is also this version for the same bytes.

function(s)diff(range(sign(diff(utf8ToInt(s)))))<2 

It diffs and signs the character ascii values to give a vector of -1, 0, and 1's. range give the min and max of that and the diff of the that is tested.

added 65 characters in body
Source Link
MickyT
  • 12.3k
  • 2
  • 27
  • 49
Loading
Source Link
MickyT
  • 12.3k
  • 2
  • 27
  • 49
Loading