Skip to main content
added 469 characters in body
Source Link
Dennis
  • 210.3k
  • 41
  • 370
  • 824

Jelly, 6 bytes

&-ṣ-ḌS

Try it online!

How it works

&-ṣ-ḌS  Main link. Input: L (string)

&-      Take the bitwise AND of L's characters and -1.
        This attempts to cast to int, so '0' & -1 -> 0 & -1 -> 0.
        On failure, it returns the integer argument (if any), so 'a' & -1 -> -1.
  ṣ-    Split the resulting list at occurrences of -1.
    Ḍ   Convert each chunk from decimal to integer. In particular, [] -> 0.
     S  Compute the sum of the results.

Jelly, 6 bytes

&-ṣ-ḌS

Try it online!

Jelly, 6 bytes

&-ṣ-ḌS

Try it online!

How it works

&-ṣ-ḌS  Main link. Input: L (string)

&-      Take the bitwise AND of L's characters and -1.
        This attempts to cast to int, so '0' & -1 -> 0 & -1 -> 0.
        On failure, it returns the integer argument (if any), so 'a' & -1 -> -1.
  ṣ-    Split the resulting list at occurrences of -1.
    Ḍ   Convert each chunk from decimal to integer. In particular, [] -> 0.
     S  Compute the sum of the results.
Source Link
Dennis
  • 210.3k
  • 41
  • 370
  • 824

Jelly, 6 bytes

&-ṣ-ḌS

Try it online!