Readme Posted February 4, 2008 Share Posted February 4, 2008 I am trying to find a calculation that will determine the number of two digit combinations that can be derived from twelve numbers, and what those number are. Any thoughts? Example: 68 41 90 100 are the numbers. 68 41 68 90 68 100 41 68 41 90 41 100 90 68 90 41 90 100 100 68 100 41 100 90 Thanks!!! Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/ Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 n * (n-1) or (n^2) - n Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457655 Share on other sites More sharing options...
Readme Posted February 4, 2008 Author Share Posted February 4, 2008 hm Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457666 Share on other sites More sharing options...
Readme Posted February 4, 2008 Author Share Posted February 4, 2008 im noob I need full code Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457669 Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 <?php $nums = array(68,41,90,100); foreach($nums as $i=>$num1){ foreach($nums as $j=>$num2){ if($i == $j) continue; print "$num1 $num2"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457671 Share on other sites More sharing options...
Readme Posted February 4, 2008 Author Share Posted February 4, 2008 Good job!! But Result (incorrect): 68 4168 9068 10041 6841 9041 10090 6890 4190 100100 68100 41100 90 correct 100% 68 41 68 90 68 100 41 68 41 90 41 100 90 68 90 41 90 100 100 68 100 41 100 90 my English is not very good Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457686 Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 It is correct, I just didn't put a line break tag in it: <?php $nums = array(68,41,90,100); foreach($nums as $i=>$num1){ foreach($nums as $j=>$num2){ if($i == $j) continue; print "$num1 $num2<br>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457691 Share on other sites More sharing options...
Readme Posted February 4, 2008 Author Share Posted February 4, 2008 The last question. How to create a combination of 6 numbers? Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457713 Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 How are you using this? As in, how are you getting the numbers? Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457716 Share on other sites More sharing options...
Readme Posted February 4, 2008 Author Share Posted February 4, 2008 Sometimes I use two combinations, sometimes 3 and extremely rarely 6. Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457757 Share on other sites More sharing options...
rhodesa Posted February 4, 2008 Share Posted February 4, 2008 so something like this? <?php function getCombos ( $arr, $n ,$stack = array(), $combos = array()){ if(count($stack) < $n){ foreach(array_keys($arr) as $key){ if(in_array($key,array_keys($stack))) continue; $combos = getCombos($arr,$n,array_merge($stack,array($key=>$arr[$key])),$combos); } }else $combos[] = array_values($stack); return $combos; } $nums = array(68,41,90,100,32,56,78,34,23,53); $combos = getCombos($nums,3); foreach($combos as $combo) print implode(' ',$combo)."<br>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457784 Share on other sites More sharing options...
Readme Posted February 4, 2008 Author Share Posted February 4, 2008 Yes!!! Thank you very much. Very good job Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-457796 Share on other sites More sharing options...
Readme Posted February 7, 2008 Author Share Posted February 7, 2008 How do! When creating a combination of numbers, the number sequence becomes too long, and to avoid this, you need to bring in an exact number (68). Example: $number = array([68],41,90,100,32,56 [68] is exact number 68 41 90 100 32 56 68 41 90 100 56 56 68 41 90 32 32 56 68 41 90 32 56 56 68 41 90 56 32 56 68 41 90 56 56 56 Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-460941 Share on other sites More sharing options...
Readme Posted February 8, 2008 Author Share Posted February 8, 2008 rhodesa ? Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-461739 Share on other sites More sharing options...
rhodesa Posted February 8, 2008 Share Posted February 8, 2008 I didn't see a question, and thought you were informing me of something. What is the question exactly? Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-461746 Share on other sites More sharing options...
Readme Posted February 8, 2008 Author Share Posted February 8, 2008 $nums = array(68,41,90,100,32,56) That it takes the first number (68) and creates a combination with other numbers; then further number 41 and creates new combination, etcetera. I would need it this way, that by giving it a number, the system would create a combination with other numbers. My English is not very good Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-461807 Share on other sites More sharing options...
rhodesa Posted February 8, 2008 Share Posted February 8, 2008 I think I see what you are asking. Just leave the first number off the front of the array, and add it back when printing: <?php function getCombos ( $arr, $n ,$stack = array(), $combos = array()){ if(count($stack) < $n){ foreach(array_keys($arr) as $key){ if(in_array($key,array_keys($stack))) continue; $combos = getCombos($arr,$n,array_merge($stack,array($key=>$arr[$key])),$combos); } }else $combos[] = array_values($stack); return $combos; } $base = 68; $nums = array(41,90,100,32,56); $combos = getCombos($nums,count($nums)); foreach($combos as $combo) print $base." ".implode(' ',$combo)."<br>"; ?> output: 68 41 90 100 32 56 68 41 90 100 56 56 68 41 90 32 32 56 68 41 90 32 56 56 68 41 90 56 32 56 68 41 90 56 56 56 68 41 100 100 32 56 68 41 100 100 56 56 68 41 100 32 32 56 68 41 100 32 56 56 68 41 100 56 32 56 68 41 100 56 56 56 68 41 32 100 32 56 68 41 32 100 56 56 68 41 32 32 32 56 68 41 32 32 56 56 68 41 32 56 32 56 68 41 32 56 56 56 68 41 56 100 32 56 68 41 56 100 56 56 68 41 56 32 32 56 68 41 56 32 56 56 68 41 56 56 32 56 68 41 56 56 56 56 68 90 90 100 32 56 68 90 90 100 56 56 68 90 90 32 32 56 68 90 90 32 56 56 68 90 90 56 32 56 68 90 90 56 56 56 68 90 100 100 32 56 68 90 100 100 56 56 68 90 100 32 32 56 68 90 100 32 56 56 68 90 100 56 32 56 68 90 100 56 56 56 68 90 32 100 32 56 68 90 32 100 56 56 68 90 32 32 32 56 68 90 32 32 56 56 68 90 32 56 32 56 68 90 32 56 56 56 68 90 56 100 32 56 68 90 56 100 56 56 68 90 56 32 32 56 68 90 56 32 56 56 68 90 56 56 32 56 68 90 56 56 56 56 68 100 90 100 32 56 68 100 90 100 56 56 68 100 90 32 32 56 68 100 90 32 56 56 68 100 90 56 32 56 68 100 90 56 56 56 68 100 100 100 32 56 68 100 100 100 56 56 68 100 100 32 32 56 68 100 100 32 56 56 68 100 100 56 32 56 68 100 100 56 56 56 68 100 32 100 32 56 68 100 32 100 56 56 68 100 32 32 32 56 68 100 32 32 56 56 68 100 32 56 32 56 68 100 32 56 56 56 68 100 56 100 32 56 68 100 56 100 56 56 68 100 56 32 32 56 68 100 56 32 56 56 68 100 56 56 32 56 68 100 56 56 56 56 68 32 90 100 32 56 68 32 90 100 56 56 68 32 90 32 32 56 68 32 90 32 56 56 68 32 90 56 32 56 68 32 90 56 56 56 68 32 100 100 32 56 68 32 100 100 56 56 68 32 100 32 32 56 68 32 100 32 56 56 68 32 100 56 32 56 68 32 100 56 56 56 68 32 32 100 32 56 68 32 32 100 56 56 68 32 32 32 32 56 68 32 32 32 56 56 68 32 32 56 32 56 68 32 32 56 56 56 68 32 56 100 32 56 68 32 56 100 56 56 68 32 56 32 32 56 68 32 56 32 56 56 68 32 56 56 32 56 68 32 56 56 56 56 68 56 90 100 32 56 68 56 90 100 56 56 68 56 90 32 32 56 68 56 90 32 56 56 68 56 90 56 32 56 68 56 90 56 56 56 68 56 100 100 32 56 68 56 100 100 56 56 68 56 100 32 32 56 68 56 100 32 56 56 68 56 100 56 32 56 68 56 100 56 56 56 68 56 32 100 32 56 68 56 32 100 56 56 68 56 32 32 32 56 68 56 32 32 56 56 68 56 32 56 32 56 68 56 32 56 56 56 68 56 56 100 32 56 68 56 56 100 56 56 68 56 56 32 32 56 68 56 56 32 56 56 68 56 56 56 32 56 68 56 56 56 56 56 Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-461810 Share on other sites More sharing options...
Readme Posted February 8, 2008 Author Share Posted February 8, 2008 Yes! Thanks man Quote Link to comment https://forums.phpfreaks.com/topic/89376-number-combination-calculation/#findComment-461816 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.