Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge: Validate a code
#51
Jesus christ, that code will give me nightmares for weeks....

And reading from video ram is around 100 times slower then sys ram. And writing to it is around 10 times slower then sys ram. It's faster then files, but a huge array would have been faster. So if it was performance you were after...

Why do i get the feeling that meg won cuz she's the only girl here?
oship me and i will give you lots of guurrls and beeea
Reply
#52
Quote:Write the program in the most efficient manner possible, WITHOUT USING ANY ADDITIONAL FILES.


Efficiency is equal to SPEED, not source code length, as Moneo thinks.. Smile

BTW, Mr. Blitz, could you compare yours to mine...? Mine reads in 20,000 numbers, then reads them in again and searches for them. Also checks that they are numbers and proper format.

I could do this myself, but you see, if I keep looking at YOUR code (50% whitespace..), *I* might have nightmares for weeks.. :bounce:
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.
Reply
#53
Blitz,
Speed was not an issue here. Speed is seldom an issue when a program has a user interface. The user can't telll the difference waiting for 100ms or 200ms between his input and a response from the program.

I like simplicity. Meg's program is 39% the size of yours, and accomplishes the same task.
*****
Reply
#54
Moneo, moneo..

My validation program is 3 lines of code:

Code:
FUNCTION num.exists% (n&)
k% = n& MOD 16
j% = n& \ 16 + 1
IF (huge.array(j%) AND bit2(k%)) THEN num.exists% = -1
END FUNCTION
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.
Reply
#55
Aga, are you kidding me?
That's the validation function. You entire validation program takes 90 lines of code.
*****
Reply
#56
Er, I meant function.

Realize that I have three functions. One to test an entire file of numbers, one to load a file of numbers, one to test one number, and some code for user input.

Also realize that writing to the screen takes much more moving-around- the-computer-code (SPEED) than writing to an array.

So, if you ignore what's inside the functions, the actual program is only 3 lines, too.
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.
Reply
#57
Come on man, i don't care who wins. I never even enter these callenges becuase of the people who are supose to judge it. What annoys me is that you don't actually seem to understand any of the code. For instance, if it's the shortest code you wanted you would have seen that my first one was basically this. When you remove all the dims, functions, consts, defint, comments. All the things that make clear code. You would have gotten this. Which is quite a bit smaller then megs when you count actual lines of code. So i don't think you're qualified to judge this. In my opnion Antoni should have won. Even though it was basically my code replaced with a bit array. A bit array didn't come to my mind at first. So i think he should have won. Although i would have given him less points for coding style. He would still be the winner.


Code:
'$dynamic
dim shared keyTable( 7, 16383 ) as integer

open "valid.txt" for input a #1
while ( not eof( 1 ) )
    input #1, currKey&
    keyTable( currKey& \ 16384& , currKey& and 16383&  ) = -1
wend
close #1

do
    input "Enter a key or -1 to exit: ", keyToCheck&
    
    if ( keyTable( keyToCheck& \ 16384& , keyToCheck& and 16383& ) = 0 ) then
        print "Invalid key, quiting"
        exit do
    else
        print "Valid key"
    end if
loop
oship me and i will give you lots of guurrls and beeea
Reply
#58
Aga: Using longs is not bad, only dangerous: there are some entries at Microsoft Knowledge Base about QB45 bugs related to longs, in particular as parameters to SUBS and FUNCTIONS.

Blitz: When I die my style of coding will be taught in schools :rotfl:
Antoni
Reply
#59
Blitz,
Your late entry is a beautiful piece of tight code.
However, I had the following little problems:
1) The OPEN statement had "a" instead of "as"
2) I discovered that I needed to compile with /ah switch.
3) It's supposed to exit on -1. However, it says that it's valid.
4) So, I tried some other negative numbers, like -99999 which caused a "subscript out of range" error.
5) You also allow leading, embedded and trailing blanks on the input numbers, which is not good practice. If I entered "1 3" but really meant "123" you accept the input as "13".
6) I also tried some numbers larger than 99999, like 222222, which caused the "subscript out of range" error.

With a few more minutes of work, your last entry could have been a serious contenter. However, we closed off the challenge earlier.

As far as judging is concerned, we don't have any other alternate way of judging challenges. Maybe what I've been doing is not the best way of judging, that is, having the person who posted the challenge be the judge, but it's been working up to now for my posts. Any suggestions?

Regarding my not understanding all the code, it's tough enough to get the programs to compile and then to test them thoroughly. I take a fast look at them to get a fundamental idea of how they work, but without comments of any kind, it's extremely hard to really comprhend the general algorithms of the programs and the logic of their respective functions. If you were test-driving a car, you'd start it up, put in gear and drive around a bit. You woudn't take the engine and transmission apart to see how everything works.
*****
Reply
#60
Oh yeah, forgot the if ( (keyToCheck& < 0) or ( keyToCheck > 99999) ) then exit do
oship me and i will give you lots of guurrls and beeea
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)