Advertisement
arkanon

Identificação de sequências numéricas na expansão decimal de π

Jun 5th, 2025 (edited)
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Arkanon <[email protected]>
  4. # 2025/06/05 (Thu) 04:26:45 -03
  5. # 2025/06/05 (Thu) 02:30:17 -03
  6.  
  7. # <http://atractor.pt/mat/fromPI/PIsearch.html>
  8.  
  9.  
  10. sudo apt-get install pi
  11.  
  12. time pi $((10**9)) > pi  # 67m9,650s
  13.  
  14. wc -c < pi               # 1000000002
  15. sed "s/^..//" pi | wc -c # 1000000000
  16.  
  17. for i in F G E P; { time grep -o$i $s pi; }
  18.  
  19. dd if=pi bs=1c skip=2 count=10 2>&-; echo # 1415926535
  20.  
  21.  
  22. pos()
  23. {
  24.   local n i s=${1?}
  25.   time n=$(grep -oF $s pi | wc -l) # 11
  26.   echo $n
  27.   time for ((i=1;i<=n;i++))
  28.   {
  29.     sed "s/^..//;s/$s/\n/$i" pi |
  30.     LC_NUMERIC=pt_BR.utf8 awk '{printf "%'\''11i\n", 1+length}' |
  31.     head -n1
  32.   } | nl -w3 -s'  '
  33. }
  34.  
  35.  
  36. check()
  37. {
  38.   local pos=${1?} len=${2?}
  39.   dd if=pi bs=1c skip=$((2+${pos//.}-1)) count=$len 2>&-; echo
  40. }
  41.  
  42.  
  43. # <http://fb.com/bbcnewsbrasil/videos/718526187341534/?comment_id=1219544899384535>
  44.  
  45. pos 06111982 8
  46. #  1  132.441.625
  47. #  2  140.362.410
  48. #  3  165.026.204
  49. #  4  231.707.620
  50. #  5  523.214.813
  51. #  6  544.500.848
  52. #  7  670.248.601
  53. #  8  692.815.027
  54. #  9  847.186.872
  55. # 10  906.621.305
  56. # 11  907.622.927
  57. #
  58. # 0m03,718s
  59. # 1m24,856s
  60.  
  61. check 907.622.927 8
  62.  
  63. pos 19821106
  64. #  1   40.586.516
  65. #  2   45.463.015
  66. #  3  255.076.215
  67. #  4  282.922.620
  68. #  5  327.418.957
  69. #  6  410.776.841
  70. #  7  516.909.942
  71. #  8  581.766.209
  72. #  9  604.401.827
  73. # 10  806.850.982
  74. # 11  846.107.576
  75. # 12  908.604.255
  76. #
  77. # 0m02,779s
  78. # 1m28,778s
  79.  
  80.  
  81. # <http://fb.com/bbcnewsbrasil/videos/718526187341534/?comment_id=9801557443245986>
  82.  
  83. pos 20021986
  84. #  1   29.458.308
  85. #  2  125.210.989
  86. #  3  193.439.009
  87. #  4  199.246.089
  88. #  5  236.427.252
  89. #  6  509.117.561
  90. #  7  520.446.597
  91. #  8  629.973.436
  92. #  9  721.062.016
  93. # 10  732.115.060
  94. # 11  745.321.152
  95. # 12  754.075.841
  96. # 13  821.453.254
  97. # 14  918.890.445
  98. # 15  935.662.384
  99. # 16  962.787.711
  100. #
  101. # 0m02,869s
  102. # 2m07,777s
  103.  
  104. check 199.246.089
  105.  
  106. pos 19860220
  107. #  1   14.455.109
  108. #  2   57.871.929
  109. #  3   83.133.937
  110. #  4  122.586.287
  111. #  5  242.974.880
  112. #  6  443.154.654
  113. #  7  482.601.851
  114. #  8  483.049.239
  115. #  9  664.132.876
  116. # 10  821.019.387
  117. # 11  861.891.996
  118. #
  119. # 0m2,871s
  120. # 1m15,337s
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement