Skip to main content
–1
Source Link

sed -E, 109 99 97 7575 74 bytes

h;s:.:0:g;G
:l;s:0.(0*.*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;tl
s:\+0+::g;s:\n..?::

Each line of the input is considered a separate number. Try it onlineTry it online.

Explanation:

h;                                           | copy the original string to the temporary buffer
  s:.:0:g;                                   | substitute all digits with zeroes
          G                                  | append the original string to the substituted one
                                             |
:l;                                          | main loop start
   s:0.(0*.*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;   | cut the next digit from the number, append with zeroes and add to the back
                                          tl | loop if the substitution hasn`t converged yet
                                             |
s:\+0+::g;                                   | remove all zero terms
          s:\n..?::                            | remove \n and the first +, if any

…can be golfed futher, I presume.

sed -E, 109 99 97 75 bytes

h;s:.:0:g;G
:l;s:0(0*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;tl
s:\+0+::g;s:\n.?::

Each line of the input is considered a separate number. Try it online.

Explanation:

h;                                           | copy the original string to the temporary buffer
  s:.:0:g;                                   | substitute all digits with zeroes
          G                                  | append the original string to the substituted one
                                             |
:l;                                          | main loop start
   s:0(0*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;   | cut the next digit from the number, append with zeroes and add to the back
                                          tl | loop if the substitution hasn`t converged yet
                                             |
s:\+0+::g;                                   | remove all zero terms
          s:\n.?::                           | remove \n and the first +, if any

…can be golfed futher, I presume.

sed -E, 109 99 97 75 74 bytes

h;s:.:0:g;G
:l;s:.(.*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;tl
s:\+0+::g;s:..?::

Each line of the input is considered a separate number. Try it online.

Explanation:

h;                                           | copy the original string to the temporary buffer
  s:.:0:g;                                   | substitute all digits with zeroes
          G                                  | append the original string to the substituted one
                                             |
:l;                                          | main loop start
   s:.(.*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;   | cut the next digit from the number, append with zeroes and add to the back
                                          tl | loop if the substitution hasn`t converged yet
                                             |
s:\+0+::g;                                   | remove all zero terms
          s:..?::                            | remove \n and the first +, if any

…can be golfed futher, I presume.

–22 bytes, wow
Source Link

sed -E, 109 99 9797 75 bytes

h;s:.:0:g;G;s:0\n(.*): -\1-:g;G
:l;s:(.)0(.*0*)-\n(.)(.*)-\+?(.*):\2-\4-\5+ \3\1\2\1\n\3+\4\2\1:;tl
s:. 0* \+0+::g;s:[^ ]* \n.?::

Each line of the input is considered a separate number. Try it onlineTry it online.

h;                                             | copy the original string to the temporary buffer
  s:.:0:g;                                     | substitute all digits with zeroes
          G; G                                  | append the original string to the substituted one
            s:0\n(.*): -\1-:                   | '0…000\n6…987' -> '0…00 -6…987-'
                                               |
:l;                                            | main loop start
   s:(.)0(.*0*)-\n(.)(.*)-\+?(.*):\2-\4-\5+ \3\1\2\1\n\3+\4\2\1:;   | cut the next digit from the number, append with zeroes and add to the back
                                            tl | loop if the substitution hasn`t converged yet
                                               |
s:. 0* \+0+::g;                                    | remove all zero terms
           s:[^ ]* \n.?::                           | remove everything up\n toand the first space+, if any

…still plenty of room for optimization…can be golfed futher, I presume.

sed -E, 109 99 97 bytes

h;s:.:0:g;G;s:0\n(.*): -\1-:
:l;s:(.)(.*)-(.)(.*)-(.*):\2-\4-\5+ \3\1\2:;tl
s:. 0* ::g;s:[^ ]* ::

Each line of the input is considered a separate number. Try it online.

h;                                             | copy the original string to the temporary buffer
  s:.:0:g;                                     | substitute all digits with zeroes
          G;                                   | append the original string to the substituted one
            s:0\n(.*): -\1-:                   | '0…000\n6…987' -> '0…00 -6…987-'
                                               |
:l;                                            | main loop start
   s:(.)(.*)-(.)(.*)-(.*):\2-\4-\5+ \3\1\2:;   | cut the next digit from the number, append with zeroes and add to the back
                                            tl | loop if the substitution hasn`t converged yet
                                               |
s:. 0* ::g;                                    | remove all zero terms
           s:[^ ]* ::                          | remove everything up to the first space

…still plenty of room for optimization.

sed -E, 109 99 97 75 bytes

h;s:.:0:g;G
:l;s:0(0*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;tl
s:\+0+::g;s:\n.?::

Each line of the input is considered a separate number. Try it online.

h;                                           | copy the original string to the temporary buffer
  s:.:0:g;                                   | substitute all digits with zeroes
          G                                  | append the original string to the substituted one
                                             |
:l;                                          | main loop start
   s:0(0*)\n(.)(.*)\+?(.*):\1\n\3+\4\2\1:;   | cut the next digit from the number, append with zeroes and add to the back
                                          tl | loop if the substitution hasn`t converged yet
                                             |
s:\+0+::g;                                   | remove all zero terms
          s:\n.?::                           | remove \n and the first +, if any

…can be golfed futher, I presume.

–2
Source Link

sed -E, 109 9999 97 bytes

h;s:.:0:g;G;s:0\n(.*): -\1-\n:
:l;s:(.)(.*)-(.)(.*)-(.*):\2-\4-\5+ \3\1\2:;tl
s:. 0* ::g;s:[^ ]* ::

Each line of the input is considered a separate number. Try it onlineTry it online.

Explanation:

h;                                             | copy the original string to the temporary buffer
  s:.:0:g;                                     | substitute all digits with zeroes
          G;                                   | append the original string to the substituted one
            s:0\n(.*): -\1-\n:                   | '0…000\n6…987' -> '0…00 -6…987-\n''
                                               |
:l;                                            | main loop start
   s:(.)(.*)-(.)(.*)-(.*):\2-\4-\5+ \3\1\2:;   | cut the next digit from the number, append with zeroes and add to the back
                                            tl | loop if the substitution hasn`t converged yet
                                               |
s:. 0* ::g;                                    | remove all zero terms
           s:[^ ]* ::                          | remove everything up to the first space

…still plenty of room for optimization.

sed -E, 109 99 bytes

h;s:.:0:g;G;s:0\n(.*): -\1-\n:
:l;s:(.)(.*)-(.)(.*)-(.*):\2-\4-\5+ \3\1\2:;tl
s:. 0* ::g;s:[^ ]* ::

Each line of the input is considered a separate number. Try it online.

Explanation:

h;                                             | copy the original string to the temporary buffer
  s:.:0:g;                                     | substitute all digits with zeroes
          G;                                   | append the original string to the substituted one
            s:0\n(.*): -\1-\n:                 | '0…000\n6…987' -> '0…00 -6…987-\n'
                                               |
:l;                                            | main loop start
   s:(.)(.*)-(.)(.*)-(.*):\2-\4-\5+ \3\1\2:;   | cut the next digit from the number, append with zeroes and add to the back
                                            tl | loop if the substitution hasn`t converged yet
                                               |
s:. 0* ::g;                                    | remove all zero terms
           s:[^ ]* ::                          | remove everything up to the first space

…still plenty of room for optimization.

sed -E, 109 99 97 bytes

h;s:.:0:g;G;s:0\n(.*): -\1-:
:l;s:(.)(.*)-(.)(.*)-(.*):\2-\4-\5+ \3\1\2:;tl
s:. 0* ::g;s:[^ ]* ::

Each line of the input is considered a separate number. Try it online.

Explanation:

h;                                             | copy the original string to the temporary buffer
  s:.:0:g;                                     | substitute all digits with zeroes
          G;                                   | append the original string to the substituted one
            s:0\n(.*): -\1-:                   | '0…000\n6…987' -> '0…00 -6…987-'
                                               |
:l;                                            | main loop start
   s:(.)(.*)-(.)(.*)-(.*):\2-\4-\5+ \3\1\2:;   | cut the next digit from the number, append with zeroes and add to the back
                                            tl | loop if the substitution hasn`t converged yet
                                               |
s:. 0* ::g;                                    | remove all zero terms
           s:[^ ]* ::                          | remove everything up to the first space

…still plenty of room for optimization.

woohoo, –10 bytes!
Source Link
Loading
Source Link
Loading