Advertisement
szabozoltan69

subsets3

May 14th, 2014
277
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/php
  2. <?php
  3.  
  4. define('n',"\n");
  5. function olvasd($i){global $f_,$elsok;  if (($tmp=fgets($f_[$i])) !== false) {$elsok[$i]=trim($tmp);} else unset($elsok[$i]); }
  6.  
  7. $f_[]= @fopen('a', 'r');
  8. $f_[]= @fopen('b', 'r');
  9. $f_[]= @fopen('c', 'r');
  10. $f_[]= @fopen('d', 'r');
  11. $f_[]= @fopen('e', 'r');
  12. $fsize=sizeof($f_); print $fsize." input files will be processed...".n;
  13. for($i=0;$i<pow(2,$fsize);$i++){$tmp='f'.str_pad(decbin($i),$fsize,'0',STR_PAD_LEFT); $$tmp=@fopen($tmp,'w'); /* print str_pad(decbin($i),4,'0',STR_PAD_LEFT)."\n"; */ }
  14. //$f0..00=@fopen('f0..00', 'w');
  15. //..
  16. //$f1..11=@fopen('f1..11', 'w');
  17.  
  18. $elsok=array(); for($i=0;$i<$fsize;$i++) olvasd($i);
  19.  
  20. while (!empty($elsok)) {
  21.     asort($elsok); $elso_k=array_keys($elsok); $kiirni=$elsok[$elso_k[0]]; $fajlnev="f";
  22.     for($i=0;$i<$fsize;$i++) {if ((array_key_exists($i,$elsok))&&($kiirni==$elsok[$i])) {$fajlnev.="1"; olvasd($i);} else {$fajlnev.="0";}}
  23.     fwrite($$fajlnev, $kiirni.n);
  24. }
  25.  
  26. for($i=0;$i<      $fsize; $i++) if (!feof($f_[$i])) {echo "Hiba: varatan fgets() problema.".n;} ;
  27. for($i=0;$i<      $fsize; $i++)    fclose($f_[$i]);
  28. for($i=0;$i<pow(2,$fsize);$i++){$tmp='f'.str_pad(decbin($i),$fsize,'0',STR_PAD_LEFT); fclose($$tmp); print $tmp." file created.\n"; }
  29.  
  30. /* 5 input files will be processed...
  31. f00000 file created.
  32. f00001 file created.
  33. f00010 file created.
  34. f00011 file created.
  35. f00100 file created.
  36. f00101 file created.
  37. f00110 file created.
  38. f00111 file created.
  39. f01000 file created.
  40. f01001 file created.
  41. f01010 file created.
  42. f01011 file created.
  43. f01100 file created.
  44. f01101 file created.
  45. f01110 file created.
  46. f01111 file created.
  47. f10000 file created.
  48. f10001 file created.
  49. f10010 file created.
  50. f10011 file created.
  51. f10100 file created.
  52. f10101 file created.
  53. f10110 file created.
  54. f10111 file created.
  55. f11000 file created.
  56. f11001 file created.
  57. f11010 file created.
  58. f11011 file created.
  59. f11100 file created.
  60. f11101 file created.
  61. f11110 file created.
  62. f11111 file created.
  63.  
  64. real    0m10.329s
  65. user    0m8.437s
  66. sys 0m1.880s
  67. */
  68. ?>
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement