Entrada:
Una lista de enteros
Salida:
Coloque cada dígito (y el signo menos) en su propio carril, en el orden -0123456789
, ignorando los dígitos duplicados.
Ejemplo:
Entrada: [1,729,4728510,-3832,748129321,89842,-938744,0,11111]
Salida:
-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
Reglas de desafío:
- Cualquier dígito duplicado en el número se ignora.
- Las E / S pueden estar en cualquier formato razonable. La entrada puede ser como una lista / matriz de cadenas o una matriz de caracteres. La salida puede ser como una lista de cadenas, caracteres, matriz de caracteres, etc.
- Los espacios finales son opcionales.
- Cualquier cantidad de nuevas líneas iniciales o finales son opcionales (pero no entre líneas).
- La entrada siempre contendrá al menos un número entero
- Sin
-2,147,483,648
embargo , deberá admitir un rango entero de al menos2,147,483,647
(32 bits). - La entrada de lista no contendrá
-0
,00
(o más de dos ceros), o enteros con ceros a la izquierda (es decir012
). - Si su idioma usa un símbolo diferente para los números negativos (como un superior
¯
), también se le permite usarlo, siempre que sea coherente. - Se le permite tener un delimitador de espacio entre dígitos (por lo que puede ser una línea sin 5 u 8 en
- 0 1 2 3 4 6 7 9
lugar de-01234 67 9
), siempre que sea coherente (y, por lo tanto, también debe haber un espacio entre-
y0
).
Reglas generales:
- Este es el código de golf , por lo que la respuesta más corta en bytes gana.
No permita que los lenguajes de code-golf lo desanimen a publicar respuestas con lenguajes que no sean codegolf. Trate de encontrar una respuesta lo más breve posible para 'cualquier' lenguaje de programación. - Se aplican reglas estándar para su respuesta, por lo que puede usar STDIN / STDOUT, funciones / método con los parámetros adecuados y programas completos de tipo retorno. Tu llamada.
- Las lagunas predeterminadas están prohibidas.
- Si es posible, agregue un enlace con una prueba para su código.
- Además, agregue una explicación si es necesario.
Casos de prueba:
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
¯
lugar de-
?"-0 1 2 3 4 <space> 6 7 <space> 9"
(Los espacios se colapsan en los comentarios, por alguna razón)Respuestas:
Stax, 8 bytes
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.
Run this one
fuente
["7"]
. This format can also handle multiple values such as["34", "43"]
.05AB1E, 13 bytes
Code:
Uses the 05AB1E encoding. Try it online!
Explanation:
fuente
vðTúyvyÐd+ǝ},
;).ǝ
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 :PHaskell, 51 bytes
-1 byte thanks to Laikoni.
Try it online!
This challenge is digitist. D:
fuente
"-0123456789"
is a byte shorter than'-':['0'..'9']
.JavaScript,
5958 bytesInput & output as an array of strings.
Try it
Original
Takes input as an array of strings and outputs an array of character arrays
Show code snippet
fuente
APL (Dyalog),
3212 bytes28 bytes saved thanks to @Adám and @ngn
Try it online!
fuente
{' '@(~∊∘⍵)'¯',⎕D}¨
. Can obviously also take-
with trivial change.{⊃¨⍵∘.∩'¯',⎕d}
⊃¨⎕∘.∩'¯',⎕d
05AB1E,
1713 bytesSaved 4 bytes thanks to Adnan
Try it online!
Explanation
fuente
Ruby, 42 bytes
Anonymous lambda processing the array of numbers:
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 bytesTry it online!
Finally, the following is possible if it is acceptable for the output strings to be quoted:
Ruby
-n
, 27 bytesTry it online!
fuente
JavaScript (Node.js), 60 bytes
Try it online!
fuente
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?(X+"").includes(x)
withRegExp(x).test(X)
(X+"").match(x)
would be even shorter. The question also allows input to be an array of strings, so it could even beX.match(x)
.Japt, 16 bytes
Input & output as an array of strings.
Try it
Explanation
fuente
Python 3,
7764 bytes-12 bytes thanks to @Rod
Try it online!
My first proper attempt at golfing in Python. Advice welcome!
Returns a 2D array of characters.
fuente
'-0123456789'
insteadrange(10)
and drop the first block and swapstr(z)
withz
, you can also switch to python2 and use`y`
insteadstr(y)
(``
is +- equivalent torepr
)in "-
.Perl 5
-pl
, 33 bytesTry it online!
Takes input as line separated.
fuente
Haskell, 47 bytes
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
Try it online!
fuente
MATL, 13 bytes
Input is a cell array of strings. Try it online! Or verify all test cases.
Explanation
fuente
J,
3227 bytes-5 bytes thanks to FrownyFrog!
Try it online!
Original solution:
J, 32 bytes
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 listTry it online!
fuente
10|.":(10<."."0@[)}11$' '"0
Google Sheets, 124 bytes
Input is a comma-separated list in cell
A1
. Output is in the rangeB1:L?
where?
is however many entries were input. (You can put the formula wherever you want, I just choseB1
for convenience.) Note that Sheets will automatically add four closing parentheses to the end of the formula, saving us those four bytes.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 theMid(~)
portion but I don't know of one.)ArrayFormula(If(~))
is what makes the multi-cell references inMid(~)
andFind(~)
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.fuente
Jelly, 12 bytes
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.
fuente
Perl 6, 35 bytes
Try it online!
Output is a character matrix containing either regex matches or space characters.
fuente
-pe
would let you dispense with the initial .map, braces and swap$^a
for$_
-p
and-n
somehow seem buggy, at least on TIO. For some reason$_
isn't passed to blocks. See example 1, example 2.Java 8, 53 bytes
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.
fuente
C (gcc), 159 bytes
Try it online!
fuente
R,
9675 bytesTry 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.
fuente
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.SOGL V0.12,
1413 bytesTry it Here!
Explanation:
fuente
SNOBOL4 (CSNOBOL4), 85 bytes
Try it online!
fuente
Pyth, 14 bytes
Takes input as list of strings and outputs a list of strings for each line.
Try it here
Explanation
fuente
Retina, 26 bytes
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).fuente
Perl 5
-n
, 30 bytesWouldn't work if
-
could appear anywhere else than in the first positionTry it online!
fuente
-
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. :PRed, 94 bytes
Takes input as a block of strings
Try it online!
fuente
CJam, 20 bytes
Try it online!
Accepts input as space separated list of integers. Pretty much the same approach as @adnans answer.
fuente
C (gcc),
9594 bytesTry it online!
Input in the form of a list of strings. Output to STDOUT.
fuente
c++
, and changingd=c?c+47:
tod=c++?c+46:
.K4,
3027 bytesSolution:
Example:
Explanation:
Return "-0123..." or " " based on the input. Interpreted right-to-left. No competition for the APL answer :(
fuente
APL+WIN, 33 bytes
Prompts for screen input as a string
fuente