Posts: 1,956
Threads: 65
Joined: Jun 2003
BLITZ AND ANTONI,
I compiled your original programs using BC with /ah option, and now they run fine.
BLITZ: Excellent, yours runs perfectly. Later you can explain what the 2 dimeensional array is all about.
ANTONI: Very good, also runs well. One very minor problem, you do not alllow the user to specify a code or zero nor a code of 99999, which are within the defined limits.
*****
Posts: 1,956
Threads: 65
Joined: Jun 2003
ANTONI,
Your "bit array" is exactly my preferred solution. See my program below with a slightly simpler bit handling than yours, that is, no need for a pwrsof2 array. Code: REM Code validation program by Edward F. Moneo
DEFINT A-Z
CONST BT.MAXSIZE = 99999
DIM BT.TAB ( 0 TO ((BT.MAXSIZE+1)\16) ) AS INTEGER
DIM BT.BIT AS LONG
DIM BT.LOC AS INTEGER
DIM BT.ARG AS LONG
DIM BT.TRUE AS INTEGER
open "valid.txt" for input as #1
do while not eof(1)
line input #1,d$
bt.arg=val(d$)
gosub bt.set
loop
do
input "Enter code to be validated (X=exit)";z$
if ucase$(z$)="X" then system
gosub validate
if valid=0 then
print "ERROR: Non-numeric or out or range input code"
else
bt.arg=val(z$)
gosub bt.test
if bt.true=0 then print "ERROR: code invalid" else print "ok, code valid"
end if
loop
'******************************************************************************
BT.SET:
GOSUB BT.GET
BT.TAB(BT.LOC) = BT.TAB(BT.LOC) OR BT.BIT
RETURN
BT.TEST:
GOSUB BT.GET
BT.TRUE = ( BT.TAB(BT.LOC) AND BT.BIT )
RETURN
BT.GET:
BT.BIT = BT.ARG MOD 16
BT.BIT = 2^BT.BIT
BT.LOC = BT.ARG\16
RETURN
'BT.RESET: '(Not used by this program)
' GOSUB BT.GET
' BT.TAB(BT.LOC) = BT.TAB(BT.LOC) AND (NOT(BT.BIT))
'RETURN
' *************************************************************************
'*** CHECK FOR STRICTLY NUMERIC AND LESS/EQUAL TO BT.MAXSIZE.
VALIDATE:
VALID=0 'Init to False
IF Z$="" THEN RETURN '------------------
FOR X = 1 TO LEN(Z$)
A=ASC(MID$(Z$,X,1))
IF A<48 OR A>57 THEN RETURN '-------
NEXT X
IF VAL(Z$)<=BT.MAXSIZE THEN VALID=-1
RETURN
*****
Posts: 1,407
Threads: 117
Joined: Dec 2002
Blitz:
OK, you won!
Moneo:
I use the array of Pwrsof2 just for speed. In this case this is not an issue but when doing real time graphics (p.e. scaling a font) it is.
Antoni
Posts: 1,956
Threads: 65
Joined: Jun 2003
Ok, Antoni, what you say makes sense for speed. Once you learn to do something considering speed, you get in the habit of always doing it that way.
P.S.: It's hard to consider Blitz as having won. His last posted program is incomplete. Also, he abandoned his original approach and adopted yours.
*****
Posts: 788
Threads: 53
Joined: Nov 2002
Eh, that was my orginal aproatch. My original one used a huge array of integers which had 100,000 elements. The one antoni wrote the second time was the same as mine but with a bit array instead. My second one same as my first, except with a bit array. So i don't see how it is ME who has abboned their original aproach.
The two dimensional array is bascially the same principal as real mode memory. It's split up into segments. In this case each segment is 16384 integers. That times 13 gives us over 100,000 elements to work with. To calculate the element index as a two dimensional array we do this indxa = element \ 16384, indxb = element mod 16384.
oship me and i will give you lots of guurrls and beeea
Posts: 1,956
Threads: 65
Joined: Jun 2003
Ok, sorry, Blitz. It's just that you've posted several versions including benchmark versions, so I'm a little confused as to which is your lastest working version. Would you please post your latest, running version so I can try it again.
*****
Posts: 3,368
Threads: 195
Joined: Jan 2003
i'm gonna try this, now that Moneo has explained what it's all about.
And, stop spamming, Blitzilla.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 1,956
Threads: 65
Joined: Jun 2003
Aga,
Your right, I didn't explain everything up front this time, like I usually do. If I do too much explaining, then I get accused of posting a challenge with too many "constraints". I'm damned if I do, and damned if I don't.
Ok, so go ahead and try this one out, now that you know.
*****
Posts: 480
Threads: 24
Joined: Mar 2003
How's this for cramming the codes into as little memory as possible? No arrays (this outta be good for a laugh, at least!)
Code: DECLARE FUNCTION GetCode& ()
CLS
SCREEN 11
OPEN "VALID.TXT" FOR INPUT AS #1
FOR i% = 1 TO 20000
INPUT #1, n&
PSET (n& MOD 640, n& \ 640), 15
NEXT i%
CLOSE #1
DO
UserCode& = GetCode&
PRINT UserCode&; "is ";
IF POINT(UserCode& MOD 640, UserCode& \ 640) THEN
PRINT "Valid. "
ELSE
PRINT "Invalid. "
END IF
LOOP
FUNCTION GetCode&
LOCATE 12, 1: PRINT SPC(79);
LOCATE 12, 1: PRINT "Enter Code: ";
Code& = 0
DO
LOCATE 12, 13: PRINT Code&; " "
DO
c$ = INKEY$
LOOP UNTIL c$ <> ""
IF c$ = CHR$(27) THEN SYSTEM
IF c$ = CHR$(13) THEN EXIT DO
IF c$ = CHR$(8) THEN Code& = Code& \ 10
IF c$ >= "0" AND c$ <= "9" THEN
IF Code& <= 9999 THEN Code& = Code& * 10 + VAL(c$)
END IF
LOOP
GetCode& = Code&
END FUNCTION
*peace*
Meg.
Posts: 1,407
Threads: 117
Joined: Dec 2002
Fine idea, Meg!
This reminds me old times. I once used screen memory to run an assembler program in a Sinclair ZX Spectrum, back in 1985.... The idea was to leave all conventional memory to load a game (from an audio cassette), then my program made an (illegal) copy of it..
Antoni
|