Skip to main content
deleted 242 characters in body
Source Link
G B
  • 23.4k
  • 1
  • 24
  • 55

Ruby, 45 40 4037 bytes

->n{n(n+n.gsubscan(/(.(.?))/,'\1\2\2')*''*2).sum%10<1} 

Try it online!

###How it works: Iterate on the string, triplicating every second character. The sum of the ASCII codes of the string modulo 10 is the same as the checksum we are looking for (the difference is 487+486*3==1200 so it doesn't matter)Try it online!

Ruby, 45 40 bytes

->n{n.gsub(/(.(.?))/,'\1\2\2').sum%10<1} 

Try it online!

###How it works: Iterate on the string, triplicating every second character. The sum of the ASCII codes of the string modulo 10 is the same as the checksum we are looking for (the difference is 487+486*3==1200 so it doesn't matter)

Ruby, 45 40 37 bytes

->n{(n+n.scan(/.(.)/)*''*2).sum%10<1} 

Try it online!

added 2 characters in body
Source Link
G B
  • 23.4k
  • 1
  • 24
  • 55

Ruby, 45 40 bytes

->n{n.gsub(/(.(.?))/,'\1\2\2').sum%10<1} 

Try it online!

###How it works: Iterate on the string, triplicating every second character. The sum of the ASCII codes of the string modulo 10 is the same as the checksum we are looking for (the difference is 487+486*3==1200 so it doesn't matter)

Ruby, 45 40 bytes

->n{n.gsub(/(.(.?))/,'\1\2\2').sum%10<1} 

Try it online!

Ruby, 45 40 bytes

->n{n.gsub(/(.(.?))/,'\1\2\2').sum%10<1} 

Try it online!

###How it works: Iterate on the string, triplicating every second character. The sum of the ASCII codes of the string modulo 10 is the same as the checksum we are looking for (the difference is 487+486*3==1200 so it doesn't matter)

added 2 characters in body
Source Link
G B
  • 23.4k
  • 1
  • 24
  • 55

Ruby, 4545 40 bytes

->n{n.digitsgsub(/(.zip([1.?))/,3]*7'\1\2\2').sum{|a,b|a*b}%10<1sum%10<1} 

Try it online!Try it online!

Ruby, 45 bytes

->n{n.digits.zip([1,3]*7).sum{|a,b|a*b}%10<1} 

Try it online!

Ruby, 45 40 bytes

->n{n.gsub(/(.(.?))/,'\1\2\2').sum%10<1} 

Try it online!

Source Link
G B
  • 23.4k
  • 1
  • 24
  • 55
Loading