I'm doing Project Euler problems as a learning platform for Forth. Currently I'm solving Project Euler Problem 8 which involves a 1000-long string, which I entered directly in the source code.
My questions are:
- What options are common for dealing with input?
- If I put the
locals
on the stack, won't that make the loop too full of (otherwise unneeded) stack manipulation words? - Suggestions, criticism, nitpicks are welcome...
: e008-multNdigits ( a n -- p )
1 swap 0 do swap dup i + c@ [char] 0 - rot * loop nip ;
: euler008
0 13 locals| length maxproduct |
s" 731671765313306249192...450"
( a 1000 )
length - 0 do
dup i + length e008-multNdigits
dup maxproduct > if to maxproduct else drop then
loop maxproduct . ;