Skip to main content
replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

Pyth, 12 11 10 bytes

ssM:z"\D"3
    z        autoinitialized to input()
   : "\D"3   split on non-digits
 sM          convert all elements of resulting array to ints
s            sum

Fortunately, s (convert to int) returns 0 when applied to the empty string, so I don't have to worry about the fact that split("a1b", "\D+") returns ["", "1", ""]. Similarly, split("a", "\D+") returns ["", ""].

This even allows me to split on every non-digit individually, since 1 + 0 + 0 + 0 + 0 + 2 is the same thing as 1 + 2.

Thanks to Thomas KwaThomas Kwa for a byte!

Pyth, 12 11 10 bytes

ssM:z"\D"3
    z        autoinitialized to input()
   : "\D"3   split on non-digits
 sM          convert all elements of resulting array to ints
s            sum

Fortunately, s (convert to int) returns 0 when applied to the empty string, so I don't have to worry about the fact that split("a1b", "\D+") returns ["", "1", ""]. Similarly, split("a", "\D+") returns ["", ""].

This even allows me to split on every non-digit individually, since 1 + 0 + 0 + 0 + 0 + 2 is the same thing as 1 + 2.

Thanks to Thomas Kwa for a byte!

Pyth, 12 11 10 bytes

ssM:z"\D"3
    z        autoinitialized to input()
   : "\D"3   split on non-digits
 sM          convert all elements of resulting array to ints
s            sum

Fortunately, s (convert to int) returns 0 when applied to the empty string, so I don't have to worry about the fact that split("a1b", "\D+") returns ["", "1", ""]. Similarly, split("a", "\D+") returns ["", ""].

This even allows me to split on every non-digit individually, since 1 + 0 + 0 + 0 + 0 + 2 is the same thing as 1 + 2.

Thanks to Thomas Kwa for a byte!

added 101 characters in body
Source Link
Doorknob
  • 71.5k
  • 20
  • 143
  • 383

Pyth, 1212 11 10 bytes

smsdssM:z"\D+"3z"\D"3
     z        autoinitialized to input()
    : "\D+"3"\D"3   split on non-digits
 msdsM          convert all elements of resulting array to ints
s             sum

Fortunately, s (convert to int) returns 0 when applied to the empty string, so I don't have to worry about the fact that split("a1b", "\D+") returns ["", "1", ""]. Similarly, split("a", "\D+") returns ["", ""].

This even allows me to split on every non-digit individually, since 1 + 0 + 0 + 0 + 0 + 2 is the same thing as 1 + 2.

Thanks to Thomas Kwa for a byte!

Pyth, 12 bytes

smsd:z"\D+"3
     z        autoinitialized to input()
    : "\D+"3  split on non-digits
 msd          convert all elements of resulting array to ints
s             sum

Fortunately, s (convert to int) returns 0 when applied to the empty string, so I don't have to worry about the fact that split("a1b", "\D+") returns ["", "1", ""]. Similarly, split("a", "\D+") returns ["", ""].

Pyth, 12 11 10 bytes

ssM:z"\D"3
    z        autoinitialized to input()
   : "\D"3   split on non-digits
 sM          convert all elements of resulting array to ints
s            sum

Fortunately, s (convert to int) returns 0 when applied to the empty string, so I don't have to worry about the fact that split("a1b", "\D+") returns ["", "1", ""]. Similarly, split("a", "\D+") returns ["", ""].

This even allows me to split on every non-digit individually, since 1 + 0 + 0 + 0 + 0 + 2 is the same thing as 1 + 2.

Thanks to Thomas Kwa for a byte!

Source Link
Doorknob
  • 71.5k
  • 20
  • 143
  • 383

Pyth, 12 bytes

smsd:z"\D+"3
     z        autoinitialized to input()
    : "\D+"3  split on non-digits
 msd          convert all elements of resulting array to ints
s             sum

Fortunately, s (convert to int) returns 0 when applied to the empty string, so I don't have to worry about the fact that split("a1b", "\D+") returns ["", "1", ""]. Similarly, split("a", "\D+") returns ["", ""].