Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- namespace Libraries
- {
- public class Probleme
- {
- public List<int> listInput = new List<int>();
- public List<List<int>> listOutput = new List<List<int>>();
- public void Init()
- {
- for (int i = 1; i <= 6; i++)
- {
- listInput.Add(i);
- }
- listOutput = calc(listInput);
- Debug.Log(listOutput.Count + " combinaisons possibles de " + ArrayToString(listInput));
- foreach (List<int> combi in listOutput)
- {
- combi.Reverse();
- Debug.Log(ArrayToString(combi));
- }
- }
- public string ArrayToString(List<int> list)
- {
- StringBuilder sb = new StringBuilder();
- sb.Append("[");
- for (int i = 0 ; i < list.Count ; i++)
- {
- sb.Append((i > 0?",":"") + list[i]);
- }
- sb.Append("]");
- return sb.ToString();
- }
- public List<List<int>> calc(List<int> listCurrentInput)
- {
- List<List<int>> result = new List<List<int>>();
- if (listCurrentInput.Count == 1)
- {
- List<int> subCombi = new List<int>(listCurrentInput);
- result.Add(subCombi);
- }
- else
- {
- for (int i = 0; i < listCurrentInput.Count; i++)
- {
- List<int> listNewInput = new List<int>(listCurrentInput);
- listNewInput.Remove(listCurrentInput[i]);
- List<List<int>> combi = calc(listNewInput);
- foreach (List<int> subCombi in combi)
- {
- subCombi.Add(listCurrentInput[i]);
- result.Add(subCombi);
- }
- }
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement