number match selection


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838

    Default number match selection

    need to do some code which is giving me an issue

    i want to find a value of 1-6 in a variable in an array and if the value has been used , then it is removed from the list as an available value

    the lowest value that has not been used is then returned as the answer

    regards

    Sheldon

    though something like this as a starting point

    for z = 0 the index
    if value1(z) & $F0 = value2 then
    y = value1(z) & $0F
    if Y = 1 then not_free = 1
    if y = 2 then not_free = 2
    if y = 3 then not_free = 3
    if y = 4 then not_free = 4
    if y = 5 then not_free = 5
    if y = 6 then not_free = 6
    endif
    next z

  2. #2
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: number match selection

    On way is to use bit flags to keep track of what numbers have been guessed:

    GUESSES = %01111110 ' We're not using bit 0 because you can't guess 0

    On each guess, GUESSES.[Numberguessed] = 0. If 3 is guessed GUESSES.3 = 0 and GUESSES becomes %01110110...

    To determine the lowest number and return it

    IF GUESSES = 0 then all numbers have been guessed
    For LP = 1 to 6
    IF GUESSES.LP = 1 Then
    LP is the lowest number left
    Endif
    Next LP

    I'm not advertising this as suitable code, rather sort of pseudo-code to illustrate the concept.

  3. #3
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: number match selection

    thanks for that - sometime i get caught up in what i am doing and cant think of easy answer

    here is simulated code ill try,my real codes has multi indexed variables ,but the principle is correct
    the end value shown needs to be the lowest number between 1 -6 for my use , 0 is ok as it show there is no " index slots" Left and is used to determine if more index slots are added later

    Code:
    z = 0
    X = 0
    index_slot = 0 
     
    for z = 0 the index                                 ' test to array length 
        if value1(z) & $F0 = value2 then           ' match upper nibble 
          for X = 1 to 6
               Y  = value1(z) & $0F                   ' get lower nibble value into Y
               if  X = Y  then Index_slot.X = 1     ' put a 1 into the bit location representing values 1- 6 of index_slot that have been used    
          next X
     next z
     
    x = 0 
     for X = 6 to 1                                            
        if index_slot.X >> X = 1  then index_slot = X  '  show the lowest value available  index slot for use 
     next X

  4. #4
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: number match selection

    i get a " bad token" error with this , what is the correct way to do it again ?

    Code:
    for X = 6 to 1                                            
        if index_slot.X >> X = 1  then index_slot = X  '  show the lowest value available  index slot for use 
     next X

  5. #5
    Join Date
    Feb 2012
    Location
    PERTH AUSTRALIA
    Posts
    838


    Did you find this post helpful? Yes | No

    Default Re: number match selection

    Code:
    for X = 6 to 1                                            
        if index_slot.0[X] >> X = 1  then index_slot = X  '  show the lowest value available  index slot for use 
     next X

  6. #6
    Join Date
    Apr 2011
    Location
    Welches, Oregon
    Posts
    198


    Did you find this post helpful? Yes | No

    Default Re: number match selection

    Don't forget to add a" STEP -1" to your "FOR" line, unnecessary when counting up, but required to decrement your loop variable

Similar Threads

  1. Target Device does not match selected device
    By queenidog in forum FAQ - Frequently Asked Questions
    Replies: 3
    Last Post: - 25th June 2011, 00:24
  2. PIC received buffers don't match PC sent buffers via USB
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th June 2010, 07:20
  3. A real String type & functions to match
    By Phil Moore in forum PBP Wish List
    Replies: 3
    Last Post: - 25th December 2008, 16:45
  4. Target device does not match
    By krohtech in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd February 2008, 04:20

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts