More short-circuit updates
parent
c5cc533182
commit
bdd66927fc
|
@ -56,7 +56,7 @@ TUPLE: trace-state old new table i j ;
|
||||||
{
|
{
|
||||||
[ i>> 0 > ] [ j>> 0 > ]
|
[ i>> 0 > ] [ j>> 0 > ]
|
||||||
[ [ old-nth ] [ new-nth ] bi = ]
|
[ [ old-nth ] [ new-nth ] bi = ]
|
||||||
} <-&& ;
|
} 1&& ;
|
||||||
|
|
||||||
: do-retain ( state -- state )
|
: do-retain ( state -- state )
|
||||||
dup old-nth retain boa ,
|
dup old-nth retain boa ,
|
||||||
|
|
|
@ -26,7 +26,7 @@ IN: math.text.english
|
||||||
|
|
||||||
SYMBOL: and-needed?
|
SYMBOL: and-needed?
|
||||||
: set-conjunction ( seq -- )
|
: set-conjunction ( seq -- )
|
||||||
first { [ dup 100 < ] [ dup 0 > ] } && and-needed? set drop ;
|
first { [ dup 100 < ] [ dup 0 > ] } 0&& and-needed? set drop ;
|
||||||
|
|
||||||
: negative-text ( n -- str )
|
: negative-text ( n -- str )
|
||||||
0 < "Negative " "" ? ;
|
0 < "Negative " "" ? ;
|
||||||
|
|
|
@ -59,7 +59,7 @@ PRIVATE>
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: worth-calculating? ( n -- ? )
|
: worth-calculating? ( n -- ? )
|
||||||
{ [ dup 1- 3 mod zero? ] [ dup 1- 3 / even? ] } && nip ;
|
{ [ dup 1- 3 mod zero? ] [ dup 1- 3 / even? ] } 0&& nip ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ IN: project-euler.021
|
||||||
|
|
||||||
: amicable? ( n -- ? )
|
: amicable? ( n -- ? )
|
||||||
dup sum-proper-divisors
|
dup sum-proper-divisors
|
||||||
{ [ 2dup = not ] [ 2dup sum-proper-divisors = ] } && 2nip ;
|
{ [ 2dup = not ] [ 2dup sum-proper-divisors = ] } 0&& 2nip ;
|
||||||
|
|
||||||
: euler021 ( -- answer )
|
: euler021 ( -- answer )
|
||||||
10000 [1,b] [ dup amicable? [ drop 0 ] unless ] sigma ;
|
10000 [1,b] [ dup amicable? [ drop 0 ] unless ] sigma ;
|
||||||
|
|
|
@ -27,7 +27,7 @@ IN: project-euler.036
|
||||||
|
|
||||||
: both-bases? ( n -- ? )
|
: both-bases? ( n -- ? )
|
||||||
{ [ dup palindrome? ]
|
{ [ dup palindrome? ]
|
||||||
[ dup >bin dup reverse = ] } && nip ;
|
[ dup >bin dup reverse = ] } 0&& nip ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ IN: project-euler.043
|
||||||
[ 5 4 pick subseq-divisible? ]
|
[ 5 4 pick subseq-divisible? ]
|
||||||
[ 3 3 pick subseq-divisible? ]
|
[ 3 3 pick subseq-divisible? ]
|
||||||
[ 2 2 pick subseq-divisible? ]
|
[ 2 2 pick subseq-divisible? ]
|
||||||
} && nip ;
|
} 0&& nip ;
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ IN: project-euler.052
|
||||||
[ number>digits natural-sort ] map all-equal? ;
|
[ number>digits natural-sort ] map all-equal? ;
|
||||||
|
|
||||||
: candidate? ( n -- ? )
|
: candidate? ( n -- ? )
|
||||||
{ [ dup odd? ] [ dup 3 mod zero? ] } && nip ;
|
{ [ dup odd? ] [ dup 3 mod zero? ] } 0&& nip ;
|
||||||
|
|
||||||
: next-all-same ( x n -- n )
|
: next-all-same ( x n -- n )
|
||||||
dup candidate? [
|
dup candidate? [
|
||||||
|
|
|
@ -19,7 +19,7 @@ strings regexp splitting parser-combinators ascii unicode.case ;
|
||||||
dup [ dupd matches? ] [ drop f ] if
|
dup [ dupd matches? ] [ drop f ] if
|
||||||
] unless*
|
] unless*
|
||||||
]
|
]
|
||||||
} && nip ;
|
} 0&& nip ;
|
||||||
|
|
||||||
: mark-number ( keyword -- id )
|
: mark-number ( keyword -- id )
|
||||||
keyword-number? DIGIT and ;
|
keyword-number? DIGIT and ;
|
||||||
|
@ -50,7 +50,7 @@ M: rule match-position drop position get ;
|
||||||
[ over matcher-at-line-start? over zero? implies ]
|
[ over matcher-at-line-start? over zero? implies ]
|
||||||
[ over matcher-at-whitespace-end? over whitespace-end get = implies ]
|
[ over matcher-at-whitespace-end? over whitespace-end get = implies ]
|
||||||
[ over matcher-at-word-start? over last-offset get = implies ]
|
[ over matcher-at-word-start? over last-offset get = implies ]
|
||||||
} && 2nip ;
|
} 0&& 2nip ;
|
||||||
|
|
||||||
: rest-of-line ( -- str )
|
: rest-of-line ( -- str )
|
||||||
line get position get tail-slice ;
|
line get position get tail-slice ;
|
||||||
|
@ -273,7 +273,7 @@ M: mark-previous-rule handle-rule-start
|
||||||
[ check-end-delegate ]
|
[ check-end-delegate ]
|
||||||
[ check-every-rule ]
|
[ check-every-rule ]
|
||||||
[ check-word-break ]
|
[ check-word-break ]
|
||||||
} || drop
|
} 0|| drop
|
||||||
|
|
||||||
position inc
|
position inc
|
||||||
mark-token-loop
|
mark-token-loop
|
||||||
|
|
Loading…
Reference in New Issue