Largest difference between adjacent primes/Factor: Difference between revisions

m
fix vestigial code
(add detailed explanation)
 
m (fix vestigial code)
 
(2 intermediate revisions by the same user not shown)
Line 3:
 
lprimes dup cdr lzip [ first2 2dup swap - -rot 3array ] lmap-lazy
[ lastsecond 1e6 < ] lwhile { 0 } [ max ] foldl
 
"Largest difference in adjacent primes under a million: %d between %d and %d.\n" vprintf</lang>
Line 91:
|
|
| <tt>L{ { 1 2 3 } { 2 3 5 } { 2 5 7 } { 4 7 11 } ... }</tt>
|-
| <tt>[ second 1e6 < ] lwhile</tt>
Line 100:
| take the maximum element, using <tt>{ 0 }</tt> as a seed
| <tt>{ 114 492113 492227 }</tt>
|-
| <tt>"Largest difference in adjacent primes under a million: %d between %d and %d.\n" vprintf</tt>
| like printf, but take arguments from a sequence instead of the data stack
|
|}
 
At this point, we simply use <tt>vprintf</tt> to output the answer. <tt>vprintf</tt> is like <tt>printf</tt> except it takes its arguments from a sequence instead of the data stack.
1,808

edits