| Bytes | Lang | Time | Link |
|---|---|---|---|
| 026 | Ruby | 180618T112429Z | G B |
| 3026 | PowerShell 3.0 | 180618T224748Z | Veskah |
| 044 | Red | 180619T075255Z | Galen Iv |
| 018 | Perl 6 | 180618T122300Z | Jo King |
| 004 | Jelly | 180618T171720Z | Jonathan |
| 004 | Japt | 180618T115445Z | Shaggy |
| 031 | TSQL | 180618T162920Z | BradC |
| 027 | JavaScript | 180618T153520Z | vityavv |
| 035 | JavaScript | 180618T140536Z | The rand |
| 021 | Python 3 | 180618T133822Z | G B |
| 005 | 05AB1E | 180618T121138Z | Kevin Cr |
| 008 | Charcoal | 180618T122422Z | Neil |
| 065 | Java 10 | 180618T114855Z | Kevin Cr |
Ruby, 28 26 bytes
->x{x.map{x[($.+=17)%54]}}
Today I decided to have a look at this problem again, and I could shave 3 5 bytes from the previous solution (reported below).
Ruby, 31 bytes
->x{(0..53).map{|r|x[r*17%54]}}
Explanation:
I'm picking one card, then skipping over the next 16 and start from the first card when I reach the last card of the deck. 17 and 54 are mutually prime, so I'm sure to pick all cards.
The 17th position is guaranteed to be a different suit and the difference in value is at least 2: the 13th (or 15th) card has the same value and a different suit, so by skipping other 4 (or 2), the value is right.
PowerShell 3.0, 30 26 Bytes
$args[(0..53|%{$_*17%54})]
-4 thanks to Mazzy
Old code at 30 bytes
param($d)0..53|%{$d[$_*17%54]}
Another port of G B's method.
Red, 44 bytes
func[a][append/dup a a 16 prin extract a 17]
Another interpetation of G B's code. I append 16 copies of the deck to itself and then extract each 17th card.
Perl 6, 21 20 18 bytes
Thanks to Brad Gilbert b2gills for -2 bytes
{.[$++*17%$_]xx$_}
Yet another port of G B's answer. Note that, while the global variable However, $! is not reset between functions, the value doesn't matter, since any order of the output is valid.$ is reset.
Explanation:
{ } #Anonymous code block
xx$_ #Repeat size of inputted array (54) times
.[ ] #Get from the inputted array, the value at index
$++*17%$_ #The incremented variable, multiplied by 17, modded by size of the array
Jelly, 5 4 bytes
s⁴ZẎ
Turns out the way everyone else everyone else except The random guy is doing it saves a byte :(
Credit to G B for their method.
The way I went...
ṙÐe20
How?
Fix every other card and intersperse it with a rotation of the deck left by 20 places (18 and 22 places also work; furthermore so does either direction of rotation as well as fixing either odd or even cards)
ṙÐe20 - Link: list of the card strings (lists of characters)
20 - place a literal twenty on the right
Ðe - apply to even indices:
ṙ - rotate left (by 20)
That is (using T for 10 and rj & bj for the Js):
input: AS 2S 3S 4S 5S 6S 7S 8S 9S TS JS QS KS AD 2D 3D 4D 5D 6D 7D 8D 9D TD JD QD KD AH 2H 3H 4H 5H 6H 7H 8H 9H TH JH QH KH AC 2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC rj bj
ṙ20: 8D 9D TD JD QD KD AH 2H 3H 4H 5H 6H 7H 8H 9H TH JH QH KH AC 2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC rj bj AS 2S 3S 4S 5S 6S 7S 8S 9S TS JS QS KS AD 2D 3D 4D 5D 6D 7D
ṙÐe20: AS 9D 3S JD 5S KD 7S 2H 9S 4H JS 6H KS 8H 2D TH 4D QH 6D AC 8D 3C TD 5C QD 7C AH 9C 3H JC 5H KC 7H bj 9H 2S JH 4S KH 6S 2C 8S 4C TS 6C QS 8C AD TC 3D QC 5D rj 7D
Japt, 6 5 4 bytes
Splits the input array into sub-arrays of every 16th element and flattens.
óG c
T-SQL, 31 bytes
SELECT c FROM t ORDER BY i*7%54
If you don't care about an extra column in the output I can get it down to 29 bytes:
SELECT*FROM t ORDER BY i*7%54
So you can verify my output is "Superb", here is the deck it produces:
J, 5H, 8S, KH, 3D, 8C, JD, AS, 6H, 9S, AC, 4D, 9C, QD,
2S, 7H, 10S, 2C, 5D, 10C, KD, 3S, 8H, JS, 3C, 6D, JC,
AH, 4S, 9H, QS, 4C, 7D, QC, 2H, 5S, 10H, KS, 5C, 8D,
KC, 3H, 6S, JH, AD, 6C, 9D, J, 4H, 7S, QH, 2D, 7C, 10D
(Generated using the new SQL 2017 addition, STRING_AGG):
SELECT STRING_AGG(c,', ')WITHIN GROUP(ORDER BY i*7%54)FROM t
The hard part for me was not the select code, it was populating the input table (which is allowed for SQL per our IO rules).
Because SQL is inherently unordered (it only guarantees a certain order if you include an explicit ORDER BY clause), I had to include that original order as a field i in the input table t. This also means I can use it to sort, using the same "relatively prime" factor/mod process everyone else is using. I found that i*7%54 worked just as well as i*17%54.
Here are the commands to set up and populate the input table t, based on my solution to this related question:
CREATE TABLE t (i INT IDENTITY(1,1), c VARCHAR(5))
--Insert 52 suited cards
INSERT t(c)
SELECT v.value+s.a as c
FROM STRING_SPLIT('A-2-3-4-5-6-7-8-9-10-J-Q-K','-')v,
(VALUES('S',1),('D',2),('H',3),('C',4))s(a,b)
ORDER BY s.b
--Insert Jokers
INSERT t(c) SELECT 'J'
INSERT t(c) SELECT 'J'
JavaScript, 27
Another one based off of the ruby answer
d=>d.map((_,i)=>d[i*17%54])
Edited in an obvious shortening
JavaScript, 35 bytes
x=>x.map((a,i)=>i%2?a:x[(i+20)%54])
Taking an array of deck as input, and replacing each odd value with another card that is "20 cards" away on the deck.
Python 3, 21 bytes
lambda x:(x*17)[::17]
Explanation:
The same idea as my Ruby answer, but even shorter in Python: I use 17 decks, and pick every 17th card.
05AB1E, 9 7 5 bytes
ā17*è
Port of @GB's Ruby answer, so make sure to upvote him!
-2 bytes by printing each card with a new-line delimiter instead of wrapping it to a result-list
-2 bytes thanks to @Mr.Xcoder
Explanation:
ā # 1-indexed length range [1 ... length_of_input_list (54)]
17* # `k`: Multiply each index by 17
è # And then replace each item with the 0-indexed `k`'th card of the input-list
# (with automatic wrap-around)
Charcoal, 8 bytes
Eθ§θ×¹⁷κ
Try it online! Link is to verbose version of code. Another port of @GB's Ruby answer. Explanation:
θ Input array
E Map over elements
κ Current index
¹⁷ Literal 17
× Multiply
θ Input array
§ Cyclically index
Implicitly print each result on its own line
Java 10, 72 65 bytes
d->{var r=d.clone();for(int i=54;i-->0;r[i*7%54]=d[i]);return r;}
Similar as @GB's Ruby answer, but by using i*7%54 on the result-array, instead of i*17%54 on the input-array to save a byte.
Explanation:
d->{ // Method with String-array as both parameter and return-type
var r=d.clone();// Result-String, starting as a copy of the input
for(int i=54;i-->0;
// Loop `i` in the range (54, 0]
r[ // Set an item in the result-array at index:
i*7%54 // Index `i` multiplied by 7, and then take modulo-54
]=d[i]); // To the `i`'th item in the input-Deck
return r;} // Return the result-Array