14
\$\begingroup\$

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!

\$\endgroup\$
2
  • 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\$ Jun 5, 2013 at 16:06
  • 2
    \$\begingroup\$ Completely accurate. But what's the fun in that? :p \$\endgroup\$
    – lochok
    Jun 10, 2013 at 2:44

4 Answers 4

9
\$\begingroup\$

GolfScript, 30 characters

.-1%]$1=3>7/);{{1&}%2base}%""+

Input is provided on STDIN. Example:

> 1011000001100001010000111001
ABC

> 1001110000101000011000001101
ABC
\$\endgroup\$
1
\$\begingroup\$

J - 35 bytes

_7(a.{~#.)\_4}.3}.|.^:([:-.2{])"."0

Explanation coming later :).

\$\endgroup\$
1
  • 6
    \$\begingroup\$ How much later? ;-) \$\endgroup\$
    – Tim
    Jun 10, 2016 at 1:25
0
\$\begingroup\$

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.

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

AWK, 116 bytes

/101$/{r=1}{L=split($0,a,"")
n=r?L-2:3
N=r?-1:1
while(d<L-7){c=0
for(k=0;k<7;k++){c*=2;c+=a[n+=N];d++}printf"%c",c}}

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.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ @tailsparkrabbitear Suggest golfs in comments, don't edit them in \$\endgroup\$ Mar 18, 2021 at 17:07
  • 1
    \$\begingroup\$ @chartz Hi. I'm sorry at that time when I didn't have a privilege to add a comment yet. I wanted to suggest length(). \$\endgroup\$
    – user100411
    Mar 19, 2021 at 4:03
  • \$\begingroup\$ While you are correct that there is a length() function, that would not provide the array 'a' \$\endgroup\$ Mar 24, 2021 at 12:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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