For Programmers: Free Programming Magazines  


Home > Archive > Fortran > December 2006 > book to obviate a grab bag of forum questions









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author book to obviate a grab bag of forum questions
lane straatman

2006-12-26, 7:09 pm

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

Terence

2006-12-26, 7:10 pm

lane straatman wrote:
> 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,


It's 1 in 17 ON AVERAGE. Beyond a critical number of hands in play
there's more chances of pairs against each other than being alone and
dominant.

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com