Skip to main content
added 376 characters in body
Source Link
Rosario
  • 351
  • 5

APL(NARS), 100109 chars

r←a F w;d;v;m;p
r←d←1+(2≠↑a)×w-1⋄m←w×wׯ1⋄p←2⊃a⋄v←0 1-2=↑a
→0×⍳0≥p-←1⋄r+←d×←m÷×/v+←2⋄→2

6⍕¨(⊂1 2)⎕⍪{6⍕⍵a[2]F F⎕1⊃a}¨⍳2⊣a←⎕

15+42+28+2+13=10015+42+28+2+22=109

the last line call the function F that is a sin and cos function depend of first input on the left (inputit is ≠2 is sin input =2 is cos). Some test:

      6⍕¨(⊂1 2)⎕ F⎕
⎕:
     ⍪{6⍕⍵a[2]F 31⊃a}¨⍳2⊣a←⎕
⎕:
      5 3
  10.208333 
  14.541667 
      6⍕¨(⊂1 2)⎕⍪{6⍕⍵a[2]F F⎕1⊃a}¨⍳2⊣a←⎕
⎕:
      12   8.555 
⎕:13
    0.765431  6.54
  0.253986 0¯0.967147641092 
      6⍕¨(⊂1 2)⎕⍪{6⍕⍵a[2]F F⎕1⊃a}¨⍳2⊣a←⎕
⎕:
      13
⎕:
   9.26 10
  8¯3.555154677 
  0.765431 ¯0¯8.641092404354 

OT it would be possible to calculate the exactexact answer using rationals and input rational for example of 1r4 (0.25=1/4)

      ⍪{6⍕⍵a[2]F 1⊃a}¨⍳2⊣a←⎕
⎕:
      1r4 10
  0.247404 
  0.968912 
      {⍵○1r4}¨⍳2
  0.2474039593 0.9689124217 
      {⍵○0.25}¨⍳2
  0.2474039593 0.9689124217 
      1 10 F 1r4      
  8264318085745811128158727r33404146443928530321408000 
      2 10 F 1r4 
  17051609536099989115458551r17598710837038136237752320   
        

thisthese last number2 numbers both cut, it would be the decimaldecimals 0.247403959254522929592474039592 and 0.9689124217

APL(NARS), 100 chars

r←a F w;d;v;m;p
r←d←1+(2≠↑a)×w-1⋄m←w×wׯ1⋄p←2⊃a⋄v←0 1-2=↑a
→0×⍳0≥p-←1⋄r+←d×←m÷×/v+←2⋄→2

6⍕¨(⊂1 2)⎕ F⎕

15+42+28+2+13=100

the last line call the function F that is a sin and cos function depend of input (input ≠2 is sin input =2 is cos). Some test:

      6⍕¨(⊂1 2)⎕ F⎕
⎕:
      3
⎕:
      5
  10.208333 14.541667 
      6⍕¨(⊂1 2)⎕ F⎕
⎕:
      12    
⎕:
      6.54
  0.253986 0.967147 
      6⍕¨(⊂1 2)⎕ F⎕
⎕:
      13
⎕:
      8.555
  0.765431 ¯0.641092 

OT it would be possible to calculate the exact answer using rationals and input rational

     1 10 F 1r4
8264318085745811128158727r33404146443928530321408000

this last number cut, it would be the decimal 0.24740395925452292959

APL(NARS), 109 chars

r←a F w;d;v;m;p
r←d←1+(2≠↑a)×w-1⋄m←w×wׯ1⋄p←2⊃a⋄v←0 1-2=↑a
→0×⍳0≥p-←1⋄r+←d×←m÷×/v+←2⋄→2

⍪{6⍕⍵a[2]F 1⊃a}¨⍳2⊣a←⎕

15+42+28+2+22=109

the last line call the function F that is a sin and cos function depend of first input on the left (it is ≠2 is sin input =2 is cos). Some test:

      ⍪{6⍕⍵a[2]F 1⊃a}¨⍳2⊣a←⎕
⎕:
      5 3
  10.208333 
  14.541667 
      ⍪{6⍕⍵a[2]F 1⊃a}¨⍳2⊣a←⎕
⎕:
      8.555 13
  0.765431  
  ¯0.641092 
      ⍪{6⍕⍵a[2]F 1⊃a}¨⍳2⊣a←⎕
⎕:
      9.26 10
  ¯3.154677 
  ¯8.404354 

OT it would be possible to calculate the exact answer using rationals and input rational for example of 1r4 (0.25=1/4)

      ⍪{6⍕⍵a[2]F 1⊃a}¨⍳2⊣a←⎕
⎕:
      1r4 10
  0.247404 
  0.968912 
      {⍵○1r4}¨⍳2
  0.2474039593 0.9689124217 
      {⍵○0.25}¨⍳2
  0.2474039593 0.9689124217 
      1 10 F 1r4      
  8264318085745811128158727r33404146443928530321408000 
      2 10 F 1r4 
  17051609536099989115458551r17598710837038136237752320   
        

these last 2 numbers both cut would be the decimals 0.2474039592 and 0.9689124217

deleted 331 characters in body
Source Link
Rosario
  • 351
  • 5

APL(NARS), 116100 chars

r←a CF w;d;v;m;p
r←d←1+(2≠↑a)×w-1⋄m←w×wׯ1⋄p←2⊃a⋄v←0 1-(2=↑a)
→0×⍳0≥p-←1⋄r+←d×←m÷×/v+←2⋄→2

z←⎕⋄6⍕16⍕¨(⊂1 z[2]C↑z⋄6⍕22)⎕ z[2]C↑zF⎕

15+44+28+2+27=11615+42+28+2+13=100

the last line call the function CF that is a sin and cos function depend of input (input ≠2 is sin input =2 is cos). Some test:

      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕26⍕¨(⊂1 z[2]C↑z2)⎕ F⎕
⎕:
      5 3
 10.208333
 14.541667
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      8.555 135
 0 10.765431
208333 ¯014.641092
541667  
     z←⎕⋄6⍕1 z[2]C↑z⋄6⍕26⍕¨(⊂1 z[2]C↑z2)⎕ F⎕
⎕:
      9.26 10
 ¯3.154677
 ¯8.404354
     12 z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      6.54 12
  0.253986
  0.967147
   
     z←⎕⋄6⍕1 z[2]C↑z⋄6⍕26⍕¨(⊂1 z[2]C↑z2)⎕ F⎕
⎕:
      5 1
 5.000000
 1.000000
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 13
⎕:
      20 208.555
 ¯5364 0.411846
765431 ¯10898¯0.499385641092 

OT it would be possible to calculate the exact answer using rationals and input rational

      z←⎕⋄1 z[2]C↑z⋄2 z[2]C↑z 
⎕:
   1 10 F 1r4  10
8264318085745811128158727r33404146443928530321408000 
17051609536099989115458551r17598710837038136237752320

this last number cut, it would be the decimal 0.24740395925452292959

APL(NARS), 116 chars

r←a C w;d;v;m;p
r←d←1+(2≠↑a)×w-1⋄m←w×wׯ1⋄p←2⊃a⋄v←0 1-(2=↑a)
→0×⍳0≥p-←1⋄r+←d×←m÷×/v+←2⋄→2

z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z

15+44+28+2+27=116

the last line call the function C that is a sin and cos function depend of input (input ≠2 is sin input =2 is cos)

      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      5 3
 10.208333
 14.541667
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      8.555 13
 0.765431
 ¯0.641092
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      9.26 10
 ¯3.154677
 ¯8.404354
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      6.54 12
 0.253986
  0.967147
       z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      5 1
 5.000000
 1.000000
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      20 20
 ¯5364.411846
 ¯10898.499385

OT it would be possible to calculate the exact answer using rationals and input rational

      z←⎕⋄1 z[2]C↑z⋄2 z[2]C↑z 
⎕:
      1r4  10
8264318085745811128158727r33404146443928530321408000 
17051609536099989115458551r17598710837038136237752320

APL(NARS), 100 chars

r←a F w;d;v;m;p
r←d←1+(2≠↑a)×w-1⋄m←w×wׯ1⋄p←2⊃a⋄v←0 1-2=↑a
→0×⍳0≥p-←1⋄r+←d×←m÷×/v+←2⋄→2

6⍕¨(⊂1 2)⎕ F⎕

15+42+28+2+13=100

the last line call the function F that is a sin and cos function depend of input (input ≠2 is sin input =2 is cos). Some test:

      6⍕¨(⊂1 2)⎕ F⎕
⎕:
      3
⎕:
      5
  10.208333 14.541667  
      6⍕¨(⊂1 2)⎕ F⎕
⎕:
      12    
⎕:
      6.54
  0.253986 0.967147  
      6⍕¨(⊂1 2)⎕ F⎕
⎕:
      13
⎕:
      8.555
  0.765431 ¯0.641092 

OT it would be possible to calculate the exact answer using rationals and input rational

     1 10 F 1r4
8264318085745811128158727r33404146443928530321408000

this last number cut, it would be the decimal 0.24740395925452292959

Source Link
Rosario
  • 351
  • 5

APL(NARS), 116 chars

r←a C w;d;v;m;p
r←d←1+(2≠↑a)×w-1⋄m←w×wׯ1⋄p←2⊃a⋄v←0 1-(2=↑a)
→0×⍳0≥p-←1⋄r+←d×←m÷×/v+←2⋄→2

z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z

15+44+28+2+27=116

the last line call the function C that is a sin and cos function depend of input (input ≠2 is sin input =2 is cos)

      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      5 3
 10.208333
 14.541667
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      8.555 13
 0.765431
 ¯0.641092
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      9.26 10
 ¯3.154677
 ¯8.404354
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      6.54 12
 0.253986
 0.967147
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      5 1
 5.000000
 1.000000
      z←⎕⋄6⍕1 z[2]C↑z⋄6⍕2 z[2]C↑z 
⎕:
      20 20
 ¯5364.411846
 ¯10898.499385

OT it would be possible to calculate the exact answer using rationals and input rational

      z←⎕⋄1 z[2]C↑z⋄2 z[2]C↑z 
⎕:
      1r4  10
8264318085745811128158727r33404146443928530321408000 
17051609536099989115458551r17598710837038136237752320