Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add me: Factor #2

Open
shnarazk opened this issue Dec 12, 2023 · 0 comments
Open

Add me: Factor #2

shnarazk opened this issue Dec 12, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@shnarazk
Copy link
Owner

shnarazk commented Dec 12, 2023

  • 2024-02-09
    golfed
USING: kernel math ;
IN: leibniz

: lpi ( num-of-pairs: integer -- pi )
  0.0 0 rot
  [ [ 4.0 * [ 3.0 + ] [ 1.0 + ] bi * 2.0 swap / + ] keep 1 + ] times
  drop 4 *
;
  • 2023-12-12
USING: kernel math ;
IN: Leibniz

: calcpi ( -- pi index )
    0.0 0
    [
        dup [ 4.0 * [ 3.0 + ] [ 1.0 + ] bi * 2.0 swap / + ] dip
      1 +
     dup 100000000 <
    ] loop
    [ 4 * ] dip
    ! drop
    ;

100M pairs => 0.137 sec. on 2.3GHz dual core Core i5 😲

@shnarazk shnarazk self-assigned this Dec 12, 2023
@shnarazk shnarazk added the enhancement New feature or request label Dec 12, 2023
@shnarazk shnarazk changed the title Add me Add me: Factor Feb 8, 2024
@shnarazk shnarazk reopened this Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant