Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> wszystkie mozliwe kombinacje, algorytm
deniol13
post
Post #1





Grupa: Zarejestrowani
Postów: 190
Pomógł: 2
Dołączył: 30.11.2009

Ostrzeżenie: (10%)
X----


witam, poszukuje skryptu/algorytmu ktory z jakiejs tablicy ktora zawiera integery wszystkie kombinacje bez powtorzen
np

$tab[a] = 1;
$tab[b] = 2;
$tab[c] = 3;

wszystkie kombinacje to
123
213
321
312
231
i moze jeszcze pare
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
paxton
post
Post #2





Grupa: Zarejestrowani
Postów: 66
Pomógł: 1
Dołączył: 22.06.2009
Skąd: Londyn, UK

Ostrzeżenie: (0%)
-----


10 sekund szukania w google
  1. <?php
  2. header('Content-Type: text/plain');
  3.  
  4. function showCombinations($string, $traits, $i)
  5. {
  6. if ($i >= count($traits))
  7. echo trim($string) . "\n";
  8. else
  9. {
  10. foreach ($traits[$i] as $trait)
  11. showCombinations("$string $trait", $traits, $i + 1);
  12. }
  13. }
  14.  
  15. $traits = array
  16. (
  17. array(1, 2, 3, 4),
  18. array(1, 2, 3, 4),
  19. array(1, 2, 3, 4)
  20. );
  21.  
  22. showCombinations('', $traits, 0);
  23. ?>

Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 14:32