URGENT: Mathematics Programming

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).
ZeroTakenaka
Posts: 5
Joined: Sat Oct 08, 2005 2:59 pm

URGENT: Mathematics Programming

Post by ZeroTakenaka »

I am doing one of your mathematics ideas and I am using QBASIC to do the Hi-Lo Project or namely The Effects of Card Counting on a Card Game.
I need help on the programming. My programming so far is:

CLS
RANDOMIZE TIMER
FOR x = 1 TO 10000
PRINT INT(RND*13)+1
NEXT

Help me out here!
david_w
Posts: 2
Joined: Mon Sep 19, 2005 7:48 pm

Post by david_w »

As always, I would suggest a Google Search to help find information about QBASIC.

However, it does seem as though you have at least a basic knowledge of QBASIC (sorry, I don't), so I would be inclined to think that it is more a problem of inspiration than knowledge. Try thinking about what needs to happen in the program for your project, and think about the ways in which a program could carry out what you want it to do.

What is the first thing the program will need to do in order for it to get itself ready to do all the calculations that might be required for a project such as yours? Program this if you can, then think about the next thing.. Just go through the testing process in your head, and translate that, through QBASIC, into a program that will carry out what you want it to do for the project.

And it sounds like a neat project, indeed! The outcome could have an effect on the way you play cards, you never know..
ZeroTakenaka
Posts: 5
Joined: Sat Oct 08, 2005 2:59 pm

Post by ZeroTakenaka »

I know quite a bit of QBASIC programming. I want something like this but it won't work.

IF x > 7 THEN a + 1
IF x = 7 THEN b + 1
IF x < 7 THEN c + 1
a = 0
b = 0
c = 0

And I forget what the rest of the project wants me to do.
david_w
Posts: 2
Joined: Mon Sep 19, 2005 7:48 pm

Post by david_w »

I have done some basic C programming, and it seems that in order for your variable value to increase, you need to set it up so that it would be

a = a + 1 ( can you have an increment (++) in QBASIC? so that it would look like: a++ )

And you probably should review the project so that you can continue programming the rest of the code.
LewisWhaley
Former Expert
Posts: 181
Joined: Wed Aug 31, 2005 2:47 pm
Occupation: Retired - Information Technology Software Development and Systems Support since 1969.
Project Question: n/a
Project Due Date: n/a
Project Status: Not applicable

Post by LewisWhaley »

Hi ZeroTakenaka.

You are definitely on the right track.

Here is some of your QBASIC code, modified some,
that you may be able to use as a skeleton program
for your project:

=======
CLS

RANDOMIZE TIMER

FOR x = 1 TO 10000
r = INT(RND * 13) + 1
n = r
IF r > 7 THEN n = r - 1
IF r < 7 THEN n = r + 1
PRINT "Card Showing "; r; " Card Count Next Card "; n
PRINT "Press any Key to continue or type x to Stop.": INPUT a$
IF a$ = "x" OR a$ = "X" THEN GOTO GameOver
a$ = ""
NEXT

GameOver:
END
=======

Good Luck!
Best Regards,

Lewis Whaley
Ask an Expert Forum
Science Buddies
LewisWhaley
Former Expert
Posts: 181
Joined: Wed Aug 31, 2005 2:47 pm
Occupation: Retired - Information Technology Software Development and Systems Support since 1969.
Project Question: n/a
Project Due Date: n/a
Project Status: Not applicable

Post by LewisWhaley »

Hi ZeroTakenaka.

One more thing, just a suggestion.

This would be a really cool project to do using
Microsoft Excel spreadsheet and VBA, Visual Basic for Applications,
Macros instead of QBASIC
if you have access to Microsoft Excel, included with Microsoft Office.

You could capture all of the results and "populate" the spreadsheet Cells,
Rows, and Columns, from your Macro program code,
plus you would have a GUI interface using Message Boxes
and Input Boxes.

You can convert QBASIC code fairly easy to Microsoft VBA code.
You would just need to know the specifics about populating the
spreadsheet with the results which is not that difficult.
If you decide to try this, I can help you and I am sure there
are a lot of other Mentors that are better at this than I am.

Let us know what you think about this.

Good Luck!
Best Regards,

Lewis Whaley
Ask an Expert Forum
Science Buddies
ZeroTakenaka
Posts: 5
Joined: Sat Oct 08, 2005 2:59 pm

Post by ZeroTakenaka »

[quote][i]First, you should play the game a bit by yourself. Develop your own strategy for playing the game (for example, if the card is greater than 7 you always guess lower, if the card is less than 7 you always guess higher) and then test it out by taking a deck of cards and keeping track of how often you can correctly guess whether the next card is higher or lower than the one you turned over. If you can guess right more than 70% of the time, you've probably got the right strategy. The next thing you need to do is pick a programming language. If you've never programmed before, you should start with QBASIC, which is available for free at many internet sites, and is as close to English as any programming language. You'll write a computer simulation that will play thousands of hands of this card game Your simulation program needs two parts - the first is a shuffling routine to make sure the deck is random. The second is the actual game-playing strategy. You'll also have to write some data collection routines so you know how many times you've won or lost, and on which cards. Programming the strategy is the most involved part of this project, and can lead to a lot of results about how to play the game. [/i][/quote]

This is what i have to do and I updated on your skeleton but it is not counting all numbers that are in the FOR.

Updated Skeleton:

CLS
RANDONIZE TIMER
FOR x = 1 TO 10000
n = INT(RND * 13) + 1
NEXT
a = 0
b = 0
c = 0
IF n > 7 THEN a = a + 1
IF n = 7 THEN b = b + 1
IF n < 7 THEN c = c + 1
PRINT a; b; c
END

Any help on this is appreciated.
LewisWhaley
Former Expert
Posts: 181
Joined: Wed Aug 31, 2005 2:47 pm
Occupation: Retired - Information Technology Software Development and Systems Support since 1969.
Project Question: n/a
Project Due Date: n/a
Project Status: Not applicable

Post by LewisWhaley »

Hi ZeroTakenaka.

Here is the latest skeleton for you to use.
You need to use REM statements to document
your Changes.
Programs like this tend to "Evolve" and it is real easy
to lose your place if you have many copies around.

This should be close to what you are trying to accomplish.
Try different ways to "Count" the Next Card Number,
like adding 2 instead of 1 or subtracting 2 instead of 1
or use a Random Number for the Card Number showing,
like:
n = RND(r) - 1 or n = RND(r) + 1
instead of
n = r - 1 or n = r + 1
You will just have to change the variable "n" in different ways
until you find a good algorithm that works closest
to providing the best number of matches.

New Program:

=======
REM: Card Counting Analysis Program
REM: Program Written:
REM: 10-09-2005 09:12 AM EDT
REM: Change Log:
REM: 10-09-2005 08:12 PM EDT Add and print Total Counts for Match / Unmatch.
REM:
REM:

CLS

DEFINT A-Z

a = 0
b = 0
c = 0
n = 0
amatch = 0
bmatch = 0
cmatch = 0
aunmatch = 0
bunmatch = 0
cunmatch = 0

RANDOMIZE TIMER

FOR x = 1 TO 10000
r = INT(RND * 13) + 1
p = n
n = r
IF r > 7 THEN n = r - 1: a = a + 1: IF p = n THEN amatch = amatch + 1
IF r = 7 THEN b = b + 1: IF p = n THEN bmatch = bmatch + 1
IF r < 7 THEN n = r + 1: c = c + 1: IF p = n THEN cmatch = cmatch + 1
PRINT "Card Showing "; r; " Card Count Next Card "; n
PRINT "Press any Key to continue or type x to Stop.": INPUT a$
IF a$ = "x" OR a$ = "X" THEN GOTO GameOver
a$ = ""
NEXT

GameOver:

aunmatch = a - amatch
bunmatch = b - bmatch
cunmatch = c - cmatch


PRINT
PRINT "Total number of Cards : "; x
PRINT
PRINT "Card > 7 Number of times : "; a; " Matched: "; amatch; " Unmatched: "; aunmatch
PRINT "Card = 7 Number of times : "; b; " Matched: "; bmatch; " Unmatched: "; bunmatch
PRINT "Card < 7 Number of times : "; c; " Matched: "; cmatch; " Unmatched: "; cunmatch
END

=======

Note - The following similar Counts are displayed at the END of program.


Total number of Cards : 101

Card > 7 Number of times : 46 Matched: 8 Unmatched: 38
Card = 7 Number of times : 9 Matched: 2 Unmatched: 7
Card < 7 Number of times : 45 Matched: 2 Unmatched: 43
=======


Good Luck!
Best Regards,

Lewis Whaley
Ask an Expert Forum
Science Buddies
ZeroTakenaka
Posts: 5
Joined: Sat Oct 08, 2005 2:59 pm

Post by ZeroTakenaka »

Ah yes... so sorry for waiting to reply, I gave up on my project for a moment. I needed to examine and update my program. Here is a good upadated program but I need to run a simulation hi-lo game and I wanna know how to save the last random number generated.

CLS
RANDOMIZE TIMER
a = 0
b = 0
c = 0
FOR x = 1 TO 10000
G = INT(RND * 13) + 1
IF G > 7 THEN a = a + 1
IF G = 7 THEN b = b + 1
IF G < 7 THEN c = c + 1
NEXT x
PRINT a; b; c
LewisWhaley
Former Expert
Posts: 181
Joined: Wed Aug 31, 2005 2:47 pm
Occupation: Retired - Information Technology Software Development and Systems Support since 1969.
Project Question: n/a
Project Due Date: n/a
Project Status: Not applicable

Post by LewisWhaley »

Hi ZeroTakenaka.

You just need to use the Random Number generated each time
to calculate the next number, then save it in a,b,c
like for example, change your program code as follows:

RANDOMIZE TIMER
a = 0
b = 0
c = 0
FOR x = 1 TO 10000
G = INT(RND * 13) + 1
IF G > 7 THEN a = G + 1
IF G = 7 THEN b = G + 1
IF G < 7 THEN c = G - 1
NEXT x
PRINT a; b; c


If you want to save all 10,000 Random numbers,
you will need three Arrays for a,b,c.

Let us know if this helps you and what you are doing next.

Good Luck ZeroTakenaka! :D
Best Regards,

Lewis Whaley
Ask an Expert Forum
Science Buddies
ZeroTakenaka
Posts: 5
Joined: Sat Oct 08, 2005 2:59 pm

Post by ZeroTakenaka »

What in the world are you talking about? How do I save the numbers generated to use it in my simulation game?
LewisWhaley
Former Expert
Posts: 181
Joined: Wed Aug 31, 2005 2:47 pm
Occupation: Retired - Information Technology Software Development and Systems Support since 1969.
Project Question: n/a
Project Due Date: n/a
Project Status: Not applicable

Post by LewisWhaley »

Hi ZeroTakenaka.

The program I Posted the second time we discussed this
does what you need.

I changed the program to write a text file you can open in Notepad
or WordPad.
Output File Name is TextFileName = "C:\ZTaka01.txt"




--------------------------------------------------------------------------------

Posted: Sun Oct 09, 2005 8:37 pm Post subject:

--------------------------------------------------------------------------------

Hi ZeroTakenaka.

Here is the latest skeleton for you to use.
You need to use REM statements to document
your Changes.
Programs like this tend to "Evolve" and it is real easy
to lose your place if you have many copies around.

This should be close to what you are trying to accomplish.
Try different ways to "Count" the Next Card Number,
like adding 2 instead of 1 or subtracting 2 instead of 1
or use a Random Number for the Card Number showing,
like:
n = RND(r) - 1 or n = RND(r) + 1
instead of
n = r - 1 or n = r + 1
You will just have to change the variable "n" in different ways
until you find a good algorithm that works closest
to providing the best number of matches.

New Program:

=======
REM: Card Counting Analysis Program
REM: Program Written:
REM: 10-09-2005 09:12 AM EDT
REM: Change Log:
REM: 10-09-2005 08:12 PM EDT Add and print Total Counts for Match / Unmatch.

REM: 10-05-2005 07:23 PM EDT Add Output File for Saved Results.
REM:
REM:

CLS

DEFINT A-Z

a = 0
b = 0
c = 0
n = 0
amatch = 0
bmatch = 0
cmatch = 0
aunmatch = 0
bunmatch = 0
cunmatch = 0

TextFileName = "C:\ZTaka01.txt"

Open TextFileName For Output As #1


RANDOMIZE TIMER

FOR x = 1 TO 10000
r = INT(RND * 13) + 1
p = n
n = r
IF r > 7 THEN n = r - 1: a = a + 1: IF p = n THEN amatch = amatch + 1
IF r = 7 THEN b = b + 1: IF p = n THEN bmatch = bmatch + 1
IF r < 7 THEN n = r + 1: c = c + 1: IF p = n THEN cmatch = cmatch + 1
Record = Record + 1
Result$ = "Record_" + Record +"Card Showing " + r + " Card Count Next Card " + n
PRINT #1,Result$
PRINT Result$
REM: Comment Now: PRINT "Card Showing "; r; " Card Count Next Card "; n
PRINT "Press any Key to continue or type x to Stop.": INPUT a$
IF a$ = "x" OR a$ = "X" THEN GOTO GameOver
a$ = ""
NEXT

GameOver:

aunmatch = a - amatch
bunmatch = b - bmatch
cunmatch = c - cmatch


PRINT
PRINT "Total number of Cards : "; x
PRINT
PRINT "Card > 7 Number of times : "; a; " Matched: "; amatch; " Unmatched: "; aunmatch
PRINT "Card = 7 Number of times : "; b; " Matched: "; bmatch; " Unmatched: "; bunmatch
PRINT "Card < 7 Number of times : "; c; " Matched: "; cmatch; " Unmatched: "; cunmatch
CLOSE
END

=======

Note - The following similar Counts are displayed at the END of program.


Total number of Cards : 101

Card > 7 Number of times : 46 Matched: 8 Unmatched: 38
Card = 7 Number of times : 9 Matched: 2 Unmatched: 7
Card < 7 Number of times : 45 Matched: 2 Unmatched: 43
=======

--------------------------------------------------------------------------------
Best Regards,

Lewis Whaley
Ask an Expert Forum
Science Buddies
shaukmio
Posts: 2
Joined: Wed Mar 28, 2007 6:08 pm

Qbasic

Post by shaukmio »

Is it possible to copy and paste the code you have just put.
davidkallman
Former Expert
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

Re: copy and paste

Post by davidkallman »

Hi shaukmio!

Yes, of course it's possible. And, in fact, it's the preferred method, so errors an exact copy is made, and errors are not introduced. In fact, I used above for your ID!
Cheers!

Dave
davidkallman
Former Expert
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

Re: copy and paste

Post by davidkallman »

Speaking of errors, it was a case of "the pot calling the kettle black." In my last post, I had an extra "errors." The correct text is:

Yes, of course it's possible. And, in fact, it's the preferred method, so an exact copy is made, and errors are not introduced. In fact, I used above for your ID!

P.S.: One really needs to proofread AND spell check!
Cheers!

Dave
Locked

Return to “Math & Computer Science Sponsored by Hyperion Solutions Corp”