fork download
  1. $string = <>; #the random bit string is taken as input from STDIN. As of now, it can't contain whitespace
  2. chomp($string);
  3. $string = reverse($string);
  4.  
  5. TEST2:{
  6. $stra = $string;
  7. for(1..240){
  8. $bits = 0;
  9. $bits += chop($stra);
  10. $bits += chop($stra);
  11. $bits += chop($stra);
  12. if($bits == 0){
  13. $zero++
  14. }
  15. if($bits == 1){
  16. $one++
  17. }
  18. if($bits == 2){
  19. $two++
  20. }
  21. if($bits == 3){
  22. $three++
  23. }
  24. }
  25. $zero *= 8/240;
  26. $one *= 8/240;
  27. $two *= 8/240;
  28. $three *= 8/240;
  29. print "Test 2: $zero (1) $one (3) $two (3) $three (1)\n"; #the proportions should be 1:3:3:1
  30. }
  31.  
  32. TEST3:{
  33. $strb = $string;
  34. $state = chop($strb);
  35. $runlength = 1;
  36. for(1..998){
  37. $temp = chop($strb);
  38. if($temp == $state){
  39. $runlength++
  40. }
  41. else{
  42. $runs[$runlength]++;
  43. $state = $temp;
  44. $runlength = 1;
  45. }
  46. }
  47. print "Test 3: @runs\n"; #the result should be a series of numbers, each 1/2 of the previous number
  48. }
  49.  
  50. TEST3:{
  51. $strc = $string;
  52. for(0..209){
  53. $half1[$_] = chop($strc);
  54. }
  55. for(0..209){
  56. $half2[$_] = chop($strc);
  57. }
  58. for(0..209){
  59. if($half1[$_] == $half2[$_]){
  60. $same++;
  61. }
  62. }
  63. $same /= 210;
  64. print "Test 4: $same\n"; #the result should be 0.5
  65. }
Success #stdin #stdout 0s 4552KB
stdin
1101110011011110101011010011110011101101110110110010000010100110001001101100001111000010101001001011100001001011010111001101000001010100001000000101000100111001111101011010000101111101010011001001110110010000110010000100010011100100110100000111101001010001001010111001010111100100010111000001001011110001011010001111100010110101100010011111011101000001101011010111011001100100101100010001100011110010100101011010000100001111101000000010000001010101000001001000100000010010000010110010010011000100101110111101111110010001110001101011011111010110001000001110101010001100101001110111001111000010100110000000111001000010000010101011100000010000110111011010110110101110000110010110100101011000000110100100011110100111010010000010000000000111110011100100111011011001110101010101110110010000101100000111011111000110010110100000110101100111101001101000010111100110011001100010010010001001000111111000000000101110101000011110001010010000110110001101101011000101010001101001101110001011011011101110101110001010
stdout
Test 2: 1.26666666666667 (1) 3.16666666666667 (3) 2.8 (3) 0.766666666666667 (1)
Test 3:  268 126 61 30 20 7 2  1 1
Test 4: 0.466666666666667