Wkład:
Lista liczb całkowitych
Wydajność:
Umieść każdą cyfrę (i znak minus) na swoim własnym torze, w kolejności -0123456789
, ignorując powielone cyfry.
Przykład:
Wkład: [1,729,4728510,-3832,748129321,89842,-938744,0,11111]
Wydajność:
-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
Zasady konkursu:
- Wszelkie zduplikowane cyfry w numerze są ignorowane.
- I / O może mieć dowolny rozsądny format. Dane wejściowe mogą mieć postać listy / tablicy ciągów lub tablicy znaków. Dane wyjściowe mogą być listą ciągów, znaków, macierzy znaków itp.
- Spacje końcowe są opcjonalne.
- Dowolna liczba wiodących lub końcowych nowych wierszy jest opcjonalna (ale nie między wierszami).
- Dane wejściowe zawsze będą zawierać co najmniej jedną liczbę całkowitą
- Będziesz musiał obsługiwać zakres całkowitą przynajmniej
-2,147,483,648
choć2,147,483,647
(32-bit). - Wejście-lista nigdy nie będzie zawierać
-0
,00
(lub więcej niż dwa zera) lub całkowite z wiodącymi zerami (czyli012
). - Jeśli twój język używa innego symbolu dla liczb ujemnych (jak górna
¯
), możesz również użyć tego, o ile jest on spójny. - Dozwolony jest separator spacji między cyframi (więc
- 0 1 2 3 4 6 7 9
zamiast 5 lub 8 można wstawić wiersz-01234 67 9
), o ile jest spójny (dlatego też powinna istnieć spacja między-
i0
).
Główne zasady:
- To jest golf golfowy , więc wygrywa najkrótsza odpowiedź w bajtach.
Nie pozwól, aby języki gry w golfa zniechęcały Cię do publikowania odpowiedzi w językach niekodujących golfa. Spróbuj znaleźć możliwie najkrótszą odpowiedź na „dowolny” język programowania. - Do odpowiedzi mają zastosowanie standardowe reguły , więc możesz używać STDIN / STDOUT, funkcji / metody z odpowiednimi parametrami i zwracanymi typami, pełnych programów. Twoja decyzja.
- Domyślne luki są zabronione.
- Jeśli to możliwe, dodaj link z testem swojego kodu.
- W razie potrzeby dodaj również wyjaśnienie.
Przypadki testowe:
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
¯
zamiast-
?"-0 1 2 3 4 <space> 6 7 <space> 9"
(Multiple spaces get collapsed in comments, for some reason)Odpowiedzi:
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
źródło
["7"]
. This format can also handle multiple values such as["34", "43"]
.05AB1E, 13 bytes
Code:
Uses the 05AB1E encoding. Try it online!
Explanation:
źródło
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:
źródło
"-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
źródło
APL (Dyalog),
3212 bytes28 bytes saved thanks to @Adám and @ngn
Try it online!
źródło
{' '@(~∊∘⍵)'¯',⎕D}¨
. Can obviously also take-
with trivial change.{⊃¨⍵∘.∩'¯',⎕d}
⊃¨⎕∘.∩'¯',⎕d
05AB1E,
1713 bytesSaved 4 bytes thanks to Adnan
Try it online!
Explanation
źródło
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!
źródło
JavaScript (Node.js), 60 bytes
Try it online!
źródło
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
źródło
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.
źródło
'-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.
źródło
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!
źródło
MATL, 13 bytes
Input is a cell array of strings. Try it online! Or verify all test cases.
Explanation
źródło
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!
źródło
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.źródło
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.
źródło
Perl 6, 35 bytes
Try it online!
Output is a character matrix containing either regex matches or space characters.
źródło
-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.
źródło
C (gcc), 159 bytes
Try it online!
źródło
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.
źródło
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:
źródło
SNOBOL4 (CSNOBOL4), 85 bytes
Try it online!
źródło
Pyth, 14 bytes
Takes input as list of strings and outputs a list of strings for each line.
Try it here
Explanation
źródło
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).źródło
Perl 5
-n
, 30 bytesWouldn't work if
-
could appear anywhere else than in the first positionTry it online!
źródło
-
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!
źródło
CJam, 20 bytes
Try it online!
Accepts input as space separated list of integers. Pretty much the same approach as @adnans answer.
źródło
C (gcc),
9594 bytesTry it online!
Input in the form of a list of strings. Output to STDOUT.
źródło
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 :(
źródło
APL+WIN, 33 bytes
Prompts for screen input as a string
źródło