YAPC::EU 2018 Glasgow Update!
This commit is contained in:
parent
22f33d4004
commit
4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions
|
|
@ -0,0 +1,31 @@
|
|||
USING: formatting io kernel lists lists.lazy locals math
|
||||
math.ranges prettyprint sequences ;
|
||||
IN: rosetta-code.stern-brocot
|
||||
|
||||
: fn ( n -- m )
|
||||
[ 1 0 ] dip
|
||||
[ dup zero? ] [
|
||||
dup 1 bitand zero?
|
||||
[ dupd [ + ] 2dip ]
|
||||
[ [ dup ] [ + ] [ ] tri* ] if
|
||||
-1 shift
|
||||
] until drop nip ;
|
||||
|
||||
:: search ( n -- m )
|
||||
1 0 lfrom [ fn n = ] lfilter ltake list>array first ;
|
||||
|
||||
: first15 ( -- )
|
||||
15 [1,b] [ fn pprint bl ] each
|
||||
"are the first fifteen." print ;
|
||||
|
||||
: first-appearances ( -- )
|
||||
10 [1,b] 100 suffix
|
||||
[ dup search "First %3u at Stern #%u.\n" printf ] each ;
|
||||
|
||||
: gcd-test ( -- )
|
||||
1,000 [1,b] [ dup 1 + [ fn ] bi@ gcd nip 1 = not ] filter
|
||||
empty? "" " not" ? "All GCDs are%s 1.\n" printf ;
|
||||
|
||||
: main ( -- ) first15 first-appearances gcd-test ;
|
||||
|
||||
MAIN: main
|
||||
|
|
@ -1,7 +1,4 @@
|
|||
# Project : Stern-Brocot sequence
|
||||
# Date : 2018/02/01
|
||||
# Author : Gal Zsolt [~ CalmoSoft ~]
|
||||
# Email : <calmosoft@gmail.com>
|
||||
|
||||
limit = 1200
|
||||
item = list(limit+1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue