Thread: computing points depending from values of vector

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    5

    computing points depending from values of vector

    Hello,
    I am pretty new to the c++ language I am doing a coding challenge regarding checking the values of a vector.

    I have been stuck on this challenge for hours and I can't think of a proper solution.

    I have a vector which is called values that looks like this :

    Code:
    std::vector <char > values {a,b,a,b,b,b,a,a,a,a,b,b,a};
    
    Then after three values a column is started , so at the end this is how the values should be looked at
    Code:
    abaaa
    bbab
    abab
    Player 1 has the letter a and player 2 the letter b.
    If player one has orthogonally connecting a's (exluding diagonal a's) he get's points at the end of the iteration.
    If one a is not connected to any other a player 1 get's one point. Two a's are worth 2 points and for 3 a's 5 points. Always excluding diagonal a's.
    If there are more than 3 connected a's player 1 gets 2 points extra. for example 4 a's 7 points and 5' as 9 points.
    This applies for player 2 as well.
    The tricky part is that a player can get points for more than one group of orthogonally connects a's or b's.
    So for example if player 1 has a group of 3 'as he gets 5 points. If he also has a single a he get's a point.
    So at the end he get's 6 points altogether.

    in this case:
    Code:
    abaaa
    bbab
    abab
    Player 1 gets : 9+1+1
    Player 2 gets: 7+2

    I hope my question is clear.
    I would be thankful for any hint.
    Last edited by kaido; 01-07-2021 at 10:48 AM. Reason: removed the +2 points

  2. #2
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    You say "C language", but you mean "C++ language". Although they are related, they are radically different.

    In player 1's score, I see where the 9 and the two 1's come from, but where does the 2 come from? I feel I don't understand your explanation of the "tricky" part: "a player can get points for more than one group of orthogonally connects a's or b's."
    A little inaccuracy saves tons of explanation. - H.H. Munro

  3. #3
    Registered User
    Join Date
    Dec 2019
    Posts
    5
    sorry I made a mistake the two points are wrong . i will remove it.
    The tricky part in my opinion is how to determine that player 1 get's 9+1+1 points by checking if the letters are connected orthogonally and ignoring the other letter b and also excluding diagonal letters for each player
    Last edited by kaido; 01-07-2021 at 10:48 AM.

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    Okay, that makes sense now.

    I think you will need a kind of "floodfill" algorithm.
    (Hopefully someone else will suggest a simpler solution if it exists.)
    The floodfill function is recursive.
    Do you know anything about recursion?

    BTW, what is the maximum size of the values vector?
    A little inaccuracy saves tons of explanation. - H.H. Munro

  5. #5
    Registered User
    Join Date
    Dec 2019
    Posts
    5
    Thanks for the suggestion.
    No I don't really know much about recursions.
    But I will check out the floodfill algorithm
    The maximum size of values can be anything. I just tried it with these values.

  6. #6
    Registered User
    Join Date
    Dec 2017
    Posts
    1,628
    So the size of the value array could be trillions of characters?
    Are you sure your computer has enough memory?
    Maybe you should look at the problem description again.
    Usually there are constraints to these kinds of problems.
    If you have a link to the problem description, post it.
    A little inaccuracy saves tons of explanation. - H.H. Munro

  7. #7
    Registered User
    Join Date
    Dec 2019
    Posts
    5
    the maximum size could can be 24 so space for a maximum amount of 23 letters

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 12-23-2020, 12:38 PM
  2. Replies: 4
    Last Post: 12-10-2013, 02:29 AM
  3. Bidirectional loop? (Increase/decrease depending on values)
    By BlueGooGames in forum C Programming
    Replies: 4
    Last Post: 01-08-2011, 12:08 PM
  4. Replies: 10
    Last Post: 06-10-2010, 09:52 PM
  5. Computing Large Values
    By swbluto in forum C++ Programming
    Replies: 8
    Last Post: 04-07-2005, 03:04 AM

Tags for this Thread