Created
January 10, 2015 04:52
-
-
Save glabra/8ccda22d7c6d236917b3 to your computer and use it in GitHub Desktop.
円周率を求める on APL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
⍝ _IB: 整数のビット幅 | |
⍝ _SD: SEED | |
⍝ _AC: sampleの小数点制度 | |
⍝ _TC: 試行回数 | |
_IB←32 | |
_SD←123456789 362436069 521288629 88675123 | |
_AC←10*6 | |
_TC←10 | |
∇R←A Xor B | |
R←(_IB⍴2)⊥1=((_IB⍴2)⊤B)+(_IB⍴2)⊤A | |
⍫ | |
∇R←BITS Shl IN | |
R←(_IB⍴2)⊥(BITS↓(_IB⍴2)⊤IN),BITS⍴0 | |
⍫ | |
∇R←BITS Lshr IN | |
R←(_IB⍴2)⊥(BITS⍴0),(-BITS)↓(_IB⍴2)⊤IN | |
⍫ | |
∇R←_RndBody MAX;t | |
t←_SD[1] Xor 11 Shl _SD[1] | |
_SD←_SD[2 3 4],(_SD[4] Xor 19 Lshr _SD[4]) Xor t Xor 8 Lshr t | |
R←(1+MAX)|_SD[4] | |
⍫ | |
⍝ Range: 0 ~ MAX | |
∇R←Rnd MAX | |
R←_RndBody ¨ MAX | |
⍫ | |
∇R←Sim SIZE | |
tc←SIZE×_TC | |
s←((Rnd tc 2⍴2×_AC)÷_AC)-1 | |
R←(4×+/1≥+/s*2)÷tc | |
⍫ | |
res←(Sim 100) (Sim 810) (Sim 1919) | |
'Samples : Pi' | |
'100 : ',res[1] | |
'810 : ',res[2] | |
'1919 : ',res[3] | |
)OFF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
乱数生成アルゴリズムは Xorshift です