book to obviate a grab bag of forum questions



program poker9
IMPLICIT NONE
integer, dimension(52) :: cards
integer counter, iterations
counter = 0
call random_seed()
do iterations = 1, 10000
call shuffle(cards)
call deal(cards, counter)
end do
!WRITE(*,*) cards
write(*,'(a)')"26/17=1.52941176"
write(*,'(a,i5)') "iterations= ", iterations -1
write (*,'(a,i5)') "final counter= ", counter
contains
subroutine shuffle(cards)
integer :: cards(:), ii, index
real :: numbers(size(cards))
call random_number(numbers)
do ii = 1, size(cards)
index = minloc(numbers, dim=1)
cards(ii) = index
numbers(index) = 2.0
end do
end subroutine shuffle
subroutine deal(cards, counter)
integer :: cards(:), i, counter
do i = 1, 52, 2
if (modulo(cards(i), 13).eq.modulo(cards(i+1), 13)) then
!write (*,'(a,i5,i5,i5)') "pair",i,cards(i),cards(i+1)
counter = counter + 1
end if
end do
end subroutine deal
end program
This program aims to count the number of pairs that arise when dealing
an entire deck of cards as 26 sets of hole cards, repeating the process
ten thousand times. I have a grab bag of questions every time I write
a little thing like this and think it's time that I double my fortran
library by buying another book. Richard Maine steered me in the
direction of buying MR&C, which gives the big picture, and has
consistently makes replies that stretch my game without breaking it, so
I would be particularly interested in his recommendation. I'm in the
market for a lower-level book, not pointers and bit-shifts, but a book
heavy on examples and exposition: concrete. Maybe even a workbook,
should one exist.

I think if you ask a person who plays hold 'em how often a wired pair
arises, he will tell you that it occurs more often than one in
seventeen times, as this program seems to confirm. Everyone has had
pocket queens busted by pocket kings, and maybe the severity of that
washout alters one's perception of how often it occurs. The combo here
isn't difficult: you have a total of C(52,2) hands in a
deck=52*51/2*1=1326. There's 13 ranks and C(4,2) ways to select two of
a given rank, so the numerator is 13*(4*3/2*1)=78. 78/1326=1/17. LS

.



Relevant Pages

  • Re: intrinsic elemental math functions
    ... WRITEcards ... subroutine shuffle ... The only thing I would call a dummy is 'i'. ... I think you are confusing host association and argument passing ...
    (comp.lang.fortran)
  • Re: intrinsic elemental math functions
    ... WRITEcards ... subroutine shuffle ... The only thing I would call a dummy is 'i'. ... I think you are confusing host association and argument passing ...
    (comp.lang.fortran)
  • Re: intrinsic elemental math functions
    ... WRITEcards ... subroutine shuffle ... My current fortran IDE is much less ... poker and fits in my hand when I go to play poker, but it does help to see ...
    (comp.lang.fortran)
  • Re: intrinsic elemental math functions
    ... The cards in your subroutine statement says ... that the subroutine has a dummy argument named cards. ...
    (comp.lang.fortran)
  • Re: Shuffle
    ... >Take a deck of cards in any order. ... You have randomly placed each card into the deck. ... increasing and how many decreasing after a number of iterations. ... increasing and decreasing pairs. ...
    (rec.puzzles)