Qbasicnews.com

QBasic => QB Discussion & Programming Help => Topic started by: The_Names_Gin on April 23, 2006, 05:28:51 PM



Title: Greater & Less Than
Post by: The_Names_Gin on April 23, 2006, 05:28:51 PM
All right, I have a big number group from 1 to 52,

Now lets say, I want only numbers 3, 16, 29, 43 to be the lowest of all the numbers

BUT

I want 4, 17, 30, 44, to be slightly higher but not greater than 5, 18, 31, 45

Making it in layers like so

Example:

3, 16, 29, 43 is less than 4, 17, 30, 44
4, 17, 30, 44 is less than 5, 18, 31, 45 but greater than 3, 16, 29, 43
5, 18, 31, 45 is less than 6, 19, 32, 46 but greater than 4, 17, 30, 44 & so on...


Title: Greater & Less Than
Post by: Dio on April 23, 2006, 06:56:04 PM
ok, did anybody else catch that?


Title: Re: Greater & Less Than
Post by: RyanKelly on April 23, 2006, 07:41:52 PM
I'm sorry.  Your question is beyond vague.

Quote
All right, I have a big number group from 1 to 52,

Explain what you mean by "have a big number group".
Is this an array?  Are they in a files?  Are your individual data types the numbers themselves or groups of numbers?

Quote

Now lets say, I want only numbers 3, 16, 29, 43 to be the lowest of all the numbers



All the lists you posted follow this pattern,

x, x+3, x+13, x + 14.

Does this hold true for every group you want to work with?

Give us a brief description of the broader context you're working in.


Title: Greater & Less Than
Post by: Z!re on April 23, 2006, 07:41:53 PM
Ok


Title: Greater & Less Than
Post by: Z!re on April 23, 2006, 07:42:39 PM
Also, for those who dont get it yet.. he wants to sort a deck of cards...


Title: Greater & Less Than
Post by: The_Names_Gin on April 23, 2006, 08:52:02 PM
Quote from: "Z!re"
Also, for those who dont get it yet.. he wants to sort a deck of cards...


Yeah something on the concept of that idea.

1, 14, 27, 40 -Lowest
2, 15, 28, 41
3, 16, 29, 42
4, 17, 30, 43
5, 18, 31, 44
6, 19, 32, 45
7, 20, 33, 46
8, 21, 34, 47
9, 22, 35, 48
10, 23, 36, 49
11, 24, 37, 50
12, 25, 38, 51
13, 26, 39, 52 -Highest

Each one of the numbers is going to be something on the lines of

if num = 42 then
print "Example 52"

else goto 10

if num = 16 then
print "Example 11"


Title: Greater & Less Than
Post by: Z!re on April 23, 2006, 08:54:33 PM
Ok, I dont get it..


Title: Greater & Less Than
Post by: The_Names_Gin on April 23, 2006, 09:08:46 PM
Quote from: "Z!re"
Ok, I dont get it..


It's like um...

When chosen, each number will print out something different.

Like: If num = 12 then PRINT "Example 40"

the user presses a button & it randomly shoots out 5 numbers, lets say..

17,      40,     12,    38,     45
slot1, slot2, slot3, slot4, slot5,

.. For instance.

The program will look at the five numbers/slots

Deciding which one is higher,

In my diagram of 1 - 50 we can clearly see 12 is the highest & 40 is the lowest.

I want it to than spit out to the user the highest number (12) in a string.


Title: Greater & Less Than
Post by: Dio on April 23, 2006, 09:58:19 PM
Quote from: "RyanKelly"
I'm sorry.  Your question is beyond vague.

:laughing:

Quote from: "Z!re"
Ok, I dont get it..


ok, just so as long that i'm not thee only one here


Title: Greater & Less Than
Post by: Deleter on April 23, 2006, 10:10:57 PM
The more he posts, the more lost I get  :???:


Title: Greater & Less Than
Post by: Pritchard on April 23, 2006, 10:28:44 PM
Just a suggestion, but couldn't you dim the array (0 to 12, 0 to 3) '0 to 3 for four types.  Have it throw out a random card from there. This way you can use the first spot in that array (x, y) 'x in this case, to check the value of the card.

I hope this is somewhere NEAR what you are asking, otherwise I'm amazingly confused, or...More amazingly confused than I already am.

For example:
Code:
'Dim stuff here:
dim card_Deck (0 to 12, 0 to 3) 'This will be our card deck array
dim card(0 to 5) 'Six cards at hand

'Create the deck!
for load = 0 to 12
    for load_2 = 0 to 3
        card_deck(load, load_2) = load
    next
next

'Make a hand
for card_throw = lbound(card) to ubound(card)
    card_type = int(rnd * 3)
    card_value = int(rnd * 12)
    card(card_Throw) = card_deck(card_value, card_type)
next

'Print the Values of the hand:
for card_throw = lbound(card) to ubound(card)
    print card(card_throw)
next
print "Total value is:", card(0) + card(1) + card(2) + card(3) + card(4) + card(5)
sleep


Title: Greater & Less Than
Post by: stylin on April 24, 2006, 12:41:14 AM
You could use an array, but that's a little inefficient. Here, you can rely on the fact that the numbers in your diagram are simply the reversed-ordered elements in an array (all we need to do is find the column the number would be in):

Code:

'/ returns the column the element n would be in with an
'/ array width of highestPriority
function GetPriority(n as integer, highestPriority as integer) as integer
   return (n-1) mod highestPriority
end function

   '/ create an array to hold the random nums
   const MaxSlots as integer = 5
   dim slots(0 to MaxSlots-1) as integer
   
   '/ fill slots with random numbers
   '/ ...

   '/ find the number with highest priority
   dim highestPriority as integer = 0

   dim slot as integer
   for slot = 0 to MaxSlots-1
      dim priority as integer = GetPriority(slots(slot),13)
      if (highestPriority < priority) then
         highestPriority = priority
      end if
   next

   '/ highestPriority now contains the slot with
   '/ the highest priority :)


Title: Greater & Less Than
Post by: stylin on April 24, 2006, 12:44:47 AM
My internet's borked, so I had to shorten my code above so I could post it. Just wanted to add that you should get rid of that literal '13' and replace it with a constant - or a var, if you'd like to change the array width (max priority) at run-time.

EDIT: and you'll have to actually save the slot along with the highest priority. (my code just keeps track of the priority) :o


Title: Greater & Less Than
Post by: The_Names_Gin on April 24, 2006, 02:19:26 PM
I took a different route by using DIM commands,

but now I get a duplicate error

1 = 1
14 = 1
27 = 1
40 = 1


Title: Greater & Less Than
Post by: stylin on April 24, 2006, 02:22:32 PM
Let me consult my crystal ball ... it tells me I need more information [IOW, nobody is a mind-reader here]. You might want to post some code. Sorry.


Title: Greater & Less Than
Post by: na_th_an on April 24, 2006, 06:17:16 PM
This is a shuffling problem.

Steps:

1.- Create an array with 52 indexes, one for each value.
2.- Assign each value to its array index, so the array will be A(X) = X.
3.- Do a loop iterating a number of times, i.e. 26 times. The more times, the more "shuffled".
4.- Each loop just swap two array elements selected at random:

X = INT(RND*52)+1
Y = INT(RND*52)+1
AUX = A(Y)
A(Y) = A(X)
A(X) = AUX

(or use SWAP A(X), A(Y) which is a BASIC command, look for it in the help).


Title: Greater & Less Than
Post by: redcrab on April 24, 2006, 06:56:46 PM
I think I got it ! .... I guess ... (http://forum.qbasicnews.com/images/smiles/icon_eek.gif) DOH ! this is same as Stylin... but i get something different for the card chooser... ;)
I take the given example
17,40,12,28,48 then 12 is maxi and 40 is mini then :

The tip is to search for min and max of ((value-1) mod 13)
EDIT : Stylin already found it ... :oops:

Code:
dim slot(5) as integer
' example choosen
slot(1) =17 : slot(2)= 40 : slot(3) = 12 : slot(4) = 28 : slot(5) = 48

' or  to choose 5 DIFFERENTS number (between 1-52)
' here is a special  quick shuffle algo
min = 0 : for i = 5 to 1 step -1 : min = int(rnd*(52-min+1)/i)+min+1 : slot(i) = min : next

' then search min max thanks to the given logic
minvalue = 100 : maxvalue = 0 : foundmin = 100 : foundmax = 0
for i = 1 to 5
   v = (slot(i)-1) mod 13
   if v < minvalue then
       minvalue = v : foundmin = slot(i)
   end if
   if v > maxvalue  then
       maxvalue = v : foundmax = slot(i)
   end if
next i
print "max = " ; foundmax,"min=";foundmin
end


not tested but should work ...

Have fun !


Title: Greater & Less Than
Post by: stylin on April 24, 2006, 09:28:10 PM
Quote from: "The_Names_Gin"
I took a different route by using DIM commands,

but now I get a duplicate error

1 = 1
14 = 1
27 = 1
40 = 1

Your diagram has the numbers 1, 14, 27 and 40 having equal priority. If you want 1 < 14 < 27 < 40 then there's no sense in using your diagram at all. (just compare the numbers directly)


Title: Greater & Less Than
Post by: Anonymous on April 25, 2006, 12:07:05 AM
the stoner knows what's going on... funny.

Code:
Function priority( num As Integer ) As Integer
 
  Dim As Integer res
  '' 13 elements in a group in a deck of cards.
  res = ( num Mod 13 )
  If res = 0 Then res = 13
  priority = res
 
End Function




Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer

a = 20
b = 35
c = 1
d = 52


? a; "'s priority is:"; priority( a )
? b; "'s priority is:"; priority( b )
? c; "'s priority is:"; priority( c )
? d; "'s priority is:"; priority( d )

Sleep


Title: Greater & Less Than
Post by: The_Names_Gin on April 25, 2006, 01:02:20 AM
The code comes in two parts, the first part is finished, because of this it will be dismissed, skipping the second part with a GOTO command.

The second will transform into the example below

1 = 13, 14 = 13, 27 = 13, 40 = 13
2 = 1, 15 = 1, 28 = 1, 41 = 1
3 = 2, 16 = 2, 29 = 2, 42 = 2
4 = 3, 17 = 3, 30 = 3, 43 = 3
5 = 4, 18 = 4, 31 = 4, 44 = 4
6 = 5, 19 = 5, 32 = 5, 45 = 5
7 = 6, 20 = 6, 33 = 6, 46 = 6
8 = 7, 21 = 7, 34 = 7, 47 = 7
9 = 8, 22 = 8, 35 = 8, 48 = 8
10 = 9, 23 = 9 36 = 9, 49 = 9
11 = 10, 24 = 10, 37 = 10, 50 = 10
12 = 11, 25 = 11, 38 = 11, 51 = 11
13 = 12, 26 = 12, 39 = 12, 52 = 12

What I need now is to solve each four set number groups to equal the final numbers that are set so that I no longer have the duplicate error during RUN TIMES.


Title: Greater & Less Than
Post by: Anonymous on April 25, 2006, 01:23:55 AM
Code:
Sub deck_Initialize( c() As Integer )

  Dim suits As Integer
  Dim elements As Integer
 

  Redim c( 1 To 52 )
  For suits = 0 To 3
   
    c( suits * 13 + 1 ) = 13
   
    For elements = 1 To 12
   
      c( suits * 13 + elements + 1 ) = elements
     
    Next
   
  Next


End Sub


Dim cards() As Integer
Dim i As Integer

deck_Initialize( cards() )


For i = 1 To 13

 

  ? i; ":"; cards( i ),
  ? i+13; ":"; cards( i + 13 ),
  ? i+26; ":"; cards( i + 26 ),
  ? i+39; ":"; cards( i + 39 )

Next


Sleep





Title: Greater & Less Than
Post by: The_Names_Gin on April 26, 2006, 02:35:16 AM
what is the correct way of doing this?

Code:

IF slot5% > slot1% AND slot5% > slot2% AND slot5% > slot3% AND slot5% > slot4% THEN
highexample$ = held5$

END IF


Title: Greater & Less Than
Post by: Anonymous on April 26, 2006, 03:31:33 AM
no idea. because that code has no context by itself. please post a full example of code.


Title: Greater & Less Than
Post by: The_Names_Gin on April 26, 2006, 07:01:21 PM
I prefer not to write the code here.

This new question is how can I write multiple operators to get the end result. Such as

slot1% = 10
slot2% = 7
slot3% = 5
slot4% = 4
slot5% = 1

This is where I'm having trouble with, writing the execution out.

IF slot1% > slot2% AND slot1% > slot3% AND slot1% > slot4% AND slot1% > slot5% THEN

...execute somthing

Am I writing it wrong, am I suppose to use buckets? or some comma's? If so where?


Title: Greater & Less Than
Post by: stylin on April 26, 2006, 07:29:12 PM
Quote from: "The_Names_Gin"
I prefer not to write the code here.

I prefer not to guess at what you have in mind.

Quote
Am I writing it wrong, am I suppose to use buckets? or some comma's? If so where?

It depends. Explain why you are doing what you are doing, what your needs are - efficiency, flexibility, etc. - and post your algorithm and we might be able to help you. The best solution to a problem is rarely able to surface in such a small section of code.

(you'll probably get better advice with more information; there is no best way to solve software problems)


Title: Greater & Less Than
Post by: Anonymous on April 27, 2006, 04:31:23 AM
dude yeah. i'm sick oef people coming here and asking for us to help you, and acting like your code is something i've never seen. are you insulting me? are you saying your code is better than the code that i release for everyone to see??

you think i'm some robot who's designed to give you the answers? fuck that. you want something, you give something. the sooner you learn that, the sooner you stop looking like a fool.


and yeah, i've had a little to much to drink tonight, now you get a nice dose of reality.


Title: Greater & Less Than
Post by: Z!re on April 27, 2006, 08:01:08 AM
Quote from: "cha0s"
dude yeah. i'm sick oef people coming here and asking for us to help you, and acting like your code is something i've never seen. are you insulting me? are you saying your code is better than the code that i release for everyone to see??

you think i'm some robot who's designed to give you the answers? fuck that. you want something, you give something. the sooner you learn that, the sooner you stop looking like a fool.


and yeah, i've had a little to much to drink tonight, now you get a nice dose of reality.
Yarr! I agree..


Title: Greater & Less Than
Post by: Deleter on April 27, 2006, 04:33:43 PM
Unfortunately, the people who do that kind of thing are the same people who don't read a single post before posting, and ignore/insult anyone who tries to tell them anything other then the answer they want, even when the question they wrote sucks beyond belief. I'm not even sure if you made a sticked post called "READ THIS RIGHT FUCKING NOW IF YOU HAVENT BEFORE OR BE BANNED FOR FUCKING LIFE AND HAVE YOUR POSTS FUCKING DELETED" that they would read it.... :roll:

maybe we should put such a post on our forums  :laughing:


Title: Greater & Less Than
Post by: Anonymous on April 27, 2006, 09:13:38 PM
Quote from: "Z!re"
Yarr! I agree..


you only agree with me when i'm drunk and rowdy...  :mrgreen:


Title: Greater & Less Than
Post by: Z!re on April 27, 2006, 10:30:28 PM
Quote from: "cha0s"
Quote from: "Z!re"
Yarr! I agree..


you only agree with me when i'm drunk and rowdy...  :mrgreen:
Ofcourse..


Title: Greater & Less Than
Post by: anarky on April 28, 2006, 04:46:37 AM
I only skimmed over all the code posted here, but may I suggest using an array, also. But introduce letters.

Correct me if I'm wrong but smart use of the SWAP command may be an idea.


Title: Greater & Less Than
Post by: na_th_an on May 04, 2006, 06:57:46 AM
Who knows? We still don't know what the guy wants to do.


Title: Greater & Less Than
Post by: anarky on May 04, 2006, 08:33:57 AM
I do. except I don't know the best way around it.

It's essentially a card shuffler. But the only way I can think of how to do it is using a formula similar to 1=14...

Thus:
1  14 27 40  Row 1
2  15 28 41  Row 2
3  16 29 42  Row 3
4  17 30 43  Row 4
5  18 31 44  Row 5
6  19 32 45  Row 6
7  20 33 46  Row 7
8  21 34 47  Row 8
9  22 35 48  Row 9
10 23 36 49  Row 10
11 24 37 50  Row 11
12 25 38 51  Row 12
13 26 39 52  Row 13
...where row 13 is higher in value than row 12, yet 51 > 13.

See where I'm heading?
He's not working on absolute values. He's working on the value per row.

I hope this is what you're after...


Title: Greater & Less Than
Post by: na_th_an on May 04, 2006, 09:31:10 AM
So he has 52 values and has to arrange them in that order? Or do you want a formula which, given a value, tells you in which row it is?

In such case, "(value MOD 13) + 1" will give you what you are looking for...

I still don't get it.


Title: Greater & Less Than
Post by: anarky on May 04, 2006, 09:32:20 AM
Something like that, I think.


Title: Greater & Less Than
Post by: Agamemnus on May 07, 2006, 10:23:36 PM
Ummmm ok for the first post, what he says is this:

1) He has a set of numbers from 1 to 52, although he doesn't tell us how many, if there are duplicates, how they are generated, etc..

2) Then he wants it to be sorted into sets of 4 numbers each, where each set has all the numbers greater than the previous set. Except the problem is that this is not possible to achieve all the time.

...Unless (as a basic example, there are others, but this is the base):

* the quantity of the number set is divisible by 4.
* the numbers go from 1, 1+1, 1+2, 1+3... to X, where X is the quantity of the set.