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

The last test case prints 9000000+9e-7, which has been ruled valid by @NinjaBearMonkeyruled valid by @NinjaBearMonkey.

The last test case prints 9000000+9e-7, which has been ruled valid by @NinjaBearMonkey.

The last test case prints 9000000+9e-7, which has been ruled valid by @NinjaBearMonkey.

deleted 38 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825

CJam, 3333 26 bytes

r:R,,_fr_ee\'0fe<f{f=R'.f=.+R.e&s~\~t~}{},'+*0e|

This won't work with the Java interpreter; it print floats differently. Try it with the CJam interpreterCJam interpreter.

The last test case prints 9000000+9e-7, which has been ruled valid by @NinjaBearMonkey.

Thanks to @jimmy23013 for golfing off 7 bytes!

r:R     r_                           Read a token from STDIN and save itpush ina Rcopy.
   ,,      ee                        Turn REnumerate (nits characters) into I := [0, ..i. n-1]e.
  , push the _array of all
                           Push a copy[index ofcharacter] Ipairs.
      f{  \             }           For eachSwap Jthe inoriginal I,input pushon Jtop andof I;the then:stack.
        f=       '0fe<                   Perform Mapvectorized comparisonminimum with J overthe Icharacter '0'. This turns J
                                     into 1,This andreplaces all otherdigits elementswith of'0', Ibut intoleaves 0's'.'
          R'.f=                      Map comparisonuntouched, withsince '`.' over< R'0'. This turns the
                   f{    }            For each '.'[index (ifcharacter] present)pair, intopush athe 1pair and all otherthe
                                  string of zeroes charactersand of(possibly) Ra intodot; 0's.then:
             \  .+                  Swap the Performpair vectorizedon sumtop of the Boolean arraysstack.
             ~    R.e&               Dump Performindex vectorizedand logicalcharacter ANDon withthe Rstack.
                 t                  Replace the Thisstring's replaceselement theat non-zerothat integer(s)index with the
                                     correspondingthat character(s) or R.
                 ~    s~             Evaluate Castthe toresulting string and evaluate.
                        {},         Filter the array to remove zeroes.
                           '+*      Join, using '+' as separator.
                              0e|   If the result is empty, replace it with 0.
                       

CJam, 33 bytes

r:R,,_f{f=R'.f=.+R.e&s~}{},'+*0e|

This won't work with the Java interpreter; it print floats differently. Try it with the CJam interpreter.

The last test case prints 9000000+9e-7, which has been ruled valid by @NinjaBearMonkey.

r:R                                Read a token from STDIN and save it in R.
   ,,                              Turn R (n characters) into I := [0 ... n-1].
     _                             Push a copy of I.
      f{               }           For each J in I, push J and I; then:
        f=                           Map comparison with J over I . This turns J
                                     into 1, and all other elements of I into 0's.
          R'.f=                      Map comparison with '.' over R. This turns the
                                     '.' (if present) into a 1 and all other
                                     characters of R into 0's.
               .+                    Perform vectorized sum of the Boolean arrays.
                 R.e&                Perform vectorized logical AND with R.
                                     This replaces the non-zero integer(s) with the
                                     corresponding character(s) or R.
                     s~              Cast to string and evaluate.
                        {},        Filter the array to remove zeroes.
                           '+*     Join, using '+' as separator.
                              0e|  If the result is empty, replace it with 0.
                       

CJam, 33 26 bytes

r_ee\'0fe<f{\~t~}{},'+*0e|

This won't work with the Java interpreter; it print floats differently. Try it with the CJam interpreter.

The last test case prints 9000000+9e-7, which has been ruled valid by @NinjaBearMonkey.

Thanks to @jimmy23013 for golfing off 7 bytes!

r_                           Read a token from STDIN and push a copy.
  ee                         Enumerate its characters, i.e., push the array of all
                             [index character] pairs.
    \                        Swap the original input on top of the stack.
     '0fe<                   Perform vectorized minimum with the character '0'.
                             This replaces all digits with '0', but leaves '.'
                             untouched, since `.' < '0'.
          f{    }            For each [index character] pair, push the pair and the
                             string of zeroes and (possibly) a dot; then:
            \                    Swap the pair on top of the stack.
             ~                   Dump index and character on the stack.
              t                  Replace the string's element at that index with
                                 that character.
               ~                 Evaluate the resulting string.
                 {},         Filter the array to remove zeroes.
                    '+*      Join, using '+' as separator.
                       0e|   If the result is empty, replace it with 0.
                       
added 11 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
r:R,,_f{f=R'.f=.+R.e&sde&s~}0d-{},'+*0e|

This won't work with the Java interpreter; it print floats differently. Try it with the CJam interpreterCJam interpreter.

r:R                                Read a token from STDIN and save it in R.
   ,,                              Turn R (n characters) into I := [0 ... n-1].
     _                             Push a copy of I.
      f{               }           For each J in I, push J and I; then:
        f=                           Map comparison with J over I . This turns J
                                     into 1, and all other elements of I into 0's.
          R'.f=                      Map comparison with '.' over R. This turns the
                                     '.' (if present) into a 1 and all other
                                     characters of R into 0's.
               .+                    Perform vectorized sum of the Boolean arrays.
                 R.e&                Perform vectorized logical AND with R.
                                     This replaces the non-zero integer(s) with the
                                     corresponding character(s) or R.
                     sds~              Cast to string, then toand Doubleevaluate.
                        0d-{},       Remove allFilter zeroesthe fromarray theto resultingremove arrayzeroes.
                           '+*     Join, using '+' as separator.
                              0e|  If the result is empty, replace it with 0.
                       
r:R,,_f{f=R'.f=.+R.e&sd}0d-'+*0e|

This won't work with the Java interpreter; it print floats differently. Try it with the CJam interpreter.

r:R                               Read a token from STDIN and save it in R.
   ,,                             Turn R (n characters) into I := [0 ... n-1].
     _                            Push a copy of I.
      f{               }          For each J in I, push J and I; then:
        f=                          Map comparison with J over I . This turns J
                                    into 1, and all other elements of I into 0's.
          R'.f=                     Map comparison with '.' over R. This turns the
                                    '.' (if present) into a 1 and all other
                                    characters of R into 0's.
               .+                   Perform vectorized sum of the Boolean arrays.
                 R.e&               Perform vectorized logical AND with R.
                                    This replaces the non-zero integer(s) with the
                                    corresponding character(s) or R.
                     sd             Cast to string, then to Double.
                        0d-       Remove all zeroes from the resulting array.
                           '+*    Join, using '+' as separator.
                              0e| If the result is empty, replace it with 0.
                       
r:R,,_f{f=R'.f=.+R.e&s~}{},'+*0e|

This won't work with the Java interpreter; it print floats differently. Try it with the CJam interpreter.

r:R                                Read a token from STDIN and save it in R.
   ,,                              Turn R (n characters) into I := [0 ... n-1].
     _                             Push a copy of I.
      f{               }           For each J in I, push J and I; then:
        f=                           Map comparison with J over I . This turns J
                                     into 1, and all other elements of I into 0's.
          R'.f=                      Map comparison with '.' over R. This turns the
                                     '.' (if present) into a 1 and all other
                                     characters of R into 0's.
               .+                    Perform vectorized sum of the Boolean arrays.
                 R.e&                Perform vectorized logical AND with R.
                                     This replaces the non-zero integer(s) with the
                                     corresponding character(s) or R.
                     s~              Cast to string and evaluate.
                        {},        Filter the array to remove zeroes.
                           '+*     Join, using '+' as separator.
                              0e|  If the result is empty, replace it with 0.
                       
deleted 24 characters in body
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading
Source Link
Dennis
  • 210.6k
  • 41
  • 370
  • 825
Loading