Skip to main content
added 46 characters in body
Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 5151 48 bytes

Edit: -3 bytes thanks to Robin Ryder

function(s)sum((utf8ToInt(s)-48)*10^%*%10^(nchar(s):1-1))

Try it online!Try it online!

Multiplies Utf8 value of each character minus 48 by powers-of-ten from the length of the string minus one, down to zero, and outputs the sum.

R, 51 bytes

function(s)sum((utf8ToInt(s)-48)*10^(nchar(s):1-1))

Try it online!

Multiplies Utf8 value of each character minus 48 by powers-of-ten from the length of the string minus one, down to zero, and outputs the sum.

R, 51 48 bytes

Edit: -3 bytes thanks to Robin Ryder

function(s)(utf8ToInt(s)-48)%*%10^(nchar(s):1-1)

Try it online!

Multiplies Utf8 value of each character minus 48 by powers-of-ten from the length of the string minus one, down to zero, and outputs the sum.

Source Link
Dominic van Essen
  • 36.4k
  • 2
  • 22
  • 60

R, 51 bytes

function(s)sum((utf8ToInt(s)-48)*10^(nchar(s):1-1))

Try it online!

Multiplies Utf8 value of each character minus 48 by powers-of-ten from the length of the string minus one, down to zero, and outputs the sum.