|Welcome to the Monastery|
Code Shortening (golf) [RESOLVED]by Young Monk (Novice)
|on Oct 18, 2010 at 18:41 UTC||Need Help??|
Young Monk has asked for the
wisdom of the Perl Monks concerning the following question:
Hi all. I was trying a question in SPOJ. Let me explain the question first. The input will be a single line containing capital and small letters. Lets assume the following:
A is an opcode. The operands of A are b,c and d. Similarly, E is an opcode and its operands are f. The opcodes must be moved to the closest upper index that is a multiple of 4.
So, AbcD must be Abc-D, where '-' means a blank (output is 1).
Similarly, ABC must be A---B---C, so the output is 6.
Similarly, AbcdeF must be Abcde---F, so the output is 3.
The task is, to find the minimum number of '-'s that are needed to be inserted to align the Opcodes accordingly.
Here is my solution to this task:
It is 42 chars long and its the second shortest. The first shortest is 39 chars long. Can u pls try to make it shorter?
Edit2: Corrected a small typo. (thanks to Ken)