Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Friday Programming Quiz [modified]

Friday Programming Quiz [modified]

Scheduled Pinned Locked Moved The Lounge
c++csharppythoncomdata-structures
21 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Rama Krishna Vavilala

    Matt Gerrans wrote:

    Isn't this a programming question

    This is a programming quiz. The purpose is to have fun. The problems presented here are too trivial.


    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -Brian Kernighan

    M Offline
    M Offline
    Matt Gerrans
    wrote on last edited by
    #21

    Sorry, I intended that to be a (good natured) parody of the Lounge posting police, but that apparently didn't work very well. :-O I do like the Programming Quiz and encourage you to continue! In fact, I'll provide a Python[^] (as usual) answer:

    def ExecuteActions( actions, onAllActionsComplete ):
    def doActions(actions):
    if actions:
    actions[0]( lambda: doActions(actions[1:]) )
    else:
    onAllActionsComplete()
    doActions(actions)

    (My first answer worked, but was a lot more clunky; this is what occurred to me after pondering it a bit more.) Also, here is the code to test drive it:

    def onAllActionsComplete():
    print 'onAllActionsComplete!'

    actions = []
    for l in 'abc':
    exec( 'def %s(o):\n\tprint "%s!"\n\to()\nactions.append(%s)' % ((l,)*3) )

    ExecuteActions( actions, onAllActionsComplete )

    (This could be made a little more terse by using lambda more, but that wouldn't necessarily be better.) By the way, thanks to IronPython[^], this would be an easy way to do it in .NET.

    Matt Gerrans

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups