Advertisement
Quantumzblue

binary combination in array

Aug 8th, 2018
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.54 KB | None | 0 0
  1.  
  2. use strict;
  3. $| =1;
  4.  
  5.  my @bitC = (0.075, 0.15, 0.3, 0.6, 1.18, 2.35, 4.7, 9.4, 18.8, 37.6);
  6.           # the value combinations according to bit.
  7.                   #2 power n = prosibility as n bit.
  8. for (my $i = 0; $i<2**scalar(@bitC);  $i++){
  9. my @bits = split(//,sprintf ("%b", $i));
  10. print $i." as bin:";
  11. my $capa = 0;
  12. my $c =scalar(@bits);
  13. foreach (@bits){
  14.   print $_;
  15. if ( $_ == 1 ) {
  16.   $capa = $capa + $bitC[$c - 1]; $c--;
  17. }else {$capa = $capa +0 ; $c--;}
  18.  
  19. }
  20. print "  : ".$capa."\n";
  21. #print $capa."\n";
  22. print "\n";
  23. }
  24. sleep();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement