Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Miniscule Poker Hand Shuffler
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MEINsweeze




PostPosted: Tue Mar 02, 2021 5:48 pm   Post subject: Miniscule Poker Hand Shuffler

another submission, this one isn't very fancy, just small!

back in high school, my friend and i wanted to know which language was more compact.

we both made programs that shuffle a deck of cards and then give you the first 5
he did his in java in about 800 bytes, i did it in turing in around 650 (3-4 years later and we both still use our respective languages for side projects lmao)

since then, i've learned so much more about turing and tuned it to the point where i've spent an hour staring at it, trying to find a chink in the armour to get rid of another byte. i can't find anything else, so i'm deciding to publish it here!

it's a minuscule 390 bytes, and is as minimalist as i could possibly make it
of course, because of its compressed size, it's nearly illegible and has terrible terrible formatting...

i'll put it here too since it's not exactly bulky!
code:
var A,B,C:=0var D:array 1..13,1..4 of boolean var G:array 1..13of string for E:1..13for F:1..4D(E,F):=true end for G(E):=intstr(E)end for G(1):="A"G(11):="J"G(12):="Q"G(13):="K"var H:array 1..4of string:=init("h","d","c","s")var I:array 1..52of string loop exit when C=52randint(B,1,4)randint(A,1,13)if D(A,B)then C+=1I(C):=G(A)+H(B)D(A,B):=false end if end loop for J:1..5put I(J)end for



picopoker.t
 Description:

Download
 Filename:  picopoker.t
 Filesize:  390 Bytes
 Downloaded:  193 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
scholarlytutor




PostPosted: Fri Mar 05, 2021 4:02 pm   Post subject: Re: Miniscule Poker Hand Shuffler

Wow, you're definitely a pro at keeping files small in terms of bytes. And it works well. The main drawback is that it's hard to read: the formatting, as you said, and also the single letter variable names. But your goal here was for the code to be compact, not readability.

I decided to challenge myself and make something similar in my 'style' of coding, and it's over 800 bytes! I'm sure I can make improvements, but I wrote it in under 30 minutes.



Card Shuffle.t
 Description:

Download
 Filename:  Card Shuffle.t
 Filesize:  857 Bytes
 Downloaded:  172 Time(s)

Worxmdom




PostPosted: Thu Jul 04, 2024 6:43 pm   Post subject: RE:Miniscule Poker Hand Shuffler

Keep up the great work with your projects!
Paystaren




PostPosted: Fri Jul 05, 2024 5:51 am   Post subject: RE:Miniscule Poker Hand Shuffler

I was doing a similar thing back in school, trying to optimize code, and every byte you cut feels like a mini victory. My friend and I once spent a whole weekend optimizing our code and ended up staying up late, fueled by a steady supply of energy drinks and snacks. At one point, we took a break and ended up at a local casino. We played a few rounds of cards and enjoyed the lively atmosphere. It was a place called Panen123 - a casino site with good vibes. While I'm more of a coding enthusiast, those random nights out really add flavor to the grind.
wtd




PostPosted: Wed Jan 01, 2025 6:34 pm   Post subject: RE:Miniscule Poker Hand Shuffler

While you've worked to optimize the byte size of your programs, both shown here are algorithmically very poor. It's very common to see people take this approach to selecting random, non-repeating samples from a finite set, but this approach of picking random cards until you get something you haven't yet drawn is not how dealing cards from a deck works at all.

This approach takes an indeterminate time to run. Might take five tries, or it might take five thousand.

The first thing you do it shuffle the finite deck of cards, and then deal the first five cards. Everything involved here has a solidly determinate runtime.

For shuffling, read up on the Fisher-Yates shuffle.
wtd




PostPosted: Wed Jan 01, 2025 6:34 pm   Post subject: RE:Miniscule Poker Hand Shuffler

While you've worked to optimize the byte size of your programs, both shown here are algorithmically very poor. It's very common to see people take this approach to selecting random, non-repeating samples from a finite set, but this approach of picking random cards until you get something you haven't yet drawn is not how dealing cards from a deck works at all.

This approach takes an indeterminate time to run. Might take five tries, or it might take five thousand.

The first thing you do it shuffle the finite deck of cards, and then deal the first five cards. Everything involved here has a solidly determinate runtime.

For shuffling, read up on the Fisher-Yates shuffle.

https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

A simple illustration in OCaml.

code:

type suit = Spade | Club | Diamond | Heart
type num = Num of int | Ace | Jack | Queen | King

let deck = Array.init 52 (fun i ->
  let n = i mod 13 in
  let s = i / 13 in
  let n = match n with
    | 12 -> Ace
    | 11 -> King
    | 10 -> Queen
    | 9 -> Jack
    | n -> Num (n+1)
  in
  let s = match[@warning "-8"] s with
    | 0 -> Spade
    | 1 -> Club
    | 2 -> Diamond
    | 3 -> Heart
  in
  (s, n)
)

let () =
  for i = 0 to 51 do
    let t = deck.(i) in
    let r = Random.int 52 in
    deck.(i) <- deck.(r);
    deck.(r) <- t
  done
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: