Skip to main content
deleted 45 characters in body
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120

R, 66 48 46 43 4038 bytes

function(s)identical!any(duplicated(rle(s)$v,unique(s)) 

This is a function that accepts the input as a vector of digits and returns a boolean. To call it, assign it to a variable.

It certainly isn'tNot the shortest but I thought it was a fun approach. We run length encode the input and extract the values. If the list of values is identical to the input withcontains duplicates removed,then return TRUEFALSE, otherwise return FALSETRUE.

Verify all test cases onlineVerify all test cases online

Saved 20 bytes thanks to MickyT, 3 thanks to Albert Masclans, and another 35 thanks to mnel!

R, 66 48 46 43 40 bytes

function(s)identical(rle(s)$v,unique(s)) 

This is a function that accepts the input as a vector of digits and returns a boolean. To call it, assign it to a variable.

It certainly isn't the shortest but I thought it was a fun approach. We run length encode the input and extract the values. If the list of values is identical to the input with duplicates removed, return TRUE, otherwise FALSE.

Verify all test cases online

Saved 20 bytes thanks to MickyT, 3 thanks to Albert Masclans, and another 3 thanks to mnel!

R, 66 48 46 43 38 bytes

function(s)!any(duplicated(rle(s)$v)) 

This is a function that accepts the input as a vector of digits and returns a boolean. To call it, assign it to a variable.

Not the shortest but I thought it was a fun approach. We run length encode the input and extract the values. If the list of values contains duplicates then return FALSE, otherwise return TRUE.

Verify all test cases online

Saved 20 bytes thanks to MickyT, 3 thanks to Albert Masclans, and 5 thanks to mnel!

added 34 characters in body
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120

R, 66 48 46 4343 40 bytes

function(s)identical(x<-rle(s)$v,unique(xs)) 

This is a function that accepts the input as a vector of digits and returns a boolean. To call it, assign it to a variable.

It certainly isn't the shortest but I thought it was a fun approach. We run length encode the input and extract the values. If the list of values is identical to itselfthe input with duplicates removed, return TRUE, otherwise FALSE.

Verify all test cases onlineVerify all test cases online

Saved 20 bytes thanks to MickyT and, 3 thanks to Albert Masclans, and another 3 thanks to mnel!

R, 66 48 46 43 bytes

function(s)identical(x<-rle(s)$v,unique(x)) 

This is a function that accepts the input as a vector of digits and returns a boolean. To call it, assign it to a variable.

It certainly isn't the shortest but I thought it was a fun approach. We run length encode the input and extract the values. If the list of values is identical to itself with duplicates removed, return TRUE, otherwise FALSE.

Verify all test cases online

Saved 20 bytes thanks to MickyT and 3 thanks to Albert Masclans!

R, 66 48 46 43 40 bytes

function(s)identical(rle(s)$v,unique(s)) 

This is a function that accepts the input as a vector of digits and returns a boolean. To call it, assign it to a variable.

It certainly isn't the shortest but I thought it was a fun approach. We run length encode the input and extract the values. If the list of values is identical to the input with duplicates removed, return TRUE, otherwise FALSE.

Verify all test cases online

Saved 20 bytes thanks to MickyT, 3 thanks to Albert Masclans, and another 3 thanks to mnel!

added 39 characters in body
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120

R, 66 48 4646 43 bytes

function(s)identical(x<-rle(s)[[2]]$v,unique(x)) 

This is a function that accepts the input as a vector of digits and returns a boolean. To call it, assign it to a variable.

It certainly isn't the shortest but I thought it was a fun approach. We run length encode the input and extract the values. If the list of values is identical to itself with duplicates removed, return TRUE, otherwise FALSE.

Verify all test cases online

Saved 20 bytes thanks to MickyT and 3 thanks to Albert Masclans!

R, 66 48 46 bytes

function(s)identical(x<-rle(s)[[2]],unique(x)) 

This is a function that accepts the input as a vector of digits and returns a boolean. To call it, assign it to a variable.

It certainly isn't the shortest but I thought it was a fun approach. We run length encode the input and extract the values. If the list of values is identical to itself with duplicates removed, return TRUE, otherwise FALSE.

Verify all test cases online

Saved 20 bytes thanks to MickyT!

R, 66 48 46 43 bytes

function(s)identical(x<-rle(s)$v,unique(x)) 

This is a function that accepts the input as a vector of digits and returns a boolean. To call it, assign it to a variable.

It certainly isn't the shortest but I thought it was a fun approach. We run length encode the input and extract the values. If the list of values is identical to itself with duplicates removed, return TRUE, otherwise FALSE.

Verify all test cases online

Saved 20 bytes thanks to MickyT and 3 thanks to Albert Masclans!

added 8 characters in body
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120
Loading
added 38 characters in body
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120
Loading
Source Link
Alex A.
  • 24.8k
  • 5
  • 39
  • 120
Loading