From: Ruby Quiz Date: 2007-02-02T22:07:56+09:00 Subject: [QUIZ] String Equations (#112) 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. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= This quiz was adapted from an ACM programming challenge at the suggestion of Gavin Kistner. Let's define two operators for a simple set of string equations. First, we will use the plus (+) operator and keep Ruby's meaning of concatenation for it. Therefore, "james" + "gray" is "jamesgray". The other operator we will support is equality (==). Two strings will be considered equal if they are anagrams (they contain the same letters in a possibly different ordering). In other words, "cinema" == "iceman". Using these two operators we can build equations: "i" + "am" + "lord" + "voldemort" == "tom" + "marvolo" + "riddle" This week's quiz is to write a program that accepts a list of words on STDIN and outputs any one string equation using those words, assuming there is one. Each word in the list may be used zero or more times, but only on one side of the equation. The program should exit(0) on success and exit(1), without printing any output, if a solution cannot be found. Let's sidestep case sensitivity issues by lower casing all incoming words. You can also remove all non-alphanumeric characters. Posting word lists and/or equations is not spoiler material.