Thread: Basic combinatorics

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    12

    Basic combinatorics

    you have 3 integers given X,Y,Z
    X is amount of black soldiers
    Y is amount of purple soldiers
    Z is amount of white soldiers

    Calculate how many variations there are if black and white can't stand togethere (a purple must be inbetween). What would be the formula in the case if variations can't and if they can repeat.

  2. #2
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    This literally has nothing to do at all with C++.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    12
    I must solve that in code but I am wondering how this would be done.

  4. #4
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by Tobias Mihel View Post
    I must solve that in code but I am wondering how this would be done.
    As with any problem, before you can hope to solve this in code you need to know how to do it on paper.

    If n = x * y * z then there are n! permutations of soldiers. That's as far as my high-school level combinatorics goes, so what i'd do is to generate all permutations and then discard any permutation where a black and white soldier are neighbours, this should leave you with the remaining legal permutations. This is the naiive approach though, and it would (very) quickly become infeasible as n grows.

    Instead, figure out how to do this using math and a piece of paper, and THEN try to translate it to code.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Necklaces and Bracelets in Combinatorics
    By Stamatis in forum C++ Programming
    Replies: 1
    Last Post: 03-26-2013, 03:29 PM
  2. Basic C
    By toddeeeEEee in forum C Programming
    Replies: 7
    Last Post: 12-05-2011, 12:50 AM
  3. new to C. need basic help
    By k4k45hi in forum C Programming
    Replies: 84
    Last Post: 09-04-2007, 04:39 AM
  4. basic ms-dos sim, need help
    By JOlszewski in forum C++ Programming
    Replies: 1
    Last Post: 01-13-2006, 03:55 PM
  5. This is basic C++
    By incognito in forum C++ Programming
    Replies: 10
    Last Post: 12-12-2001, 08:51 AM