Hi,

I think this should be something like this (below). Mind line wraps, especially in the solution for problem 5.

My solution for problem 5 is much easier but also less elegant than the Java solution on the website. If anyone has better (faster or easier) solutions, especially for problem 5, I'd like to see them.


Solutions:

// sorry, but I really can't care about the 3 different methods.
// They're silly.
function problem1
     put sum(myGivenList)
end problem1

// piece of cake for LC but in PHP and C++ also not that difficult
on problem2
     repeat with x = 1 to number of items of myList1
          put item x of myList1,item x of myList2 & comma after myNewList
     end repeat
     delete last char of myNewList
end problem2

// doh
function problem3
     put "0,1" into myList
     repeat 98
          put comma & item -2 of myList + item -1 of myList after myList
     end repeat
     return myList
end problem3

// easy
function problem4
     put "50,2,1,9" into myList
     sort items of myList numeric descending by char 1 of each
     replace comma with empty in myList
     return myList
end problem4

/* I would rather do this as a recursive function, avoiding the
multiple repeat loops and allowing for an arbitrary number of digits
(e.g. 123 or 1234 or 1468 etc) but that seems to take too much time */
function problem5
     put "+-o" into signs
     repeat with x1 = 1 to 3
          repeat with x2 = 1 to 3
               repeat with x3 = 1 to 3
                    repeat with x4 = 1 to 3
                         repeat with x5 = 1 to 3
                              repeat with x6 = 1 to 3
                                   repeat with x7 = 1 to 3
                                        repeat with x8 = 1 to 3
                                             put 1 into myLine
                                             repeat with c = 2 to 9
put char value("x"&c-1) of signs & c after myLine
                                             end repeat
replace "o" with empty in myLine do "put" && myLine && "into mySum" if mySum is 100 then put myLine && mySum & cr after myList
                                        end repeat
                                   end repeat
                              end repeat
                         end repeat
                    end repeat
               end repeat
          end repeat
     end repeat
     return myList
end problem5



--
Best regards,

Mark Schonewille

Economy-x-Talk Consulting and Software Engineering
Homepage: http://economy-x-talk.com
Twitter: http://twitter.com/xtalkprogrammer
KvK: 50277553

Installer Maker for LiveCode:
http://qery.us/468

Buy my new book "Programming LiveCode for the Real Beginner" http://qery.us/3fi

LiveCode on Facebook:
https://www.facebook.com/groups/runrev/

On 5/9/2015 23:49, Geoff Canyon wrote:
https://blog.svpino.com/2015/05/07/five-programming-problems-every-software-engineer-should-be-able-to-solve-in-less-than-1-hour

Interesting blog post, made doubly interesting because when the author
posted his solutions to problems 4 and 5, one of his solutions was
incorrect. So I guess he won't be hiring himself...

In any case, I thought they were interesting so I gave it a shot. I
finished in something like 40 minutes, but I think some of my solutions are
more expedient than I would like.

I'll post the code in replies, so don't read those if you want to try
yourself.


_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to