From: Ruby Quiz Date: 2007-08-17T22:15:37+09:00 Subject: [QUIZ] Process Rings (#135) The three rules of Ruby Quiz: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have passed from the time on this message. 2. Support Ruby Quiz by submitting ideas as often as you can: http://www.rubyquiz.com/ 3. Enjoy! Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone on Ruby Talk follow the discussion. Please reply to the original quiz message, if you can. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= I recently wrote about a challenge in the Programming Erlang book on my blog: http://blog.grayproductions.net/articles/2007/08/13/erlang-message-passing Language comparison issues aside, just figuring out how to build a ring of "processes" was quite the brain bender for me. That always makes for good Ruby Quiz material, in my opinion. The task is straight forward: 1. Your program should take two command-line arguments: a number of processes and a number of cycles. 2. Begin by creating the requested number of processes, in a ring. For example, when three processes are requested, process one creates and sends messages to process two, which creates and sends messages to process three. The third process then sends its messages back to process one. 3. Pass a message around your ring of processes a number of times equal to the requested cycles. Print timing results for how long this takes. The message you pass doesn't much matter. A simple String is fine. You may also wish to pass a counter with it, to verify the correct number of sends. I'll leave the definition of "processes" intentionally vague. Ruby doesn't have an equivalent to Erlang processes so we will just say that each process should represent a node where we could run some instructions concurrently. Be creative.