# Can you barcode code in a bar?

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!

• 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. – John Dvorak Jun 5 '13 at 16:06
• Completely accurate. But what's the fun in that? :p – lochok Jun 10 '13 at 2:44

.-1%]$1=3>7/);{{1&}%2base}%""+  Input is provided on STDIN. Example: > 1011000001100001010000111001 ABC > 1001110000101000011000001101 ABC  ## J - 35 bytes _7(a.{~#.)\_4}.3}.|.^:([:-.2{])"."0  Explanation coming later :). • How much later? ;-) – Tim Jun 10 '16 at 1:25 # Pyth, 21 smCid2c:?zv@z2_z3_4 7  Explanation:  ?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. • OK, I'll make it CW then. – isaacg Nov 4 '14 at 9:54 ## AWK, 116 bytes /101$/{r=1}{L=split(\$0,a,"")

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.