Skip to main content
Commonmark migration
Source Link

#Bash + GNU utilities, 32 24

Bash + GNU utilities, 32 24

tac|nl -s*|paste -sd+|bc

Input read from STDIN.

Update: I see the input may be given as a list of digits. My input list is newline-delimited.

Try it online.

###Explanation

Explanation

tac                       # reverse digit list
   |nl -s*                # prefix line numbers; separate with "*" operator
          |paste -sd+     # join lines onto one line, separated with "+" operator
                     |bc  # arithmetically evaluate

#Bash + GNU utilities, 32 24

tac|nl -s*|paste -sd+|bc

Input read from STDIN.

Update: I see the input may be given as a list of digits. My input list is newline-delimited.

Try it online.

###Explanation

tac                       # reverse digit list
   |nl -s*                # prefix line numbers; separate with "*" operator
          |paste -sd+     # join lines onto one line, separated with "+" operator
                     |bc  # arithmetically evaluate

Bash + GNU utilities, 32 24

tac|nl -s*|paste -sd+|bc

Input read from STDIN.

Update: I see the input may be given as a list of digits. My input list is newline-delimited.

Try it online.

Explanation

tac                       # reverse digit list
   |nl -s*                # prefix line numbers; separate with "*" operator
          |paste -sd+     # join lines onto one line, separated with "+" operator
                     |bc  # arithmetically evaluate
added 8 characters in body
Source Link
Digital Trauma
  • 73k
  • 9
  • 112
  • 264

#Bash + GNU utilities, 3232 24

rev|fold -1|nltac|nl -s*|paste -sd+|bc

Input read from STDIN.

Try it online Update: I see the input may be given as a list of digits. My input list is newline-delimited.

Try it online.

###Explanation

rev       tac                       # reverse digits
   |fold -1                      # split each digit onto its own linelist
           |nl -s*                # prefix line numbers; separate with "*" operator
                  |paste -sd+     # join lines onto one line, separated with "+" operator
                             |bc  # arithmetically evaluate

#Bash + GNU utilities, 32

rev|fold -1|nl -s*|paste -sd+|bc

Input read from STDIN.

Try it online.

###Explanation

rev                              # reverse digits
   |fold -1                      # split each digit onto its own line
           |nl -s*               # prefix line numbers; separate with "*" operator
                  |paste -sd+    # join lines onto one line, separated with "+" operator
                             |bc # arithmetically evaluate

#Bash + GNU utilities, 32 24

tac|nl -s*|paste -sd+|bc

Input read from STDIN.

Update: I see the input may be given as a list of digits. My input list is newline-delimited.

Try it online.

###Explanation

tac                       # reverse digit list
   |nl -s*                # prefix line numbers; separate with "*" operator
          |paste -sd+     # join lines onto one line, separated with "+" operator
                     |bc  # arithmetically evaluate
Source Link
Digital Trauma
  • 73k
  • 9
  • 112
  • 264

#Bash + GNU utilities, 32

rev|fold -1|nl -s*|paste -sd+|bc

Input read from STDIN.

Try it online.

###Explanation

rev                              # reverse digits
   |fold -1                      # split each digit onto its own line
           |nl -s*               # prefix line numbers; separate with "*" operator
                  |paste -sd+    # join lines onto one line, separated with "+" operator
                             |bc # arithmetically evaluate