Binary Shuffle ------ ------- You've been hired by `Giants Gaming Emporium' to help shuffle card decks, but, understand, `Giant's' is a virtual gaming emporium. So its all in a computer. The process is simple: you have a (virtual) card deck and you go to a (virtual) black box and press a (virtual) button and out pops a binary number, which instructs you on how to shuffle the deck. Specifically, you read the bits from left to right, and if a bit is 0 you take the next card from the BACK of the deck, but if it is 1 you take the next card from the FRONT of the deck. So you can read the binary number `1001100' as front back back front front back back and applied to the deck of 7 Tarot cards: 21 - World 20 - Angle 19 - Sun 18 - Moon 17 - Star 16 - Tower 15 - Devil gives the shuffled deck: 21 - World 15 - Devil 16 - Tower 20 - Angle 19 - Sun 17 - Star 18 - Moon Special Rules ------- ----- When you run out of cards, stop, even if there are more binary digits. If you run out of binary digits, go back to the BEGIN- NING of the binary number. Its as if you used an unbounded number of copies of the binary number concate- nated to each other. E.g., `101' is equivalent to `101101101...'. Input ----- For each of several test cases, a line containing just a test case name, followed by a line containing the binary number, followed by up to 100 lines each containing the name of one card, followed by a line containing just `.' Input ends with an end of file. No line is longer than 80 characters. Output ------ For each test case, a copy of the input except that the order of the cards is their order AFTER the deck has been shuffled. Sample Input ------ ----- -- SAMPLE 1 -- 1001100 21 - World 20 - Angle 19 - Sun 18 - Moon 17 - Star 16 - Tower 15 - Devil . [IMPORTANTLY there are more samples in sample.in] [BE SURE your program does ALL the samples correctly before you submit.] Sample Output ------ ------ -- SAMPLE 1 -- 1001100 21 - World 15 - Devil 16 - Tower 20 - Angle 19 - Sun 17 - Star 18 - Moon . [The output for sample.in is in sample.test] File: binshuffle.txt Author: Bob Walton Date: Wed Oct 15 07:23:59 EDT 2014 The authors have placed this file in the public domain; they make no warranty and accept no liability for this file. RCS Info (may not be true date or author): $Author: walton $ $Date: 2014/10/15 11:25:07 $ $RCSfile: binshuffle.txt,v $ $Revision: 1.6 $