Skip to main content
Commonmark migration
Source Link

#R, 46 43 bytes

R, 46 43 bytes

sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))

Explanation

                    scan(,'')                  # Take the input string
           strsplit(         ,'\\D')           # Returns list of all numeric parts of the string
                                    [[1]]      # Unlists to character vector
    strtoi(                              )     # Converts to numeric vector
sum(                                      )    # Sums the numbers

Sample run

> sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))
1: a1wAD5qw45REs5Fw4eRQR33wqe4WE
2: 
Read 1 item
[1] 97

Edit: Replaced [^0-9] with \\D.

#R, 46 43 bytes

sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))

Explanation

                    scan(,'')                  # Take the input string
           strsplit(         ,'\\D')           # Returns list of all numeric parts of the string
                                    [[1]]      # Unlists to character vector
    strtoi(                              )     # Converts to numeric vector
sum(                                      )    # Sums the numbers

Sample run

> sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))
1: a1wAD5qw45REs5Fw4eRQR33wqe4WE
2: 
Read 1 item
[1] 97

Edit: Replaced [^0-9] with \\D.

R, 46 43 bytes

sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))

Explanation

                    scan(,'')                  # Take the input string
           strsplit(         ,'\\D')           # Returns list of all numeric parts of the string
                                    [[1]]      # Unlists to character vector
    strtoi(                              )     # Converts to numeric vector
sum(                                      )    # Sums the numbers

Sample run

> sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))
1: a1wAD5qw45REs5Fw4eRQR33wqe4WE
2: 
Read 1 item
[1] 97

Edit: Replaced [^0-9] with \\D.

Golfed 3 bytes
Source Link

#R, 4646 43 bytes

sum(strtoi(strsplit(scan(,''),'[^0-9]''\\D')[[1]]))

Explanation

                    scan(,'')                     # Take the input string
           strsplit(         ,'[^0-9]''\\D')           # Returns list of all numeric parts of the string
                                       [[1]]      # Unlists to character vector
    strtoi(                                 )     # Converts to numeric vector
sum(                                         )    # Sums the numbers

Sample run

> sum(strtoi(strsplit(scan(,''),'[^0-9]''\\D')[[1]]))
1: "a1wAD5qw45REs5Fw4eRQR33wqe4WE"a1wAD5qw45REs5Fw4eRQR33wqe4WE
2: 
Read 1 item
[1] 97

Edit: Replaced [^0-9] with \\D.

#R, 46 bytes

sum(strtoi(strsplit(scan(,''),'[^0-9]')[[1]]))

Explanation

                    scan(,'')                     # Take the input string
           strsplit(         ,'[^0-9]')           # Returns list of all numeric parts of the string
                                       [[1]]      # Unlists to character vector
    strtoi(                                 )     # Converts to numeric vector
sum(                                         )    # Sums the numbers

Sample run

> sum(strtoi(strsplit(scan(,''),'[^0-9]')[[1]]))
1: "a1wAD5qw45REs5Fw4eRQR33wqe4WE"
2: 
Read 1 item
[1] 97

#R, 46 43 bytes

sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))

Explanation

                    scan(,'')                  # Take the input string
           strsplit(         ,'\\D')           # Returns list of all numeric parts of the string
                                    [[1]]      # Unlists to character vector
    strtoi(                              )     # Converts to numeric vector
sum(                                      )    # Sums the numbers

Sample run

> sum(strtoi(strsplit(scan(,''),'\\D')[[1]]))
1: a1wAD5qw45REs5Fw4eRQR33wqe4WE
2: 
Read 1 item
[1] 97

Edit: Replaced [^0-9] with \\D.

Added an explanation
Source Link

#R, 46 bytes

sum(strtoi(strsplit(scan(,''),'[^0-9]')[[1]]))

Sample run:Explanation

                    scan(,'')                     # Take the input string
           strsplit(         ,'[^0-9]')           # Returns list of all numeric parts of the string
                                       [[1]]      # Unlists to character vector
    strtoi(                                 )     # Converts to numeric vector
sum(                                         )    # Sums the numbers

Sample run

> sum(strtoi(strsplit(scan(,''),'[^0-9]')[[1]]))
1: "a1wAD5qw45REs5Fw4eRQR33wqe4WE"
2: 
Read 1 item
[1] 97

#R, 46 bytes

sum(strtoi(strsplit(scan(,''),'[^0-9]')[[1]]))

Sample run:

> sum(strtoi(strsplit(scan(,''),'[^0-9]')[[1]]))
1: "a1wAD5qw45REs5Fw4eRQR33wqe4WE"
2: 
Read 1 item
[1] 97

#R, 46 bytes

sum(strtoi(strsplit(scan(,''),'[^0-9]')[[1]]))

Explanation

                    scan(,'')                     # Take the input string
           strsplit(         ,'[^0-9]')           # Returns list of all numeric parts of the string
                                       [[1]]      # Unlists to character vector
    strtoi(                                 )     # Converts to numeric vector
sum(                                         )    # Sums the numbers

Sample run

> sum(strtoi(strsplit(scan(,''),'[^0-9]')[[1]]))
1: "a1wAD5qw45REs5Fw4eRQR33wqe4WE"
2: 
Read 1 item
[1] 97
Source Link
Loading