Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0k
- z sn # n = input size
- 25 sm # m = window size
- [ LRx q ] sX # Return macro, call cleanup and quit
- [ q ] sQ # Exit loop without cleanup
- # Loop: Read in input file
- [ Lis. LLs. ] SR # cleanup for loop
- [
- z 0 =X # process stack
- li 1- d si :a # pop into a @ --i
- lLx
- ] SL
- ln Si lLx
- # Loop: Initialize window
- [ LLs. s. ] SR # cleanup for loop
- [
- dd ;a r :w # w @ index = a @ index, index on top
- 1- d _1 =X # index--, break if -1
- lLx
- ] SL
- lm 1- lLx
- # Part 1
- [
- # Locals:
- [
- LCs. LSs. LLs. LAs.
- Lps. Lqs.
- ] SR
- 0 Sp # ptr for Shift window
- lm Sq # next_ptr for Shift window
- # Shift window
- [
- lq ;a lp :w # w @ ptr = a @ next_ptr
- lp 1+ lm% sp # ptr++ mod window size
- lq 1+ sq # next_ptr++
- ] SS
- # Check window
- [
- # Locals:
- [
- LTs. LIs. LJs.
- Lis. Ljs.
- ] SR
- [ 1 LRx 4Q ] ST
- 0 Si 1 Sj
- # inner loop
- [
- li;w lj;w + lq;a =T # found sum, return True
- lj 1+ sj lj lm =Q # j++, break if j == window size
- lJx
- ] SJ
- # outer loop
- [
- li 1+ sj # j = i + 1
- lJx # call inner j loop
- li 1+ si li lm 1- =Q # i++, break if i == window size - 1
- lIx
- ] SI
- lIx
- 0 LRx # return False
- ] SC
- # Print Answer
- [
- [Part 1: ]n lq;a ps. # Print answer
- LRx q
- ] SA
- # Foreach Window
- [
- lCx 0 =A # Print and exit when check fails
- lSx lq ln 1+ =X # shift window, break at end
- lLx # loop
- ] SL
- lLx
- ] S1
- l1x
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement