I did the first problem pretty quickly after learning how to duplicate the top element of the stack (it took me way too long to figure out what "dup" meant).
And then I spent 30 minutes trying to figure out how you do loops only to realize that of course there aren't any loops, 'cause it's a functional language XD
(As kilotaras has pointed out, there are indeed general loops in Factor. There's even a keyword called "loop" :P)
Besides problem A, most of my code follows the same paradigm: a recursive function that keeps track of the input we haven't used, and the answer we've calculated on the input we have used.
After a couple problems I learned about "::" for binding function parameters to local variables. Boy, does that save time.
And now that the contest is over I see that there's a "prime" function. That would surely speed up my Problem I enough because right now it's just horrendously naive trial division.
A quick mini-editorial of how your recursive state might look for each problem:
- A: No recursion necessary!
- B: (output string, left-most portion of number)
- C: (output string, current divisor, unfactored portion of number)
- D: (processed portion of string, unprocessed portion)
- E: (boolean flag that keeps track of if you've seen "H", "Q", or "9", unprocessed portion of string)
- F: (number of zeros so far, left-most 10 or so non-zero digits, factorial remaining to multiply by)
- G: I haven't done this, but it's a more complicated version of B. I think it's easily the hardest problem.
- H: (processed portion of string, unprocessed portion)
- I: (boolean flag that keeps track of if all suffixes have been prime so far, left-most unprocessed digits) I also reuse my function from C to factor each number
- J: (A stack representing unmatched open parentheses, unprocessed portion of string)
- Problem A: http://pastebin.com/W9UsyLpd
- Problem B: http://pastebin.com/6cQZtTFd
- Problem C: http://pastebin.com/vt9ApsdX
- Problem D: http://pastebin.com/MW3AmXSk
- Problem E: http://pastebin.com/MAhMn80E
- Problem F: http://pastebin.com/f1XrhGCK
- Problem G: (Not solved)
- Problem H: http://pastebin.com/Ttc2xTtm
- Problem I: http://pastebin.com/xW7xwieQ (TLE)
- Problem J: http://pastebin.com/m4AdKcSc