Skip to content

Instantly share code, notes, and snippets.

@mattboehm
Created December 5, 2017 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattboehm/357a8c6cb9ae01c4bc7c4c3750564322 to your computer and use it in GitHub Desktop.
Save mattboehm/357a8c6cb9ae01c4bc7c4c3750564322 to your computer and use it in GitHub Desktop.
must be run on cell size of 16 bits or more with wrapping on inc and dec operations
>>>>>>
,[------------------------------------------------>>,] read input and convert ascii digits to data
data is loaded into an array with empty slots in between the data cells
get len
<<[while still on a number
>[-<<+>>]<<+< move len counter to the left and inc
]
go to len counter and copy to some new cells
>[-<<+<<+>>>>]
<<[--<+>] put half len into cells
<<[-<+>]
<[->+<]
>
[-->>>>+>>+<<<<<<]
>>>>
>[>>]+[<<]> add a marker to the end of the array (needed for some of the navigation below)
go halfway through the loop finding matches and adding to a sum stored at the end
hlen _sb2_ _nb1_ (counter=hlen) num counter2=hlen n2 _s1_ n3 _s2_
[
>num [-<<+>>] move to prev num slot
>c2
[
[->>+<<]>>-
]move counter2 over and dec til 0 to find num2 halfway away
<num2
[->+>>+<<<] move num2 to next 2 slots
>
[-<<<[<<]>+>[>>]>] move num2_s1 to num1_s1
>>[-<<<+>>>] move num2_s2 to num2
<[<<]
<<[-<+>>>+<<] move num to its original place and the second slot before
>>[-<<+>>]move orig back to prev num slot
>[-<<<<->>>>] sub h from the num in sb2
<+
<<<[if sub is nonzero remove num mark
[-]>>>-<<<
]
>>>
[if num is marked sub was 0 and numbers are same
- remove mark
<<[->>>>[>>]>>+<<<<[<<]<<] result stored past the end of the array
>>
]
<<[-] clear out pnum
>[->>+<<]>>- move counter over and dec
move half counter into place
<<<<<[->>+>>>>>+<<<<<<<]
>>>>>
]
>[>>]>>sum
[-<++>]< double the sum
print to ascii
[>>+>+<<<-]>>>[<<<+>>>-]<<+>[<->[>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]
++++++++[<++++++>-]>[<<+>>-]>[<<+>>-]<<]>]<[->>++++++++[<++++++>-]]<[.[-]<]<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment