Five programming problems every Software Engineer should be able to solve in less than 1 hour

Geoff Canyon gcanyon at gmail.com
Sat May 9 19:59:58 EDT 2015


On Sat, May 9, 2015 at 6:51 PM, Geoff Canyon <gcanyon at gmail.com> wrote:

> function sumPermute S,T
>    repeat
>       put offset(",",line 1 of S) into F
>       put F into fld 1
>       wait 0 ticks
>       if F = 0 then exit repeat
>       put empty into newS
>       repeat with i = 1 to 3
>          put char i of "+- " into C
>          repeat for each line L in S
>             put C into char F of L
>             put L & cr after newS
>          end repeat
>       end repeat
>       put char 1 to -2 of newS into S
>    end repeat
>    repeat for each line L in S
>       replace space with empty in L
>       if value(L) = T then put L & cr after R
>    end repeat
>    return R
> end sumPermute
>

Debug code snuck in. That should be:

function sumPermute S,T
   repeat
      put offset(",",line 1 of S) into F
      if F = 0 then exit repeat
      put empty into newS
      repeat with i = 1 to 3
         put char i of "+- " into C
         repeat for each line L in S
            put C into char F of L
            put L & cr after newS
         end repeat
      end repeat
      put char 1 to -2 of newS into S
   end repeat
   repeat for each line L in S
      replace space with empty in L
      if value(L) = T then put L & cr after R
   end repeat
   return R
end sumPermute



More information about the use-livecode mailing list