+ Reply to Thread
Results 1 to 10 of 10

Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algorith

  1. #1
    Registered User
    Join Date
    05-01-2016
    Location
    London
    MS-Off Ver
    2016
    Posts
    5

    Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algorith

    Hi Guys, Can you please help me out on this.

    I want to generate random numbers with no duplicates (including negative numbers) lets say from -20 til 20 in no particular order. And then I want to find the series of consectuive numbers within the randomly generated numbers that gives the maximum sum of values, locate the beginning of the series and the length of the series (number of values summed to get the maximum number).

    For Example (-1, 2, -3, 3, 5)

    - Sum = 8 (Sum of 3 and 5) we exclude 2 since it is not part of the consecutive numbers within the series because of -3 in the middle.
    - Beginning location of the series = 4 (since 3 is the 4th number within the series).
    - Length of the series within the series = 2 (Since 3 and 5 are the two consecutive integers within this series that would give the maximum sum of values).

    I need the sum, beggining and the length of the series to be found through formuleas in excel if possible.

    I have across a solution in the below link, but can someone do this using formulaes. I believe its called the kadane's algorithm.

    http://www.i-programmer.info/program...y-problem.html
    Last edited by excelguruwanabee; 05-01-2016 at 06:50 PM.

  2. #2
    Registered User
    Join Date
    05-01-2016
    Location
    London
    MS-Off Ver
    2016
    Posts
    5

    Re: Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algor

    I have attached a file of my working but i am trying to get it fully automated.
    Attached Files Attached Files

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algor

    Kadane's algorithm, which is O(n), doesn't return the start and end indices, and it's not immediately obvious to me how to do so.

    The alternative is a pair of nested loops in O(n^3) time.

    Either way, I don't see any reasonable formula-based solution.
    Last edited by shg; 05-02-2016 at 09:08 AM.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    05-01-2016
    Location
    London
    MS-Off Ver
    2016
    Posts
    5
    Quote Originally Posted by shg View Post
    Kadane's algorithm, which is O(n), doesn't return the start in end indices, and it's not immediately obvious to me how to do so.

    The alternative is a pair of nested loops in O(n^3) time.

    Either way, I don't see any reasonable formua-based solution.
    Hi SHG,

    Can you please help me on this i have no programming background and need the excel to generate the random non repeatable numbers and maybe have something in VBA or any other programming language to solve this and have the results in excel if possible. It doesnt have to be formulea based.

    Thanks and regards

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algor

    What is the urgent purpose of this?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algor

    A
    B
    C
    D
    E
    F
    1
    10
    2
    -5
    Sum
    Start
    Stop
    3
    14
    51
    9
    18
    C3:E3: {=Kadane(A1:A20)}
    4
    7
    5
    -20
    6
    5
    7
    -11
    8
    -17
    9
    15
    10
    17
    11
    -2
    12
    -8
    13
    8
    14
    18
    15
    -14
    16
    1
    17
    -4
    18
    20
    19
    -3
    20
    -7


    Please Login or Register  to view this content.
    Last edited by shg; 05-03-2016 at 11:03 AM.

  7. #7
    Registered User
    Join Date
    05-01-2016
    Location
    London
    MS-Off Ver
    2016
    Posts
    5

    Re: Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algor

    hey SHG,

    Thanks a million, it worked i copied the whole code in vba in a module inserted by writing clicking the sheet then insert module and saved as excel macro enables workbook. generated the numbers and inserted the formulae {= kadane(range)}, and it showed me the max sum. However, i cant get the beg and stop to work. Sorry for not knowing how to get it to work and bothering you and thanks again.
    Last edited by excelguruwanabee; 05-03-2016 at 03:41 PM.

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algor

    Select all three cells, paste the formula in the formula bar, press and hold the Ctrl and Shift keys, then press Enter.

  9. #9
    Registered User
    Join Date
    05-01-2016
    Location
    London
    MS-Off Ver
    2016
    Posts
    5

    Re: Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algor

    It worked!!!! Thanks shg, you just made my day. Thanks again

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Generate Random Numbers with no repeats and maximum Sub-array Problem.. Kadane's algor

    You're welcome.

+ 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. VBA random numbers NO repeats
    By jamiegfinch in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 12-18-2015, 12:01 AM
  2. Maximum Sub-array Problem... Kadane's algorithm?
    By cpinault2008 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 01-13-2015, 05:10 PM
  3. [SOLVED] Generate random comma separated lines of text from list without repeats
    By Banker123456 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-12-2014, 12:00 AM
  4. [SOLVED] Generating Random Numbers between Upper & Lower Limits and without Repeats.
    By e4excel in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-17-2012, 09:42 AM
  5. Replies: 3
    Last Post: 03-21-2010, 09:04 PM
  6. Generate random numbers with no repeats
    By Paul Sheppard in forum Excel General
    Replies: 4
    Last Post: 04-06-2007, 12:37 PM
  7. code not working properly - VBA beginner (random numbers generation, no repeats)
    By msburza in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-11-2006, 01:10 PM

Tags for this Thread

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