Digits in their lanes

32

1

Input:

A list of integers

Output:

Put each digit (and the minus sign) in its own lane, in the order -0123456789, ignoring any duplicated digits.

Example:

Input: [1,729,4728510,-3832,748129321,89842,-938744,0,11111]

Output:

-0123456789  <- Added as clarification only, it's not part of the output

  1         
   2    7 9
 012 45 78 
-  23    8 
  1234  789
   2 4   89
-   34  789
 0         
  1        

Challenge rules:

  • Any duplicated digits in the number are ignored.
  • I/O can be in any reasonable format. Input can be as a list/array of strings or character-array. Output can be as a list of strings, characters, character-matrix, etc.
  • Trailing spaces are optional.
  • Any amount of leading or trailing new-lines are optional (but not in between lines).
  • Input will always contain at least one integer
  • You'll have to support an integer range of at least -2,147,483,648 though 2,147,483,647 (32-bit).
  • The input-list will never contain -0, 00 (or more than two zeroes), or integers with leading zeroes (i.e. 012).
  • If you language uses a different symbol for negative numbers (like an upper ¯), you are also allowed to use that instead, as long as it's consistent.
  • You are allowed to have a space delimiter between digits (so a line without 5 or 8 can be - 0 1 2 3 4 6 7 9 instead of -01234 67 9), as long as it's consistent (and therefore there should also be a space between - and 0).

General rules:

  • This is , so shortest answer in bytes wins.
    Don't let code-golf languages discourage you from posting answers with non-codegolfing languages. Try to come up with an as short as possible answer for 'any' programming language.
  • Standard rules apply for your answer, so you are allowed to use STDIN/STDOUT, functions/method with the proper parameters and return-type, full programs. Your call.
  • Default Loopholes are forbidden.
  • If possible, please add a link with a test for your code.
  • Also, please add an explanation if necessary.

Test cases:

Input: [1,729,4728510,-3832,748129321,89842,-938744,0,11111]
Output:
  1         
   2    7 9
 012 45 78 
-  23    8 
  1234  789
   2 4   89
-   34  789
 0         
  1        

Input: [4,534,4,4,53,26,71,835044,-3559534,-1027849356,-9,-99,-3459,-3459,-94593,-10234567859]
Output:
      4     
     345    
      4     
      4     
     3 5    
    2   6   
   1     7  
  0  345  8 
 -   345   9
 -0123456789
 -         9
 -         9
 -   345   9
 -   345   9
 -   345   9
 -0123456789

Input: [112,379,-3,409817,239087123,-96,0,895127308,-97140,923,-748]
Output:
  12       
   3    7 9
-  3       
 01 4   789
 0123   789
-      6  9
 0         
  123 5 789
-01  4  7 9
   23     9
-    4  78 

Input: [-15,-14,-13,-12,-11,10,-9,-8,-7,-5,-4,-3,-1,0,9,100,101,102,1103,104,105,106,116,-12345690]
Output:
- 1   5    
- 1  4     
- 1 3      
- 12       
- 1        
-01        
-         9
-        8 
-       7  
-     5    
-    4     
-   3      
- 1        
 0         
          9
 01        
 01        
 012       
 01 3      
 01  4     
 01   5    
 01    6   
  1    6   
-0123456  9

Input: [99,88,77,66,55,44,33,22,11,10,0,0,0,-941]
Output:
          9
         8 
        7  
       6   
      5    
     4     
    3      
   2       
  1        
 01        
 0         
 0         
 0         
- 1  4    9

Kevin Cruijssen

Posted 2018-03-27T10:51:08.043

Reputation: 67 575

Would spaces between the digits be permitted in the output? – Shaggy – 2018-03-27T11:33:54.120

Can we use upper minus ¯ instead of -? – Uriel – 2018-03-27T11:33:56.123

The missing digits would still be replaced with spaces so, in your example, there would be 3 spaces between 4 & 6 and 7 & 9: "-0 1 2 3 4 <space> 6 7 <space> 9" (Multiple spaces get collapsed in comments, for some reason) – Shaggy – 2018-03-27T11:43:31.250

1I was hoping to sneak that one past you! :D Well-spotted! – Shaggy – 2018-03-27T11:48:03.227

can I take the inputs as separate inputs and a count of the amount of them? – dzaima – 2018-03-27T13:54:54.030

@dzaima Sure, why not. – Kevin Cruijssen – 2018-03-27T13:58:30.073

Words in their lanes? - Another decent challenge spin-off idea. Even letters in their lanes would be cool. – Magic Octopus Urn – 2018-03-27T22:42:14.420

May we place negative signs on the far right? Especially relevant if using a Unicode symbol which comes after 9. – Adám – 2018-03-28T11:05:30.410

@Adám Sorry but no, the - (or any other character representing -) must be on the left. – Kevin Cruijssen – 2018-03-28T11:07:16.617

1related – streetster – 2018-03-28T18:29:58.850

@streetster Ah, I remember that challenge. It's indeed pretty similar. Btw, why did you link to your answer instead of the challenge itself? ;) – Kevin Cruijssen – 2018-03-28T18:32:45.307

Oops, was browsing through my answers to find the challenge, wasn't paying enough attention to the actual url! – streetster – 2018-03-28T21:01:48.893

@Adám Well, the minus goes to the left, doesn't it? :P – Erik the Outgolfer – 2018-03-30T12:41:35.410

Answers

4

Stax, 8 bytes

║V≡u╝─é╢

Run and debug it

It takes one number per line on standard input. It works by finding the target index of each character and assigning it into that index of the result. If the index is out of bounds, the array is expanded with zeroes until it fits. During output, 0 becomes a space. The rest are character codes.

Unpacked, ungolfed, and commented, this is what it looks like.

m       for each line of input, execute the rest of the program and print the result
 zs     put an empty array under the line of input
 F      for each character code in the line of input, run the rest of the program
  Vd    "0123456789"
  I^    get the index of the character in this string and increment
  _&    assign this character to that index in the original string

Run this one

recursive

Posted 2018-03-27T10:51:08.043

Reputation: 8 616

How is one meant to input a list of length one? (If it is just the value or the value and a new line it does not work.) – Jonathan Allan – 2018-03-30T12:01:13.563

1Oh yes, good point. An alternate form of input that also works for single values is ["7"]. This format can also handle multiple values such as ["34", "43"]. – recursive – 2018-03-30T15:29:28.813

6

05AB1E, 13 bytes

Code:

v'-žh«DyмSð:,

Uses the 05AB1E encoding. Try it online!

Explanation:

v               # For each element in the input..
 '-žh«          #   Push -0123456789
      D         #   Duplicate this string
       yм       #   String subtraction with the current element
                    e.g. "-0123456789" "456" м  →  "-0123789"
         Sð:    #   Replace all remaining elements with spaces
                    e.g. "-0123456789" "-0123789" Sð:  →  "     456   "
            ,   #   Pop and print with a newline

Adnan

Posted 2018-03-27T10:51:08.043

Reputation: 41 965

1Nice! Going the replace-route was shorter than the insert-route I see :) – Emigna – 2018-03-27T11:02:49.553

2

@Emigna The insert-route is also a very interesting approach. In fact, I think you can save 4 bytes with vðTúyvyÐd+ǝ}, ;).

– Adnan – 2018-03-27T11:24:39.747

1Brilliant! I didn't know ǝ would function like that on -0. But now that I tihnk of it, that's actually a number and not a string as I first read it as :P – Emigna – 2018-03-27T11:36:29.410

Ooooof... I was at 23bytes. The 05AB1E (pun on the humanity). – Magic Octopus Urn – 2018-03-27T22:23:24.717

4

Haskell, 51 bytes

-1 byte thanks to Laikoni.

f l=[[last$' ':[n|n`elem`i]|n<-"-0123456789"]|i<-l]

Try it online!

This challenge is digitist. D:

totallyhuman

Posted 2018-03-27T10:51:08.043

Reputation: 15 378

"-0123456789" is a byte shorter than '-':['0'..'9']. – Laikoni – 2018-03-27T12:19:00.367

4

APL (Dyalog), 32 12 bytes

28 bytes saved thanks to @Adám and @ngn

⊃¨⎕∘.∩'¯',⎕d

Try it online!

Uriel

Posted 2018-03-27T10:51:08.043

Reputation: 11 708

1

Same idea, 15: {' '@(~∊∘⍵)'¯',⎕D}¨. Can obviously also take - with trivial change.

– Adám – 2018-03-28T11:19:35.630

{⊃¨⍵∘.∩'¯',⎕d} – ngn – 2018-03-28T15:38:42.920

or even ⊃¨⎕∘.∩'¯',⎕d – ngn – 2018-03-28T15:48:22.497

4

JavaScript, 59 58 bytes

Input & output as an array of strings.

a=>a.map(x=>`-0123456789`.replace(eval(`/[^${x}]/g`),` `))

Try it

o.innerText=(g=s=>(f=
a=>a.map(x=>`-0123456789`.replace(eval(`/[^${x}]/g`),` `))
)(s.split`,`).join`\n`)(i.value="1,729,4728510,-3832,748129321,89842,-938744,0,11111");oninput=_=>o.innerText=g(i.value)
input{width:100%;}
<input id=i><pre id=o></pre>


Original

Takes input as an array of strings and outputs an array of character arrays

a=>a.map(x=>[...`-0123456789`].map(y=>-~x.search(y)?y:` `))

o.innerText=(g=s=>(f=
a=>a.map(x=>[...`-0123456789`].map(y=>-~x.search(y)?y:` `))
)(s.split`,`).map(x=>x.join``).join`\n`)(i.value="1,729,4728510,-3832,748129321,89842,-938744,0,11111");oninput=_=>o.innerText=g(i.value)
input{width:100%;}
<input id=i><pre id=o></pre>

Shaggy

Posted 2018-03-27T10:51:08.043

Reputation: 24 623

1such an elegant solution, i really like it. – Brian H. – 2018-03-28T13:02:52.867

3

05AB1E, 17 13 bytes

Saved 4 bytes thanks to Adnan

vðTúyvyÐd+ǝ},

Try it online!

Explanation

v               # loop over elements y in input
 ðTú            # push a space prepended by 10 spaces
    yv          # for each element y in the outer y
      y         # push y
       Ðd+      # push y+isdigit(y)
          ǝ     # insert y at this position in the space-string
           }    # end inner loop
            ,   # print

Emigna

Posted 2018-03-27T10:51:08.043

Reputation: 50 798

3

Ruby, 42 bytes

Anonymous lambda processing the array of numbers:

->a{a.map{|n|"-0123456789".tr"^#{n}",?\s}}

Try it online!

Alternatively, a completely Perl-like full program is much shorter. I'd say -pl switches look quite funny in this context:

Ruby -pl, 29 bytes

$_="-0123456789".tr"^#$_"," "

Try it online!

Finally, the following is possible if it is acceptable for the output strings to be quoted:

Ruby -n, 27 bytes

p"-0123456789".tr ?^+$_,?\s

Try it online!

Kirill L.

Posted 2018-03-27T10:51:08.043

Reputation: 6 693

3

JavaScript (Node.js), 60 bytes

  • Thank to @Andrew Taylor for reducing the join (8 chars)
  • Thank to @Yair Rand for X.match (8 chars)
a=>a.map(X=>"-0123456789".replace(/./g,x=>X.match(x)?x:" "))

Try it online!

DanielIndie

Posted 2018-03-27T10:51:08.043

Reputation: 1 220

Oh, that join trick is lovely — but the question reads like an array of strings is OK output so maybe you can shave 8 bytes by removing it? – Andrew Taylor – 2018-03-28T07:34:28.660

Pretty sure you can save another by replacing (X+"").includes(x) with RegExp(x).test(X) – Andrew Taylor – 2018-03-28T07:34:59.333

(X+"").match(x) would be even shorter. The question also allows input to be an array of strings, so it could even be X.match(x) . – Yair Rand – 2018-03-29T05:51:36.083

2

Japt, 16 bytes

Input & output as an array of strings.

£Ao ¬i- ®iS gXøZ

Try it


Explanation

£                    :Map over each element X
 Ao                  :  Range [0,10)
    ¬                :  Join to a string
     i-              :  Prepend "-"
        ®            :  Map over each character Z
         iS          :    Prepend a space
            g        :    Get the character at index
             XøZ     :      X contains Z? (true=1, false=0)

Shaggy

Posted 2018-03-27T10:51:08.043

Reputation: 24 623

2

Python 3, 77 64 bytes

-12 bytes thanks to @Rod

lambda x:[[[" ",z][z in str(y)]for z in"-0123456789"]for y in x]

Try it online!

My first proper attempt at golfing in Python. Advice welcome!

Returns a 2D array of characters.

Jo King

Posted 2018-03-27T10:51:08.043

Reputation: 38 234

1You can use '-0123456789' instead range(10) and drop the first block and swap str(z) with z, you can also switch to python2 and use \y`` instead str(y) (\`` is +- equivalent to repr) – Rod – 2018-03-27T12:25:33.433

Superfluous space in in "-. – Jonathan Frech – 2018-03-27T12:53:40.523

2

MATL, 13 bytes

"45KY2ht@gm*c

Input is a cell array of strings. Try it online! Or verify all test cases.

Explanation

         % Implicit input: cell array of strings, for example {'1','729',...,'11111'}
"        % For each cell
  45     %   Push 45 (ASCII code of '-')
  KY2    %   Push predefined literal '0123456789'
  h      %   Concatenate horizontally: gives '-0123456789'
  t      %   Duplicate
  @      %   Push current cell, for example {'729'}
  g      %   Convert cell to matrix. This effectively gives the cell's contents, '729'
  m      %   Ismember: gives an array of zeros and ones indicating membership of each
         %   char from '-0123456789' in '729'. The result in the example is
         %   [0 0 0 1 0 0 0 0 1 0 1]
  *      %   Multiply, element-wise. Chars are implicity converted to ASCII 
         %   Gives the array [0 0 0 50 0 0 0 0 55 0 57] 
  c      %   Convert ASCII codes to chars. 0 is displayed as space. Gives the string
         %   '   2    7 9'
         % Implicit end
         % Implicilly display each string on a different line

Luis Mendo

Posted 2018-03-27T10:51:08.043

Reputation: 87 464

2

Perl 5 -pl, 33 bytes

$_=eval"'-0123456789'=~y/$_/ /cr"

Try it online!

Takes input as line separated.

Xcali

Posted 2018-03-27T10:51:08.043

Reputation: 7 671

2

Jelly, 12 bytes

ØD”-;¹⁶e?€Ʋ€

Try it online!

-2 thanks to Jonathan Allan reading a rule I didn't.

Note that the I/O format used in the TIO link is not the actual one, which is input as a list of string representations and output as a list of lines.

Erik the Outgolfer

Posted 2018-03-27T10:51:08.043

Reputation: 38 134

2

J, 32 27 bytes

-5 bytes thanks to FrownyFrog!

10|.":(10<."."0@[)}11$' '"0

Try it online!

Original solution:

J, 32 bytes

(('_0123456789'i.[)}11$' '"0)@":

Explanation:

@": convert to characters and

}11$' '"0 change the content of an array of 11 spaces to these characters

'_0123456789'i.[ at the places, indicated by the indices of the characters in this list

Try it online!

Galen Ivanov

Posted 2018-03-27T10:51:08.043

Reputation: 13 815

110|.":(10<."."0@[)}11$' '"0 – FrownyFrog – 2018-03-28T11:48:19.950

@FrownyFrog Nice solution, thanks! – Galen Ivanov – 2018-03-28T12:08:28.977

2

Google Sheets, 124 bytes

=Transpose(ArrayFormula(If(IsError(Find(Mid("-0123456789",Row($1:$11),1),Split(A1,",")))," ",Mid("-0123456789",Row($1:$11),1

Input is a comma-separated list in cell A1. Output is in the range B1:L? where ? is however many entries were input. (You can put the formula wherever you want, I just chose B1 for convenience.) Note that Sheets will automatically add four closing parentheses to the end of the formula, saving us those four bytes.

Screenshot

Another test case and another test case

Explanation:

  • Mid("-0123456789",Row($1:$11),1) picks out each of the 11 characters in turn.
  • Find(Mid(~),Split(A1,",")) looks for those characters in each of the input elements. This either returns a numeric value or, if it's not found, an error.
  • If(IsError(Find(~)," ",Mid(~)) will return a space if the character wasn't found or the character if it was. (I wish there was a way to avoid duplicating the Mid(~) portion but I don't know of one.)
  • ArrayFormula(If(~)) is what makes the multi-cell references in Mid(~) and Find(~) work. It's also what makes a formula in one cell return values in multiple cells.
  • Transpose(ArrayFormula(~)) transpose the returned array because it starts off sideways.

Engineer Toast

Posted 2018-03-27T10:51:08.043

Reputation: 5 769

2

Haskell, 47 bytes

map(\s->do d<-"-0123456789";max" "[d|elem d s])

Try it online!

Uses max to insert a space where no element exist, since a space is smaller than any digit or minus sign.

If an ungodly number of trailing spaces is OK, two bytes can be saved:

45 bytes

map(\s->do d<-'-':['0'..];max" "[d|elem d s])

Try it online!

xnor

Posted 2018-03-27T10:51:08.043

Reputation: 115 687

1

Perl 6, 35 bytes

{.map:{map {m/$^a/||' '},'-',|^10}}

Try it online!

Output is a character matrix containing either regex matches or space characters.

nwellnhof

Posted 2018-03-27T10:51:08.043

Reputation: 10 037

If 'input can be in any reasonable format' could be stdin, then presumably -pe would let you dispense with the initial .map, braces and swap $^a for $_ – Phil H – 2018-03-27T12:56:37.210

@PhilH -p and -n somehow seem buggy, at least on TIO. For some reason $_ isn't passed to blocks. See example 1, example 2.

– nwellnhof – 2018-03-27T14:23:47.337

1

R, 96 75 bytes

for(i in scan())cat(paste(gsub(paste0("[^",i,"]")," ","-0123456789"),"\n"))

Try it online!

Thanks to Kevin Cruijssen for suggesting this regex approach!

Takes input from stdin as whitespace separated integers, and prints the ascii-art to stdout.

Giuseppe

Posted 2018-03-27T10:51:08.043

Reputation: 21 077

I don't know R too well, so I'm sure it can be golfed further, but this different approach is 12 bytes shorter: function(N)for(i in N)cat(paste(gsub(paste("[^","]",sep=i)," ","-0123456789"),"\n")). (Input as string-array instead of integer-array.) Try it online.

– Kevin Cruijssen – 2018-03-27T12:10:29.667

@KevinCruijssen ah, nice, yeah, I can golf that down as well. – Giuseppe – 2018-03-27T12:20:34.237

1

Java 8, 53 bytes

a->a.map(i->"-0123456789".replaceAll("[^"+i+"]"," "))

My own challenge is easier than I thought it would be when I made it..

Input and output both as a java.util.stream.Stream<String>.

Explanation:

Try it online.

a->                              // Method with String-Stream as both input and return-type
  a.map(i->                      //  For every String in the input:
    "-0123456789"                //   Replace it with "-0123456789",
    .replaceAll("[^"+i+"]"," ")) //   with every character not in `i` replaced with a space

Kevin Cruijssen

Posted 2018-03-27T10:51:08.043

Reputation: 67 575

1

C (gcc), 159 bytes

f(A,l,j,k,b)long*A,k;{char*s,S[99];for(j=~0;++j<l;puts(""))for(sprintf(S,"%ld",k=A[j]),putchar(k<0?45:32),k=47;++k<58;putchar(b?32:k))for(b=s=S;*s;b*=*s++-k);}

Try it online!

Jonathan Frech

Posted 2018-03-27T10:51:08.043

Reputation: 6 681

1

SOGL V0.12, 14 13 bytes

{ø,{²²⁴WI1ž}P

Try it Here!

Explanation:

{ø,{²²⁴WI1ž}P

{            repeat input times
 ø,            push an empty string and the next input above that
   {       }   for each character in the input
    ²²           push "0123456789"
      ⁴          copy the character on top
       W         and get it's index in that string (1-indexed, 0 for the non-existent "-")
        I        increment that (SOGL is 1-indexed, so this is required)
         1ž      at coordinates (index; 1) in the string pushed earlier, insert that original copy of the character
            P  print the current line

dzaima

Posted 2018-03-27T10:51:08.043

Reputation: 19 048

1

SNOBOL4 (CSNOBOL4), 85 bytes

I	X =INPUT	:F(END)
	S ='-0123456789'
R	S NOTANY(X ' ') =' '	:S(R)
	OUTPUT =S	:(I)
END

Try it online!

I	X =INPUT	:F(END)		;* read input, if none, goto end
	S ='-0123456789'		;* set the string
R	S NOTANY(X ' ') =' '	:S(R)	;* replace characters of S not in X + space with space
	OUTPUT =S	:(I)		;* print S, goto I
END

Giuseppe

Posted 2018-03-27T10:51:08.043

Reputation: 21 077

1

Pyth, 14 bytes

VQm*d}dNs+\-UT

Takes input as list of strings and outputs a list of strings for each line.
Try it here

Explanation

VQm*d}dNs+\-UT
VQ                For each string in the input...
  m     s+\-UT    ... and each character in "-0123456789"...
     }dN          ... check if the character is in the string...
   *d             ... and get that character or an empty string.

user48543

Posted 2018-03-27T10:51:08.043

Reputation:

1

Retina, 26 bytes

%"-0123456789"~`.+
[^$&]¶ 

Try it online! Note: Trailing space. Explanation: % executes its child stage ~ once for each line of input. ~ first executes its child stage, which wraps the line in [^ and ]<CR><SP>, producing a program that replaces characters not in the line with spaces. The "-0123456789" specifies that the input to that program is the given string ($ substitutions are allowed but I don't need them).

Neil

Posted 2018-03-27T10:51:08.043

Reputation: 95 035

1

Perl 5 -n, 30 bytes

Wouldn't work if - could appear anywhere else than in the first position

#!/usr/bin/perl -n
say"-0123456789"=~s/[^$_]/ /gr

Try it online!

Ton Hospel

Posted 2018-03-27T10:51:08.043

Reputation: 14 114

Wouldn't work if - could appear anywhere else than in the first position if that can be true then you are not answering this challenge, since they wouldn't be integers anymore. :P – Erik the Outgolfer – 2018-03-27T17:55:04.997

1

Red, 94 bytes

func[b][foreach a b[s: copy"           "foreach c a[s/(index? find"-0123456789"c): c]print s]]

Takes input as a block of strings

Try it online!

Galen Ivanov

Posted 2018-03-27T10:51:08.043

Reputation: 13 815

1

CJam, 20 bytes

qS%{'-10,+s_@-SerN}/

Try it online!

Accepts input as space separated list of integers. Pretty much the same approach as @adnans answer.

Marcos

Posted 2018-03-27T10:51:08.043

Reputation: 171

1

C (gcc), 95 94 bytes

c,d;f(l,n)char**l;{for(;n--;l++)for(c=0;c<12;)putchar(strchr(*l,d=c++?c+46:45)?d:d^58?32:10);}

Try it online!

Input in the form of a list of strings. Output to STDOUT.

gastropner

Posted 2018-03-27T10:51:08.043

Reputation: 3 264

You can golf a byte by removing the c++, and changing d=c?c+47: to d=c++?c+46:. – Kevin Cruijssen – 2018-03-28T10:02:57.427

1

K4, 30 27 bytes

Solution:

{?[a in$x;a:"-",.Q.n;" "]}'

Example:

q)k){?[a in$x;a:"-",.Q.n;" "]}'1 729 4728510 -3832 748129321 89842 -938744 0 11111
"  1        "
"   2    7 9"
" 012 45 78 "
"-  23    8 "
"  1234  789"
"   2 4   89"
"-   34  789"
" 0         "
"  1        "

Explanation:

Return "-0123..." or " " based on the input. Interpreted right-to-left. No competition for the APL answer :(

{?[a in$x;a:"-",.Q.n;" "]}' / the solution
{                        }' / lambda for each
 ?[      ;          ;   ]   / if[cond;true;false]
                .Q.n        / string "0123456789"
            "-",            / join with "-"
          a:                / save as a
       $x                   / convert input to string
   a in                     / return boolean list where each a in x
                     " "    / whitespace (return when false)

streetster

Posted 2018-03-27T10:51:08.043

Reputation: 3 635

0

APL+WIN, 33 bytes

Prompts for screen input as a string

n←11⍴' '⋄n['-0123456789'⍳s]←s←⎕⋄n

Graham

Posted 2018-03-27T10:51:08.043

Reputation: 3 184

0

Haskell, 49 bytes

map$(<$>"-0123456789").(%)
i%n|elem n i=n|1<3=' '

The first line defines an anonymous function which takes a list of strings and returns a list of strings. Try it online!

Laikoni

Posted 2018-03-27T10:51:08.043

Reputation: 23 676

0

Javascript 95 bytes

(a,t='-0123456789')=>a.map(a=>a+'').map(_=>[...t].map(b=>_.search(b)>=0?b:' ').join``).join`\n`

f=(a,t='-0123456789')=>a.map(a=>a+'').map(_=>[...t].map(b=>_.search(b)>=0?b:' ').join``).join`\n`

console.log(f([1,729,4728510,-3832,748129321,89842,-938744,0,11111]))

console.log(f([4,534,4,4,53,26,71,835044,-3559534,-1027849356,-9,-99,-3459,-3459,-94593,-10234567859]))

Luis felipe De jesus Munoz

Posted 2018-03-27T10:51:08.043

Reputation: 9 639

1a=>a.map(a=>a+'').map(=>[...'-0123456789'].map(b=>.search(b)+1?b:' ').join``).join outer join just use enter instead of \n. you dont need t just put the string there. this is a 87 solution – DanielIndie – 2018-03-27T14:32:55.200

0

ShellUtils, 85 bytes

There must be a better way of escaping the {} rather than using a double echo and piping through bash

xargs -i echo echo \\-0123456789 \|tr \$\(echo .0123456789- \|tr -d -- {} \) \' \'|sh

This takes the strings, one per line, from stdlin The inner tr takes -0123456789 and removes what's not in the input line. The {} represents this.

The second tr takes that output, and converts -0123456789 by replacing the input characters with spaces.

CSM

Posted 2018-03-27T10:51:08.043

Reputation: 219