You are on page 1of 5

program Edulakanti; {This program is named by my lastname - Edulakanti}

{
################################# Student Info ################################
#######
Name: Sridhar Vineeth Goud Edulakanti
UIN: 674663737
CSC 540C, Assignment HW3
###############################################################################
########
}
{
############################# Program Details ##################################
#########
NAME OF THE PROGRAM : Roulette
DESCRIPTION : In this game, players may choose to place bets on either a single
number or a range of numbers, the colors red or black, or whether
the number is odd or even.
A Roulette Wheel that contains numbers ranging from 0 to 36 is
spinned and a ball
is then dropped onto the wheel. The ball lands on a number and
numbers play Major Role in the game. Here, in this code, this numb
er
is generated randomly using a code snipped of the Random Number
Generator and the number of spins to be performed are to be entere
d
by the user.
The Problem Statement(as quoted in the Problem Definition) require
s
the following Calculations to be performed:
1. How often could a number be generated up to two times in a row on
an average and also that how often could the number be generated
up to three times in a row.
2. When a particular number is chosen at random, determine how many
times would it be generated twice in a row ? (Suppose a random num
ber
be 13, etc)
3. The longest run of Evens and Odds in a row in one program simulati
on
needs to be determined.
################################################################################
###########
}
uses crt; {#### This Program uses the crt Library ####}
{
######################## Details of the Declared Variables ####################
##########

The Variables are Declared in respective Datatypes.


num_wheel is used to define the Numbers on the Wheel.
rand is used to define the Random Numbers.
num_spins is used to define the Number of Spins.
temp is used to Temporarily Store the Numbers.
temp_gap is used to keep the Track of the Number of Spins.
even_count, odd_count are used to Store the Even and Odd Number Count in a Loop.
even_max, odd_max are used to Store the Longest runs of Evens and Odds in Each R
ow.
rand_array is the Array into which the Randomly Generated Numbers are Stored.
################################################################################
#########
}
var
num_wheel, rand, num, temp : integer;
num_spins, temp_gap, count_num : longword;
i, count_twice, count_thrice, gap_twice, gap_thrice : longword;
even_count, odd_count, even_max, odd_max : longword;
avg_twice, avg_thrice : double;
rand_array : array[0..200000000] of longword;
{######## Main Program starts ########}
begin
writeln('This is the Code for game of Roulette, coded in PASCAL Language.');
writeln();
writeln('Enter the number of Spins you would wish this game to begin with.');
readln(num_spins);
randomize;
m Number Generator #}

{# Initializing the instance of the Rando

num_wheel:=37;
s on the wheel #}
count_twice:=0;
count_thrice:=0;
gap_twice:=0;
gap_thrice:=0;
temp_gap:=0;

{# Defining the count of the total number

for i:=0 to num_spins do begin


f Random Numbers #}
rand:=random(num_wheel);
rand_array[i]:=rand;
n generated into an array #}
end;

{# Using the Loop through all the Spins o


{# Generating a random number #}
{# Moving that random number that has bee

for i:=0 to num_spins do begin


{# Using the Loop through all the Spins #
}
if(rand_array[i]=rand_array[i+1]) then begin {# Verifying if two Consecuti
ve Spins generate Equal Numbers #}
count_twice:=count_twice+1;
{# If two Consecutive Numbers are found t
o be same, Increment the Counter #}
gap_twice:=gap_twice+temp_gap+1; {# Tracking of the Number of Spins betwe
en the two Consecutive Occurences of any number #}

temp_gap:=0;
end else begin
temp_gap:=temp_gap+1;
{# If two Consecutive Numbers yielded are
NOT the Same, Increment the Gap Counter #}
end;
end;
temp_gap:=0; {# Re-initializing the Gap Counter to 0 (Zero) #}
for i:=0 to num_spins do begin
{# Begin to Loop through all the Spins #
}
if((rand_array[i]=rand_array[i+1]) and (rand_array[i]=rand_array[i+2])) then
begin
{# Verifying if three Consecutive Spins
Produce Equal Numbers #}
count_thrice:=count_thrice+1;
{# If three Consecutive Numbers are Same
, then Increment the Counter #}
gap_thrice:=gap_thrice+temp_gap+1; {# Tracking the Number of Spins betwee
n the three Consecutive Occurences of any Number #}
temp_gap:=0;
end else begin
temp_gap:=temp_gap+1;
{# If three Consecutive Numbers are NOT
the same ones, Increment the Gap Counter #}
end;
end;
if(count_twice>0) then begin
avg_twice:=(gap_twice/count_twice);
writeln();
writeln('The same numbers are repeated twice in a row for every ',avg_twice:
1:2,' numbers on an average.');
{# Output 1: Average Frequency of occure
nces of a Number - TWICE in a row #}
end else begin
writeln();
writeln('No number repeats Twice in a row');
end;
if(count_thrice>0) then begin
avg_thrice:=(gap_thrice/count_thrice);
writeln();
writeln('The same numbers are repeated Thrice in a row for every ',avg_thric
e:1:2,' numbers on an average.');
{# Output 2: Average Frequency of occure
nces of a Number - THRICE in a row #}
end else begin
writeln();
writeln('No number repeats Thrice in a row');
end;
writeln();
writeln('Please choose any number of your choice between 1-36');
readln(num);
{# Seeking the Input from the User for t
he Choice of the Number between 1-36 #}
temp_gap:=0;
for i:=0 to num_spins do begin
if(rand_array[i]=num) then begin

if(rand_array[i]=rand_array[i+1]) then begin


count_num:=temp_gap;
end else begin
temp_gap:=temp_gap+1;
end;
end else begin
temp_gap:=temp_gap+1;
end;
end;
if (count_num>0) then begin
writeln();
writeln(num,' is Repeated Twice in a row after ',count_num,' numbers');
{# Output 3: The Frequency of Occurences
of a Specific Number - TWICE in a row #}
end else begin
writeln();
writeln(num,' is not repeated Twice in a row');
end;
even_max:=0;
s #}
even_count:=0;
}

{# The Max Count of two Consecutive Even

odd_max:=0;
#}
odd_count:=0;
}

{# The Max Count of two Consecutive Odds

{# The Count of Longest Evens in a Row #

{# The Count of Longest Evens in a Row #

for i:=0 to num do begin


if (rand_array[i]<>0) then begin
{# Verifying if the Number is 0 (Zero) #
}
temp:=(rand_array[i] mod 2); {# If the Number is NOT zero, then Calcu
late the Remainder Using MOD Operator #}
if (temp<>0) then begin
{# Verifying if the Number is Even (when
mod=0) #}
odd_count:=odd_count+1;
{# If the Number is Odd, then Increment
the Count of Odds #}
if (even_count>even_max) then begin
even_max:=even_count;
{# The Longest Continuous occurences of
EVENS is Calculated #}
end;
even_count:=0;
end else begin
even_count:=even_count+1;
if (odd_count>odd_max) then begin
odd_max:=odd_count;
{# The Longest Continuous occurence of O
DDS is Calculated #}
end;
odd_count:=0;
end;
end;
end;
writeln();
writeln('The longest run of EVENS in a row = ',even_max);
{# Output 4: The Longest Number of occur
ences of EVENS in a row #}
writeln();

writeln('The longest run of ODDS in a row = ',odd_max);


{# Output 5: The Longest Number of occur
ences of ODDS in a row #}
writeln();
writeln('Press enter to exit');
readln();
End.
{# The Main program ends here #}
################################################################################
##########################################

You might also like