Welcome to the piNapple bar, Melbourne. All of the finest code golfers are here, with their laptops, sampling cocktails and programming increasingly badly.

I feel a special need to reemphasise the last point. Increasingly badly. Alcohol can do funny things to programming logic.

So - a few of the Golfers were attempting some nested quines in increasingly exotic languages. Somebody had hit the forth order in INTERCAL. Then the flow of alcohol stopped. He drunkedly, accidentally deleted the barcode reading algorithms from a completely different computer... that wasn't even connected to any network! (Kids - don't INTERCAL. For the sake of you. For the sake of your family.)

Normally, this wouldn't be a big issue. But, some golfer had designed the system years ago, and none of the barcodes were standard. Assuming 1's are lines, and 0's are space, they all start with 101 and finish with 1001. Everything in the middle is 7-bit ASCII encoded.

The barkeep does have a big fancy barcode reader that will return a string of arbitrary length (though less then 300 bits) of 1's and 0's, via STDIN, argument or file depending on your program. And it might come forward, or backwards depending on which way the bottle is being held. Your program must return the string from the middle of the barcode, via STOUT or file.

Unfortunately, he didn't spend as much on his storage, so the program with the shortest source will be chosen, and win free drinks and drunken programming tutorials from the other golfers.

Good luck!

  • 7
    \$\begingroup\$ In other words, determine if the input is 101...1001 or 1001...101 and reverse in the latter case, then pack the center into bytes. \$\endgroup\$ – John Dvorak Jun 5 '13 at 16:06
  • 1
    \$\begingroup\$ Completely accurate. But what's the fun in that? :p \$\endgroup\$ – lochok Jun 10 '13 at 2:44

GolfScript, 30 characters


Input is provided on STDIN. Example:

> 1011000001100001010000111001

> 1001110000101000011000001101
| improve this answer | |

J - 35 bytes


Explanation coming later :).

| improve this answer | |
  • 4
    \$\begingroup\$ How much later? ;-) \$\endgroup\$ – Tim Jun 10 '16 at 1:25

Pyth, 21

smCid2c:?zv@z2_z3_4 7


        ?zv@z2_z           Input if 3rd character of input is 1, else reversed input.
       :        3_4        Slice out the middle portion, ASCII of the above string.
      c             7      Chop into 7 character chunks.
 mCid2                     Convert each chunk from binary to integer, then to a character.
s                          Sum up the characters into a string and print.

Note that while the question is older than the language, the existence of the question did not influence the design of the language in any way, because I haven't seen the question before today.

Still rules are rules, so I'm making it CW.

  • \$\begingroup\$ OK, I'll make it CW then. \$\endgroup\$ – isaacg Nov 4 '14 at 9:54

AWK, 116 bytes


I know this question hasn't seen a lot of love, but I was curious about seeing and AWK solution. This isn't all that clever, but it seems to work and I don't see any obvious areas to golf. I originally reversed the string when needed, but that added more bytes than just tweaking the increment logic to move backwards.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.