Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $string = <>; #the random bit string is taken as input from STDIN. As of now, it can't contain whitespace
- chomp($string);
- $string = reverse($string);
- TEST2:{
- $stra = $string;
- for(1..240){
- $bits = 0;
- $bits += chop($stra);
- $bits += chop($stra);
- $bits += chop($stra);
- if($bits == 0){
- $zero++
- }
- if($bits == 1){
- $one++
- }
- if($bits == 2){
- $two++
- }
- if($bits == 3){
- $three++
- }
- }
- $zero *= 8/240;
- $one *= 8/240;
- $two *= 8/240;
- $three *= 8/240;
- print "Test 2: $zero (1) $one (3) $two (3) $three (1)\n"; #the proportions should be 1:3:3:1
- }
- TEST3:{
- $strb = $string;
- $state = chop($strb);
- $runlength = 1;
- for(1..998){
- $temp = chop($strb);
- if($temp == $state){
- $runlength++
- }
- else{
- $runs[$runlength]++;
- $state = $temp;
- $runlength = 1;
- }
- }
- print "Test 3: @runs\n"; #the result should be a series of numbers, each 1/2 of the previous number
- }
- TEST3:{
- $strc = $string;
- for(0..209){
- $half1[$_] = chop($strc);
- }
- for(0..209){
- $half2[$_] = chop($strc);
- }
- for(0..209){
- if($half1[$_] == $half2[$_]){
- $same++;
- }
- }
- $same /= 210;
- print "Test 4: $same\n"; #the result should be 0.5
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement