QBasic 4.5, (削除) 114 (削除ここまで) (削除) 142 (削除ここまで) 127 bytes
dim r$(54)
FOR i=1TO 52
m=i MOD 13
r$(i)=MID$("JQKA2345678910",1+m,1-(m=12))+MID$("CDHS",(i-1)13円+1,1)
NEXT
r$(53)="J
r$(54)="J
Release Notes:
- V1.0 Initial deploy
- V1.1 Misread the challenge requirements, so switched to a more expensive array
r$. All the rest of the code is pretty much the same. - V1.2 Suggestions from @TaylorScott lead to a complete rewrite saving 15 bytes!
Sample output
If we add this snippet to our code, we can see what is put into r$:
for i = 1 to ubound(r$)
?r$(i)
next
QC
KC
AC
2C
3C
4C
5C
6C
7C
8C
9C
10C
JC
QD
KD
AD
[... snip ...]
6S
7S
8S
9S
10S
JS
J
J
But how? Well, let me tell you:
dim r$(54) ' create a 54-slot array for our results
FOR i=1TO 52 ' Loop through the numbers 1-52 in var i
m=i MOD 13 ' Take i mod 13 to select a value (saved as m)
' , and (not saved) i intdiv 13 to get a suit
r$(i)= ' assigns to slot i in the result array
MID$("JQKA2345678910" ' a substring from the string with all the values
,1+m ' from position 1-13 (13 % 13 = 0, but QBasic strings are 1-based.
' Hence the + 1)
,1-(m=12)) ' taking 1 char by default, and 2 for the Ten
' Note that m=12 evaluates to 0 for 0-11, and to -1 for 12
+ MID$("CDHS",(i-1)13円+1,1) ' and take 1 char from the suits-string
NEXT
r$(53)="J ' Then append 2 jokers
r$(54)="J ' These strings are auto-closed by the QBasic compiler.
steenbergh
- 8.2k
- 1
- 27
- 43