NeedlemanWunsch without mutable state