Skip to main content
added 190 characters in body
Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina 0.8.2, 2323 22 bytes

.(.) $&$1$1 . $* M`. 0$1$ 

Try it online!Try it online! Link includes test cases. Edit: Saved 1 byte thanks to Martin Ender's comment on @Leo's Retina answer to the EAN-8 question. Explanation:

.(.) $&$1$1 

Triplicate alternate digits.

. $* 

Convert each digit to unary.

M`. 

TakeCount the sum and convert back to decimalnumber of character boundaries, which is one more than the number of characters.

0$1$ 

Check for divisibilty by 10, but allow for the 1 we just added.

Retina 0.8.2, 23 bytes

.(.) $&$1$1 . $* M`. 0$ 

Try it online! Link includes test cases. Explanation:

.(.) $&$1$1 

Triplicate alternate digits.

. $* 

Convert each digit to unary.

M`. 

Take the sum and convert back to decimal.

0$ 

Check for divisibilty by 10.

Retina 0.8.2, 23 22 bytes

.(.) $&$1$1 . $* M` 1$ 

Try it online! Link includes test cases. Edit: Saved 1 byte thanks to Martin Ender's comment on @Leo's Retina answer to the EAN-8 question. Explanation:

.(.) $&$1$1 

Triplicate alternate digits.

. $* 

Convert each digit to unary.

M` 

Count the number of character boundaries, which is one more than the number of characters.

1$ 

Check for divisibilty by 10, but allow for the 1 we just added.

Source Link
Neil
  • 184.4k
  • 12
  • 76
  • 290

Retina 0.8.2, 23 bytes

.(.) $&$1$1 . $* M`. 0$ 

Try it online! Link includes test cases. Explanation:

.(.) $&$1$1 

Triplicate alternate digits.

. $* 

Convert each digit to unary.

M`. 

Take the sum and convert back to decimal.

0$ 

Check for divisibilty by 10.