Skip to main content
Commonmark migration
Source Link

##Lua, 51 Bytes

Lua, 51 Bytes

Pretty short for once! Even shorter than Java! The input must be a command-line argument for it to work.

a=0 arg[1]:gsub("%d+",function(c)a=a+c end)print(a)

Ungolfed

a=0                 -- Initialize the sum at 0
arg[1]:gsub("%d+",  -- capture each group of digits in the string
  function(c)       -- and apply an anonymous function to each of them
  a=a+c             -- sums a with the latest group captured
end)               
print(a)            -- output a

##Lua, 51 Bytes

Pretty short for once! Even shorter than Java! The input must be a command-line argument for it to work.

a=0 arg[1]:gsub("%d+",function(c)a=a+c end)print(a)

Ungolfed

a=0                 -- Initialize the sum at 0
arg[1]:gsub("%d+",  -- capture each group of digits in the string
  function(c)       -- and apply an anonymous function to each of them
  a=a+c             -- sums a with the latest group captured
end)               
print(a)            -- output a

Lua, 51 Bytes

Pretty short for once! Even shorter than Java! The input must be a command-line argument for it to work.

a=0 arg[1]:gsub("%d+",function(c)a=a+c end)print(a)

Ungolfed

a=0                 -- Initialize the sum at 0
arg[1]:gsub("%d+",  -- capture each group of digits in the string
  function(c)       -- and apply an anonymous function to each of them
  a=a+c             -- sums a with the latest group captured
end)               
print(a)            -- output a
Source Link
Katenkyo
  • 3.1k
  • 14
  • 28

##Lua, 51 Bytes

Pretty short for once! Even shorter than Java! The input must be a command-line argument for it to work.

a=0 arg[1]:gsub("%d+",function(c)a=a+c end)print(a)

Ungolfed

a=0                 -- Initialize the sum at 0
arg[1]:gsub("%d+",  -- capture each group of digits in the string
  function(c)       -- and apply an anonymous function to each of them
  a=a+c             -- sums a with the latest group captured
end)               
print(a)            -- output a