+ Reply to Thread
Results 1 to 4 of 4

Finding Consecutive Values in a List of Numbers

  1. #1
    Registered User
    Join Date
    03-13-2019
    Location
    Brisbane
    MS-Off Ver
    1901
    Posts
    2

    Finding Consecutive Values in a List of Numbers

    Hey everyone,
    I'm at a loss as to how to do this. I have a list of 4 numbers being randomly generated (between 1 and 40). What I need to do is compare a preselected set of 4 numbers (between 1 and 40) to the ones generated, and record if they match. So, basically these numbers generated have to match the preselected numbers exactly. So,

    Comparing 12, 15, 37, 22 (the preselected set) to (Insert random numbers between 1 and 40 here). Same order as well.
    Thanks.

  2. #2
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Finding Consecutive Values in a List of Numbers

    Like this?

    match.png

    The formula in E1 is an array formula - commit with CTRL-SHIFT-ENTER:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    B2:B5 for you would be:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    In the example, if B3 were 15 rather than 14 then the E1 formula would return TRUE.

  3. #3
    Registered User
    Join Date
    03-13-2019
    Location
    Brisbane
    MS-Off Ver
    1901
    Posts
    2

    Re: Finding Consecutive Values in a List of Numbers

    Thankyou for the quick reply!
    Yes, this is what I was after. Well, mostly. Firstly, how can I keep track of how many TRUE's I get (or wins, because this is more of a lottery-style thing)? Also, how can I make it so that i can also get a TRUE (win) with 3 of the 4 numbers in a row? And record this as well?
    Thanks in advance!

  4. #4
    Forum Expert
    Join Date
    10-15-2018
    Location
    MA, USA
    MS-Off Ver
    2010, 2019
    Posts
    1,616

    Re: Finding Consecutive Values in a List of Numbers

    I'm not sure how you plan to use this. With 4 numbers each in the range [1..40] the probability of all 4 matching is 1 in 40^4 or 1 in 2,560,000. You're going to wear out your F9 key

    You could have VBA doing the re-calculate and keeping count of how many trys are needed before you match all four if that would be interesting. In fact that is what I have implemented in the attached workbook.

    "how can I make it so that i can also get a TRUE (win) with 3 of the 4 numbers in a row?"
    . So by these rules rows 2,3,4 matching counts, rows 3,4,5 matching counts, but no other row sets like 2, 4, 5 are allowed to count??

    The easier thing to calculate is is any set of 3 matching pairs. To do that simply change the "4" in the formula in E1 to "3". I believe the probability of a match in this case is 1 in 40^3/4 or 1 in 16,000. This is what I have limited things to at the moment.

    In the attached workbook, first - MAKE SURE MACROS ARE ENABLED then set cell E2 to the number of required matches (1, 2, 3 or 4), then either hit F9 to recalculate and see the tries one by one or alternatively hit the "Run" button and wait for the "Needed tries" to be updated. My somewhat long in the tooth laptop takes on average about 5 sec for 3 matching pairs and I expect it to take about 2 - 3 minutes on average for 4 matches.

    Here's how the worksheet looks:

    probabilities.png

    Here's the VBA:
    Please Login or Register  to view this content.
    Let me know if you want to explore this any further.
    Attached Files Attached Files
    Last edited by GeoffW283; 03-14-2019 at 06:22 PM. Reason: Forgot to attach workbook

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Finding 5 consecutive numbers in a set of 7 numbers
    By Namejs in forum Excel General
    Replies: 13
    Last Post: 05-20-2015, 06:35 AM
  2. Finding 2 out of 3 consecutive equal cell values
    By Runnyink in forum Excel General
    Replies: 1
    Last Post: 09-11-2012, 01:49 AM
  3. [SOLVED] Finding Consecutive Numbers
    By RebeccaArmstrong in forum Excel General
    Replies: 10
    Last Post: 05-11-2012, 11:52 AM
  4. [SOLVED] Finding consecutive numbers or dates
    By Mattieu in forum Excel General
    Replies: 5
    Last Post: 04-27-2012, 04:42 AM
  5. Excel macro to "fill in" consecutive numbers in non-consecutive list?
    By Tomkat in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2009, 01:13 PM
  6. finding consecutive values in array
    By upstate_steve in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-11-2005, 03:37 PM
  7. finding consecutive values in array
    By upstate_steve in forum Excel General
    Replies: 0
    Last Post: 01-11-2005, 01:03 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1