text:
Obfuscating text by cycling ternary digits
The goal of this challenge is the write the shortest function/program to take input text, encrypt it using the method below, and return the result.
As an example, I will use the string hello world.
First, get the input text.
hello world

Second, convert the string into ternary (base 3). Use this key:
a = 000
b = 001
c = 002
d = 010
e = 011
f = 012
g = 020

...

w = 211
x = 212
y = 220
z = 221
[space] = 222

With this key, hello world becomes 021011102102112222211112122102010, as seen below.
 h   e   l   l   o       w   o   r   l   d
021 011 102 102 112 222 211 112 122 102 010

Third, move the first digit to the end.
021011102102112222211112122102010
becomes
210111021021122222111121221020100

Fourth, convert the number back into a string using the same key.
210 111 021 021 122 222 111 121 221 020 100
 v   n   h   h   r       n   q   z   g   j

Lastly, return the encrypted text.
vnhhr nqzgj

Here are some sample text and their output:
the turtle ==> dvo fh ego
python ==> uudwqn
code golf ==> hpjoytqgp
As this is code golf, the shortest entry in bytes wins.
Errors are allowed if some of the characters are not lowercase letters or space.
This is my first challenge, so any suggestions would be more than helpful.
Good luck!
Leaderboard:

var QUESTION_ID=54643;function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),e.has_more?getAnswers():process()}})}function shouldHaveHeading(e){var a=!1,r=e.body_markdown.split("\n");try{a|=/^#/.test(e.body_markdown),a|=["-","="].indexOf(r[1][0])>-1,a&=LANGUAGE_REG.test(e.body_markdown)}catch(n){}return a}function shouldHaveScore(e){var a=!1;try{a|=SIZE_REG.test(e.body_markdown.split("\n")[0])}catch(r){}return a}function getAuthorName(e){return e.owner.display_name}function process(){answers=answers.filter(shouldHaveScore).filter(shouldHaveHeading),answers.sort(function(e,a){var r=+(e.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0],n=+(a.body_markdown.split("\n")[0].match(SIZE_REG)||[1/0])[0];return r-n});var e={},a=1,r=null,n=1;answers.forEach(function(s){var t=s.body_markdown.split("\n")[0],o=jQuery("#answer-template").html(),l=(t.match(NUMBER_REG)[0],(t.match(SIZE_REG)||[0])[0]),c=t.match(LANGUAGE_REG)[1],i=getAuthorName(s);l!=r&&(n=a),r=l,++a,o=o.replace("{{PLACE}}",n+".").replace("{{NAME}}",i).replace("{{LANGUAGE}}",c).replace("{{SIZE}}",l).replace("{{LINK}}",s.share_link),o=jQuery(o),jQuery("#answers").append(o),e[c]=e[c]||{lang:c,user:i,size:l,link:s.share_link}});var s=[];for(var t in e)e.hasOwnProperty(t)&&s.push(e[t]);s.sort(function(e,a){return e.lang>a.lang?1:e.lang<a.lang?-1:0});for(var o=0;o<s.length;++o){var l=jQuery("#language-template").html(),t=s[o];l=l.replace("{{LANGUAGE}}",t.lang).replace("{{NAME}}",t.user).replace("{{SIZE}}",t.size).replace("{{LINK}}",t.link),l=jQuery(l),jQuery("#languages").append(l)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",answers=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:<(?:s>[^&]*<\/s>|[^&]+>)[^\d&]*)*$)/,NUMBER_REG=/\d+/,LANGUAGE_REG=/^#*\s*([^,]+)/;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

Note that this technically is obfuscation, not encryption. There is no encryption key here.

@JanDvorak Will "cipher" work?

To build on @JanDvorak's comment, I would describe this as an "encoding," which is a standard way of expressing data in a different format (e.g., you can express a bit string with hexadecimal encoding, or base64 encoding).

@apsillers Except now you're re-encoding into the same alphabet as the source. For no reason other than obfuscation^K code golf challenge :-D

@JanDvorak Agreed -- I'd be more likely to call ROT13 "obfuscation" rather than "encoding" (even though it satisfies both definitions). Probably the most precise title would be "Obfuscate text by..."

@apsillers Okay, thanks! Changed.

Can we assume some limit as to the string length? Or perhaps you cauld define some penalty (add some number to the byte count) for code that only works for short strings. I have a method in mind for strings up to 10 or 11 characters; maybe others can come up with efficient approaches for short strings too

@LuisMendo I guess the limit is about how much the programming language can handle. (I know that is kind of vague, but I don't think a programming language would have a 11-character limit) I would like to see the program though! (maybe here on the comments?)

@TheTurtle The idea was to pack the characters into a large integer (uint64) using increasing powers of 27. The displacement by one digit would then be equivalent to multiplying this large integer by 3, and the introduction of the first digit on the other end would simply be an addition. But there are complications, such as discarding the last "carry" (perhaps via a mod operation), and I couldn't get it to work with few bytes

Pyth, 23 22 bytes
sXc.<sXz=+GdJ^UK3K1KJG

Try it online: Regular Input / Test Suite
Thanks to @isaacg for one byte.
Explanation:
sXc.<sXz=+GdJ^UK3K1KJG
        =+Gd             append a space the G (preinitialized with the alphabet)
               K3        assign 3 to K
            J^UK K       assign all 3-digit ternary numbers
                         [[0,0,0], [0,0,1],...,[2,2,2]] to J
      Xz  G J            translate input from G to J
     s                   sum (join all ternary numbers to one big list)
   .<             1      rotate by 1
  c                K     split into lists of size 3
 X                  JG   translate from J to G
s                        join chars to string and print

We had the same idea. I wrote a Pyth port of my CJam, then scrolled down and saw your answer :/

You can save a byte by doing an augmented assignment to G instead of using N, e.g. =+Gd.

Pyth, 26 bytes
J+Gds@LJiR3c.<s.DR9xLJz1 2

Try it online in the Pyth Compiler/Executor: demo | test cases
Idea
Assume all input characters have already been mapped to the integers that step 2 specifies.
For every 3-digit ternary number, we have that xyz3 = 9x + 3y + z, so modular division by 9 yields quotient x and residue 3y + z.
If the input is abc3 def3 ghi3, applying modular division to each yields a, 3b + c, d, 3e + f, g, 3h + i.
After rotating the list from above one unit to the left, we can group the integers into pairs. This yields the list (3b + c, d), (3e + f, g), (3h + i, a).
Now, if we convert (3y + z, w) from base 3 to integer, we obtain 3(3y + z) + w = 9y + 3z + w = zyw3.
Thus, applying base conversion to the list of pairs gives us bcd3 efg3 hia3, which is precisely the result of rotating the concatenated ternary digits one unit to the left.
All that's left to do is mapping the resulting integers back to characters.
Code
J+Gd                        Concatenate "a...z" (G) with " " (d) and save in J.
                    L z     For each character in the input(z):
                   x J        Compute its index in J.
                 R          For each index I:
               .D 9           Compute (I / 9, I % 9).
              s             Concatenate the resulting pairs.
            .<         1    Rotate the resulting list one unit to the left.
           c             2  Split it back into pairs.
         R                  For each pair:
        i 3                   Perform conversion from base 3 to integer.
      L                     For each resulting integer:
     @ J                      Select the element of J at that index.
    s                       Concatenate the resulting characters.

Yeesh, in a few hours I got beaten by CJam and Pyth. :/

Wow! Can you write an explanation of how it works? I'm curious. :)

@TheTurtle I've edited my answer.

Python 2, 96
s=input()
r=y=''
for c in s+s[0]:x=(ord(c)-97)%91;r+=y and chr((y%9*3+x/9-26)%91+32);y=x
print r

Converts a character c to a value x as x=(ord(c)-97)%91, with the modulo affecting only space to convert it to 26. The reverse conversion is i to chr((i-26)%91+32), with the modulo only affecting i=26 to make it become spaces.
We loop through the characters, noting the current value x and the previous value y. We use the last two ternary digits of y, found as y%9, and the first ternary digit of x, found as x/9. The value of the concatenation is y%9*3+x/9. There's probably some optimizations combining this arithmetic with the shifting by 97 and fixing of space.
We make this loop around, we return to the first character of the string at the end. We also do one preparation loop to write in a previous value y, suppressing the character for the first loop when y has not yet been initialized.

CJam, 39 29 bytes
The cool thing about this one is that it doesn't even use base conversion.
q'{,97>S+:XZZm*:Yere_(+3/YXer

Try it online.
I just realized I had exactly the same idea as Jakube's Pyth answer. I actually ported this CJam code to Pyth before seeing his post, ending up with 25 bytes. Given it was my first Pyth golf I guess it's not too bad.
Explanation
                              e# Z = 3
q                             e# Push input string
 '{,                          e# Push ['\0' ... 'z']
    97>                       e# Keep ['a' ... 'z']
       S+                     e# Append space
         :X                   e# Assign "a...z " to X
           ZZm*               e# Push 3rd cartesian power of [0 1 2]
                              e# i.e. all 3-digit permutations of 0, 1, 2
                              e# (in lexicographical order)
               :Y             e# Assign those permutations to Y
                 er           e# Translate input from X to Y
                   e_         e# Flatten resulting 2D array
                     (+       e# Rotate first element to the end
                       3/     e# Split back into 3-digit elements
                         YXer e# Translate from Y to X

CJam, 30 29 27 bytes
q'{,97>S+:Af#9fmd(+2/3fbAf=

Try it online in the CJam interpreter.
The approach is the same as in my other answer, which is a port of this code to Pyth.
How it works
q                           e# Read from STDIN.
 '{,                        e# Push ['\0' ... 'z'].
    97>                     e# Remove the first 97 elements (['\0' - '`']).
       S+:A                 e# Append a space and save in A.
           f#               e# Find the index of each input character in A.
             9fmd           e# Apply modular division by 9 to each index.
                 (+         e# Shift out the first quotient and append it.
                   2/       e# Split into pairs.
                     3fb    e# Convert each pair from base 3 to integer.
                        Af= e# Select the corresponding elements from A.

Javascript (ES6), 175 bytes
A one-liner!
"Overuse of variable v award, anyone?"
update: Now only uses variables called v, for total confusion!
Thanks @vihan for saving 6 bytes!
Thanks @Neil for saving 27 bytes!!

v=>(([...v].map(v=>(v<"V"?53:v.charCodeAt()-70).toString(3).slice(1)).join``)+v[0]).slice(1).match(/..?.?/g).map(v=>(v=String.fromCharCode(parseInt(v,3)+97))>"z"?" ":v).join``

Defines an anonymous function.
To use, add v= before the code to give the function a name, and call it like alert(v("hello world"))

You can use .slice(-3) to save 6 bytes, at which point you can use "00"+v to save another byte. (You could concatenate with a template but the resulting length is the same.)

Actually, you can save a whole bunch of bytes by adding 27 to your values before converting them to base three, as that guarantees enough digits. .map(v=>(v<"V"?26:v.charCodeAt()-97).toString(3)).map(v=>("000"+v).slice(v.length)) then becomes .map(v=>(v<"V"?53:v.charCodeAt()-70).toString(3).slice(1)).

@Neil Wow, that really shortened the code! It also made it a true 'one-liner', by removing the only intermediate variable. Thanks!

Pyth, 30 29 bytes
K+Gdsm@Kid3c.<sm.[Z3jxKd3z1 3

Saved 1 byte thanks to @Jakube.
Live demo and test cases.

Julia, 149 137 bytes
My first golf!
s->(j=join;b=j([base(3,i==' '?26:i-'a',3)for i=s]);r=b[2:end]*b[1:1];j([i==26?" ":i+'a'for i=[parseint(r[i:i+2],3)for i=1:3:length(r)]]))

(partially) ungolfed:
f = s -> (
    # join the ternary represenations:
    b = join([base(3, i == ' ' ? 26 : i - 'a',3) for i = s]);
    # rotate:
    r = b[2:end] * b[1:1];
    # calculate the new numbers:
    n = [parseint(r[i:i+2],3) for i = 1:3:length(r)];
    # convert back to characters:
    join([i == 26 ? " " : 'a' + i for i = n])
)
assert(f("hello world") == "vnhhr nqzgj")
assert(f("the turtle")  == "dvo fh ego")
assert(f("python")      == "uudwqn")
assert(f("code golf")   == "hpjoytqgp")

You can use = rather than in for loops and you can use b[1] in place of b[1:1]. You also don't need a space between closing parens and for.

@AlexA. Cheers for =, but b[1] returns a character, which can't be appended to a string with *.

Oh right, forgot about that.

@AlexA. The for trick is nifty.  You can also have it directly after a close quote.  I didn't realize the parser was that flexible.

It can also directly follow a numeric literal, as can end.

You can compare characters to their integer equivalents, and you know the character with the lowest value will be ' ', so rather than ==' ', use <33 to save two characters. You can drop the asterisk between b[2:end] and b[1:1]. 26 is the largest value for i in the final operation, so use i>25 rather than i==26.

@GlenO The <33 trick I saw in another answer, but didn't want to cheat and use it here.   Thank you for the tips!

It's not cheating to learn methods of golfing from other answers, as long as it's regular golfing. My only rule with it is that I won't steal someone else's approach. Hence why I gave you some tips based on what improvements I could see quickly on yours, and then thought up my own approach to contribute.

Oh, also, here's a nice way to improve on b[2:end]b[1:1] - it turns out you can do this: b[[2:end,1]], to save two more bytes.

@GlenO Interesting!  How did you find that syntax?  My google-fu isn't working with "double square brace julia" variations.

It's not "double square brace". The outer square brace is the array referencing, the inner square brace is an actual array. [2:end,1] produces the array A=[2,3,4,5,...end-1,end,1], then b[A] is getting the letters at those indices. The end is automatically converted into length(b), as far as I can tell.

Javascript (ES6), 178, 172, 170
p=>{p=p.replace(' ','{');c="";l=p.length;for(i=0;i<l;){c+=String.fromCharCode(((p.charCodeAt(i)-97)%9)*3+(((p.charCodeAt((++i)%l)-97)/9)|0)+97)}return c.replace('{',' ')}

Replaced Math.floor with a bitwise or. Created an anonymous function. If I'm understanding correctly, this should fix my noobishness somewhat (thanks Dennis!) and get me another 2 bytes down.

Julia, 169 166 bytes
s->(J=join;t=J(circshift(split(J([lpad(i<'a'?"222":base(3,int(i)-97),3,0)for i=s]),""),-1));J([c[j:j+2]=="222"?' ':char(parseint(c[j:j+2],3)+97)for j=1:3:length(t)]))

Ungolfed + explanation:
function f(s::String)
    # Convert the input into a string in base 3, with space mapping to 222
    b = join([lpad(i < 'a' ? "222" : base(3, int(i) - 97), 3, 0) for i = s])

    # Split that into a vector of single digits and shift once
    p = circshift(split(b, ""), -1)

    # Join the shifted array back into a string
    t = join(p)

    # Convert groups of 3 back into characters
    c = [t[j:j+2] == "222" ? ' ' : char(parseint(t[j:j+2], 3) + 97) for j = 1:3:length(t)]

    # Return the joined string
    join(c)
end

Haskell, 160 bytes
a!k|Just v<-lookup k a=v
x=['a'..'z']++" "
y="012";z=mapM id[y,y,y]
m(a:u:r:i:s)=[u,r,i]:m(a:s)
m[e,a,t]=[[a,t,e]]
main=interact$map(zip z x!).m.(>>=(zip x z!))

Ugh, this feels way too lengthy, but at least I'm... beating Python somehow. And Ruby.

Javascript (ES6), 141 124 120 bytes
Believe it or not.... :-)
(t,i=0,c=w=>(t.charCodeAt(w)-123)%91+26)=>String.fromCharCode(...[...t].map(k=>(c(i)%9*3+c(++i%t.length)/9+65|0)%91+32))

As with my other answer, this is an anonymous function, and needs to be assigned to a variable before it can be used. Try it here:

e=(t,i=0,c=w=>(t.charCodeAt(w)-123)%91+26)=>String.fromCharCode(...[...t].map(k=>(c(i)%9*3+c(++i%t.length)/9+65|0)%91+32));

input=document.getElementById("input");
p=document.getElementById("a");
input.addEventListener("keydown", function(){
  setTimeout(function(){p.innerHTML = e(input.value);},10);
})
<form>Type your text here: <input type="text" id="input" value="hello world"/>

Only space and lowercase letters are allowed.</form>

Output:

vnhhr nqzgj

I thought I might be able to shave a couple bytes off my previous answer by using a different technique, so I started out with one similar to Tekgno's and golfed my head off from there. I initialized some variables in the function's argument section, and again stuffed everything into a .map function. Then I realized the String.fromCharCode would be much more efficient outside the .map. After all was said and done, I had shaved off more than 30 45 bytes!
Edit 1: Saved 17 bytes by getting rid of the .replaces, using a technique similar to xnor's Python solution.
OK, maybe it's time to move onto another challenge....

Python 2, 182 180 Bytes
This solution is not ideal, due to the replace being very costly.. Trying to figure out how to avoid that.
b=lambda k:k and b(k/3)*10+k%3
s=''.join('%03d'%b(ord(x)-6-91*(x>' '))for x in input())
print`[chr(int((s[1:]+s[0])[i:i+3],3)+97)for i in range(0,len(s),3)]`[2::5].replace('{',' ')

Input is like "hello world".

You need to count 2 bytes for required quotation marks in the input, right?

@mbomb007 That's what I had thought previously, but multiple people have told me I don't need to account for that.

Javascript (ES6), 179 bytes
s=>[...s+s[0]].map(q=>`00${(q<'a'?26:q.charCodeAt(0)-97).toString(3)}`.slice(-3)).join``.slice(1,-2).match(/..?.?/g).map(q=>q>221?' ':String.fromCharCode(parseInt(q,3)+97)).join``

Props to vihan for the .match regex.

Mathematica, 162 bytes
r=Append[#->IntegerDigits[LetterNumber@#-1,3]~PadLeft~3&/@Alphabet[]," "->{2,2,2}];StringJoin[Partition[RotateLeft[Characters@#/.r//Flatten,1],3]/.(#2->#1&@@@r)]&

(Re)Using a Rule to convert the digit lists to characters and back.

Ruby, 177
Needs at least Ruby 1.9 for the each_char method
l=[*('a'..'z'),' '];n=(0..26).map{|m|m=m.to_s(3).rjust 3,'0'};s='';gets.chomp.each_char{|x|s+=n[l.index x]};puts("#{s[1..-1]}#{s[0]}".scan(/.../).map{|i|i=l[n.index i]}.join '')

Java, 458 449 bytes
It made me a little sad to determine that I could shave off 10 bytes by not using Java 8 streams and the map() method.
Here is the golfed version:
import org.apache.commons.lang.ArrayUtils;class A{public static void main(String[]a){int b=0;String[] c=new String[27];for(;b<27;++b)c[b]=String.format("%03d",Integer.valueOf(Integer.toString(b,3)));String d=a[0],e="abcdefghijklmnopqrstuvwxyz ",f="",g="";for(b=0;b<d.length();++b)f+=c[e.indexOf(d.substring(b,b+1))];f=f.substring(1)+f.charAt(0);for(b=0;b<f.length();b+=3)g+=e.charAt(ArrayUtils.indexOf(c,f.substring(b,b+3)));System.out.println(g);}}

Here is a much less golfed version.  It is intended to be readable, but I make no guarantees.
import org.apache.commons.lang.ArrayUtils;
class A {
    public static void main(String[] a) {
        int b=0;
        String[] c = new String[27];
        for (; b < 27; ++b)
            c[b] = String.format("%03d", Integer.valueOf(Integer.toString(b, 3)));
        String
            d = a[0],
            e = "abcdefghijklmnopqrstuvwxyz ",
            f = "",
            g = "";
        for (b = 0; b < d.length(); ++b)
            f += c[e.indexOf(d.substring(b, b + 1))];
        f = f.substring(1) + f.charAt(0);
        for (b = 0; b < f.length(); b += 3)
            g += e.charAt(ArrayUtils.indexOf(c, f.substring(b, b + 3)));
        System.out.println(g);
    }
}

This program takes the string to convert as a command-line argument.  If you want to have spaces in your input, you have to surround it with double quotes.
I wanted to provide an example of using this from the command line, but I was unable to get this code to work outside of Eclipse.  I never learned to use Java from the command line  ^_^;  You can probably get this running inside the IDE of your choice without too much trouble.

if you only use the ArrayUtils once using the fully qualified name inside the code is shorter than that import statement. see: http://codegolf.stackexchange.com/a/16100/10801 (bottom half of linked answer)

Javascript (ES6), 181 180 bytes
t=>((x=[...t].map(k=>`00${(k<'!'?26:k.charCodeAt(0)-97).toString(3)}`.slice(-3)).join``).slice(1)+x[0]).match(/.../g).map(j=>j>221?' ':String.fromCharCode(parseInt(j,3)+97)).join``

This is an anonymous function, so it needs to be given a name before it can be used. (E.g. encrypt=t=>...) Try it out here:

e=t=>((x=[...t].map(k=>`00${(k<'!'?26:k.charCodeAt(0)-97).toString(3)}`.slice(-3)).join``).slice(1)+x[0]).match(/.../g).map(j=>j>221?' ':String.fromCharCode(parseInt(j,3)+97)).join``;

input=document.getElementById("input");
p=document.getElementById("a");
input.addEventListener("keydown", function(){
  setTimeout(function(){p.innerHTML = e(input.value);},10);
})
<form>Type your text here: <input type="text" id="input" value="hello world"/>

Only space and lowercase letters are allowed.</form>

Output:

vnhhr nqzgj

I started out using multiple variables and for loops instead of .map. I then golfed it in every possible way without changing the algorithm, which put me somewhere around 217 bytes. After taking a look at UndefinedFunction's answer, I managed to get it down to 195, and some inspection of Dendrobium's answer resulted in another 14 golfed off.
As far as I'm aware, I can't go any further or my result would be practically identical to Dendrobium's (except for being one character shorter!). Can anyone find the place where I saved one char? :-)
As usual, suggestions are gladly welcome!

Thanks for the regex tip! I'm not sure how exactly the for-of loop could be worked into this one-line function, but perhaps it would save some space anyway. You can post your version if you like.

Julia - 92 87 61 54 bytes
s->join(32+(3(i=[s...]%91+579)%27+i[[2:end,1]]÷9)%91)

Ungolfed:
function f(s)
  t=[s...];       # Convert the string into a char array
                      #
  i=t%91+579          # Mod 91 drops the alpha characters to sit just
                      # below space, then 579 is added as a trick,
                      # equivalent to subtracting 6 and adding 9*65
  v1=3i%27            # This shifts the bottom two ternary digits up
                      # and removes the first ternary digit
  v2=i[[2:end,1]÷9    # This shifts the first ternary digit down and
                      # removes the bottom two ternary digits. [2:end,1]
                      # rotates the array to put the first value at the end
  N=(v1+v2)%91+32     # this combines the ternary digits, then returns
                      # the values to the correct ASCII values
  j=join(N)           # join the char array back to a string
  return j
end

The trick may confuse you. Subtracting 6 moves 'a' down to zero after the mod. Adding 9*65 is equivalent to adding 65 to v1+v2, which is part of the process of restoring the values to their ascii values. You could replace i=t%91+579 with i=t%91-6, and then replace N=(v1+v2)%91+32 with N=(v1+v2+65)%91+32 to get the same result, but it requires one extra character.

Matlab, 113 bytes
x=dec2base(strrep(input('','s'),' ','{')-97,3)';strrep(char(base2dec(reshape(x([2:end 1]),3,[])',3)+97)','{',' ')

Input is through stdin.
Example:
>> x=dec2base(strrep(input('','s'),' ','{')-97,3)';strrep(char(base2dec(reshape(x([2:end 1]),3,[])',3)+97)','{',' ')
hello world
ans =
vnhhr nqzgj


text:
ASCII Art Archery Arrows
Write a program or function that takes in a positive integer and prints or returns an ASCII art depiction of an archery arrow, scaled according to the input.
If the input is 1 the output is
  /\
 /  \
 \__/
  ||
  ||
  ||
  ||
  ||
  ||
  ||
  ||
 /||\
/ || \
/ || \
//  \\
/    \

If the input is 2 the output is
     /\
    /  \
   /    \
  /      \
  \      /
   \____/
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
   /|  |\
  / |  | \
 /  |  |  \
/   |  |   \
/   |  |   \
/   |__|   \
/  /    \  \
/ /      \ \
//        \\
/          \

If the input is 3 the output is
        /\
       /  \
      /    \
     /      \
    /        \
   /          \
   \          /
    \        /
     \______/
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
      |    |
     /|    |\
    / |    | \
   /  |    |  \
  /   |    |   \
 /    |    |    \
/     |    |     \
/     |    |     \
/     |    |     \
/     |____|     \
/    /      \    \
/   /        \   \
/  /          \  \
/ /            \ \
//              \\
/                \

If the input is 4 the output is
           /\
          /  \
         /    \
        /      \
       /        \
      /          \
     /            \
    /              \
    \              /
     \            /
      \          /
       \________/
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
        |      |
       /|      |\
      / |      | \
     /  |      |  \
    /   |      |   \
   /    |      |    \
  /     |      |     \
 /      |      |      \
/       |      |       \
/       |      |       \
/       |      |       \
/       |      |       \
/       |______|       \
/      /        \      \
/     /          \     \
/    /            \    \
/   /              \   \
/  /                \  \
/ /                  \ \
//                    \\
/                      \

The pattern continues on for larger input numbers - the arrow is scaled up accordingly.
Notice that for any input N:

The arrowhead is a pentagon with 2×N underscores at the base, N slashes on each of the sides extending from the base, and 2×N slashes on the two sides that form the arrow tip.
The shaft (including the part within the fletching) consists of 11×N lines of two vertical bars separated by 2×(N-1) spaces. The very last line has underscores instead of spaces.
The fletching surrounds the lower 3×N lines of the shaft. Two lines of 2×N slashes extend diagonally downward from either side of the shaft and are joined with vertical columns of slashes.
The complete arrow is 16×N lines high and 6×N characters wide.

In your output there should be no empty lines before the arrow tip and only up to one trailing newline.
None of the output lines should have unnecessary leading spaces (the left edge of the fletching should be as leftmost as possible) but any of the lines may have any number of trailing spaces.
The shortest submission in bytes wins.

Is there a maximum input size?

@vihan No. Though you can assume the numbers wont overflow your memory/integers.

Should we worry about text wrapping?  For N>=14, the default window size on my terminal makes my arrow look not like an arrow.

@kevinsa5 No. Don't worry.

Pyth, 149 147 146 144 146
Edit 2015-9-23: had a bug, fixed for 2 bytes. Might be possible to make shorter, I have no time now.
Still seems too long for a Pyth answer.
M*tGHK*11Q=Y*3QA" /"jbC+R*yQG+_Js[ms[*dGHgt-YdG\_gKG\_)tQs[gQGHgyQG\_*K\|)ms[*+QdGH*y-tQdG\\*+*8QydGHgYGH)Qms[*++KQdGHgYGH)tQ+g*13QG*hYH)mXd"\/")J

Explanation (almost up to date)
I basically generate the transpose of the arrow, since its line format is much simpler. Also, I only generate one half and then reverse it to save a lot of bytes.
M*tGH                                                       g(a,b) = (a - 1) * b
A" /"                                                       G = " ", H = "/"
              ms[...)tQ                                     N-1 lines inside body
                       s[...)                               1 line of edge of body
                             ms[...)Q                       N lines of tip + fin
                                     m...Q                  N-1 lines of fin
                                          +...              1 line of edge of fin
            s[                                )             flatten the maps to it
           J                                                save to J
          _                                                 reverse
                                                       J    another copy (unreversed)
                                               mXd"\/")     swap "\" and "/" on each line
         +                                                  add to other half
   +R*yQG                                                   add 2*N spaces to each line
  C                                                         transpose
jb                                                          join by newline

m                             tQ       map d over 0...N-2
 s[                          )         concatenate
   *dG                                 d spaces
      H                                "/"
          =Y*3Q                        save 3*N to Y
       gt-     dG                      3*N-d-2 spaces
                 \_                    "_"
                    K*11Q              save 11*N to K
                   g     G             11*N-1 spaces
                          \_           "_"

s[              )                      concatenate
  gQG                                  N-1 spaces
     H                                 "/"
      gyQG                             2*N-1 spaces
          \_                           "_"
            *K\|                       11*N pipes

m                               Q      map d over 0...N-1
 s[                            )       concatenate
   *+QdG                               N+d spaces
        H                              "/"
         *y-tQdG                       2*(N-d-1) spaces
                \\                     "\"
                  *+*8QydG             8*N+2*d spaces
                          H            "/"
                           gYG         3*N-1 spaces
                              H        "/"

m               tQ                     map d over 0...N-2
 +++                                   concatenate
    *++KQdG                            12*N+d spaces
           H                           "/"
            gYG                        3*N-1 spaces
               H                       "/"

+                                      concatenate
 g*13QG                                13*N-1 spaces
       *hYH                            3*N+1 slashes

Perl, 298 bytes
for$y(0..($w=<>)*16-1){$r=$w*3;for$x(0..$w*6-1){$z=$x<$r?$x:$w*6-$x-1,$_.=$z==$r-$y-1&&$y<$w*2||!$z&&$y>=$w*13-1||($z==$w*16-1-$y||$z==$w*13-1-$y)&&$z<$w*2?$x<$r?'/':'\\':$z==$y-$w&&$y>=$w*2&&$y<$r?$x<$r?'\\':'/':$z==$r-$w&&$y>=$r&&$y<$w*14?'|':$z>=$r-$w&&($y==$r-1||$y==$w*14-1)?_:$"}$_.=$/}print

Multi-line:
for$y(0..($w=<>)*16-1){$r=$w*3;  # read input and loop over rows
    for$x(0..$w*6-1){  # loop over columns

        # flip x on right side of arrow:
        $z=$x<$r?$x:$w*6-$x-1;

        # slashes on fletching and tip of arrowhead:
        $_.=$z==$r-$y-1&&$y<$w*2||!$z&&$y>=$w*13-1||($z==$w*16-1-$y||$z==$w*13-1-$y)&&$z<$w*2?$x<$r?'/':'\\':

        # slashes on underside of arrowhead:
        $z==$y-$w&&$y>=$w*2&&$y<$r?$x<$r?'\\':'/':

        # vertical bars on side of shaft:
        $z==$r-$w&&$y>=$r&&$y<$w*14?'|':

        # underscores on base of arrowhead and shaft:
        $z>=$r-$w&&($y==$r-1||$y==$w*14-1)?_:$"
   }
   $_.=$/  # add newline at end of each row
}
print  # print out string

Output:
2
     /\
    /  \
   /    \
  /      \
  \      /
   \____/
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
    |  |
   /|  |\
  / |  | \
 /  |  |  \
/   |  |   \
/   |  |   \
/   |__|   \
/  /    \  \
/ /      \ \
//        \\
/          \

Thanks to Dom Hastings for helping me save 5 (and counting) bytes

Hey samgak, you can save a few bytes by moving the $w=<> declaration to the first time you use it like for$y(0..($w=<>)*16-1){ and a lot of the brackets can be removed (some do change the output, but I think you're going through those anyway!). Also your '_' can just be a literal _. Hope that helps!

Ruby, 233
->n{(16*n).times{|i|j=i/n
m=n*3
e=' '*6*n
i%(11*n)==m-1&&e[2*n..4*n-1]=?_*2*n
j%14>2&&e[m+n-1]=e[m-n]=?|
k=(i-n)%m
k<n||j<11||(e[m+k]=?\\;e[m-1-k]=?/)
j>12&&(e[-1]=?\\;e[0]=?/)
j<3&&(e[n+l=(i-n*2)%(n*4)]=?\\;e[5*n-l-1]=?/)
puts e}}

I am particularly pleased with the wraparound technique I used to draw all \ in the head with a single expression (and likewise for /)
Ungolfed in test program
f=->n{
  #loop line by line, 0..16*n-1
  (16*n).times{|i|

  #convenience variables
  j=i/n
  m=n*3

  #setup a string of spaces
  e=' '*6*n

  #draw the ___ at top and bottom of shaft
  i%(11*n)==m-1&&e[2*n..4*n-1]=?_*2*n
  #draw the |, overwriting the _ in the bottom corners
  j%14>2&&e[m+n-1]=e[m-n]=?|

  #draw the diagonal fletching
  k=(i-n)%m
  k<n||j<11||(e[m+k]=?\\;e[m-1-k]=?/)

  #draw the ends of the fletching (note index -1, meaning last character in string)
  j>12&&(e[-1]=?\\;e[0]=?/)

  #draw the arrow head, wrapping round with %(n*4)
  j<3&&(e[n+l=(i-n*2)%(n*4)]=?\\;e[5*n-l-1]=?/)

  #output the line
  puts e}
}

f.call(gets.to_i)

Julia, 452 bytes
This answer isn't very inspired, and I haven't golfed it beyond the glaringly obvious.  I intend for this to be a score for other people to beat.
function R(c,x,y,e,f,n)
for i=1:n
a[y,x]=c
x+=e
y+=f
end
end
function f(n::Int)
global a=fill(' ',16n,6n)
F='/'
B='\\'
q=3n+1
r=2n+1
R(F,3n,1,-1,1,2n)
R(B,q,1,1,1,2n)
R(B,n+1,r,1,1,n)
R(F,5n,r,-1,1,n)
R('_',r,3n,1,0,2n)
R('|',r,q,0,1,11n)
R('|',4n,q,0,1,11n)
R('_',r+1,14n,1,0,r-3)
R(F,2n,11n+1,-1,1,2n)
R(B,4n+1,11n+1,1,1,2n)
R(F,1,13n,0,1,3n)
R(B,6n,13n,0,1,3n)
R(F,2n,14n+1,-1,1,2n)
R(B,4n+1,14n+1,1,1,2n)
for b = 1:16n
println(join(a[b,:]))
end
end

Try it out:
julia> f(1)
  /\
 /  \
 \__/
  ||
  ||
  ||
  ||
  ||
  ||
  ||
  ||
 /||\
/ || \
/ || \
//  \\
/    \

ungolfed:
# Repeat a character through array a from (x,y) -> (x+n*dx,y+n*dy)
function R(a::Array{Char,2},c::Char, x::Int, y::Int, dx::Int, dy::Int, n::Int)
    for i = 1:n
        a[y,x] = c
        x += dx
        y += dy
    end
end

function arrow(n::Int)
    a = fill(' ',16n,6n)
    # upper left of head
    R(a,'/',3n,1,-1,1,2n)
    # upper right of head
    R(a,'\\',3n+1,1,1,1,2n)
    # lower left of head
    R(a,'\\',n+1,2n+1,1,1,n)
    # lower right of head
    R(a,'/',5n,2n+1,-1,1,n)
    # bottom of head
    R(a,'_',2n+1,3n,1,0,2n)
    # shaft
    R(a,'|',2n+1,3n+1,0,1,11n)
    R(a,'|',4n,3n+1,0,1,11n)
    R(a,'_',2n+2,14n,1,0,2n-2)
    # upper fletching edges
    R(a,'/',2n,11n + 1,-1,1,2n)
    R(a,'\\',4n+1,11n+1,1,1,2n)
    # fletching sides
    R(a,'/',1,13n,0,1,3n)
    R(a,'\\',6n,13n,0,1,3n)
    # lower fletching edges
    R(a,'/',2n,14n + 1,-1,1,2n)
    R(a,'\\',4n+1,14n+1,1,1,2n)
    for r = 1:16n
        println(join(a[r,:]))
    end
end

Vyxal, 128 bytes
d(\/n꘍⁰3*↳øṀ,)(⁰n+\\꘍⁰d‹n- n⁰‹=[\_|ð]*+øṀ,)8*(⁰d\|꘍⁰‹꘍m,)d(\/n꘍⁰d↳\|+⁰‹꘍øṀ,)(\/⁰d↲\|+n⁰‹=[\_|ð]⁰‹*+øṀ,)d(\/n꘍⁰d‹↳:L⁰d≠[\/p]⁰꘍øṀ,

Try it Online!
Generates the rocket bit by bit.

Saying "beats all other answers" isn't encouraged here, because we are competing on a per-language basis, not language-versus-language.

@Razetime Sorry. Other people have been saying that, and I copied them.

Python 3, 336 bytes
def f(n):
 N=n+n;R=[*range(3*n)]
 L = [f'/{i*"  "}\\' for i in R[:N]] + [f'\\{2*(N+~i)*"_ "[i+1<n]}/' for i in R[:n]] + [f'|{"  "*~-n}|']*8*n + [
  f'/{"|"+2*~-n*"_ "[i+1<3*n]+"|":^{2*min(i,N-1)+N}}\\' for i in R
 ] + ["/"*(i+1<N)+f'/{"  "*(n+i)}\\'.center(6*n-2)+"\\"*(i+1<N) for i in R[:N]]
 return "\n".join(u.center(6*n).rstrip() for u in L)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
Digitising the Library of Babel
The Library of Babel is defined as

a universe in the form of a vast library containing all possible
  410-page books of a certain format and character set.

For the purposes of this question, each page of the book contains 40 lines of 40 characters each. The formatting rules are as follows:

Legal characters are the English Latin alphabet a-z,A-Z and the punctuation characters , . (comma, space and full stop).
Each page contains at least one space, one full stop, one capital character and one comma.
There must be a space after every full stop and comma. No combination of the punctuation characters , . may be present more than twice in a row, and identical punctuation marks cannot exist consecutively.
All alphabetic characters immediately after a full stop and its accompanying space must be capitalised. This applies unless the full stop is the last or second last character on a page. Capital characters may not occur anywhere else.

Challenge
Write a program or function which outputs a number of page excerpts from the Library of Babel, with a newline between each page excerpt.
Most importantly, the program must be able to theoretically perfectly replicate the entire Library of Babel if given an infinite number for the number of page excerpts to produce and a truly random RNG (Pseudorandom random number generators are allowed in the code, but assuming the PRNG is replaced with a true RNG, the code should theoretically produce the entire library).
Since this is code golf, the shortest answer will be accepted.
An example of valid output (for 2 pages):
, umqdzvvrdgijqrjv qmupgpgqeaegnqmmcig g
j itzgdr cdrsjgggmgjqgzplhrtoptqmbshbzgg
qcqqm plipugorpgqftnvmmgodpqaopqqfpbddnn
shmgqbf gqjclzjqaqpandqdjnfnrsgjamqqnzvu
ufzebfdbescszbvfoatftsqtefssbnnztiaupezu
gmtahqpisucljvpqohsauoudppsumnrlqjlfiapd
aurlenavahnbbbver. Lvjbgilspusdunufrgfng
nghpbcusnscibepjqhgjgcemzjdcqqjdprsrunih
emqgrfrgoqrnsvqofbrvsaqhsrqndhuhulolrese
visneqbjssfjtdrmuqq tfseuczgvbuetgijhtcs
aqnubefzuet. Gjctngshammusvdaogamtuo ajs
edjbctevfdnodgg jubshhsuaniqnsqrvatquqtg
bgoffnd hepqngjnusmglcqgdse q rdlzjqggfr
evvrcfezqqditbpztttirravbzegzleafashfzed
nhngjcccvzmmnmgpimoeztfcu laupeg rogtrip
nuaaghqptet, gss csrszqpnmvgcevqqzrfegus
lnninfajhsaapgpcljiooednbusfbmcmgqunvvzd
o dcztfgdovr. Ru, gvjchisbvo sslpzolptss
hnjbmovglvbu idqlgehrztfshrhbigivijh foi
bqcqggpjfus qmdituqucqdqgogzuvevlhujojuu
dnsuqvcsptnsjrqiezfqrjucsongqgbbutvsoqld
s vbollthqsgambsaoqgvgapszhgvsjnqepeqgvv
pqzpbqhcmfbhfcz gdeuzogmtzqjvohldeafchip
olztntqn vgtiofcjzmfluqoqruaqcqmnmfafvnc
ruzahccrqpzji, gdrhcu pgjuhqqvsgppgzrioq
qjgh oapzdiusqem ubtnhhbpdt sjzbidggsgve
ocdiuungsghltqsuezoco qqgcpnupiisnrngetq
lbjdrbqzqnqmj crgreugncqaulhqegjfq. Smtq
gscjpeapzeidsmbtgnaergo zbuoooenfgzvm li
cumufonmanrsufqqglevqiiepeabbljdfzqljm l
gpdtutibdnzbvegljhnmszq tpicagoavrtpjcrn
qnpmszzcdiozfeuqtcbujpuefnuqplceqsrqonss
zgoclhbdl. Fsrgqeuouergciq. Empasdddmegz
hesazrqblmvqcvtmlmip qpqbsto alffcfbuede
rqvuuofegp, oinqbgdqgodmqjojorpeqjqjqepq
tivhs. Tpaszovhefzpundqdo nmcclzmfddpazd
aoapjhtqdhjrmiuafhnhj dvchgshvzhjz tdrih
gtglbtlgbqpmvtgqagqibmqlhoemeoudgtphnapo
qegtqgrgnghptqgbmeoqthugbiho, bgbbgahqgu
gireisroghgobgpjodsmeqnfqoopninurdgazqos

. Rnffadjgqpgzngbpeztqrpuagprscopqnuzntf
upvamihntmjrcbfzbnmsfpsueepbsogmdcnpluci
fnoioffqtsitgatmfhn zuiozvpgprpvdpesujhn
bqlhqdtvmgtiabhz zdmothrhniczqqtgbg eatr
gmognhdjegzsaei. Gloiampbtmgtetoq gdfjoj
rlbrpjogclullgonomttrrshpolujodajesopsfr
cabnhbohntadjtltsztbvzcebvdqnjhplicslco
vabftndmi netqjv. Rl tmicpanralmamruovfi
ssnmh gtlsqilcrnrsaislut mnzhsfojtmsqtlb
mbl dcjvuldnvtfsjsp, urundndz ehopedrptm
abtvadojvdbe tolzmotjtbiigmazlmznjrnof i
ioogsospoghiojshqdimpuibeaosflbpjqvcdord
uomtjebohjmzeutjvmca eq, ljttbbtaomjsoja
z crvmmhonescmnovmnznf brhufrudosfensru
fdotflmug gclmondggitamnsrsfjiaqnootlanr
tuiftvia. Rccnvuebeocub, unihegbtqgslps
ngsqjflejnitpcorluetbiacgqjtbtroejeopqso
ca sdziornhsvivcteaadspibt qippmqmduinia
oqtvoo ttt qnfrfchpszaiiecsrmsrblmbojot
h rtjzqqo esufacjdvbposroesoorszoiutfloe
hs bt eibajrocingbmvterhomfuzttemvfjtltv
lcmoevnlzofpd zsjbmgvllhgrsoclvnnhnscodo
tjocglurng hrhp og bstpeabzdaocoircqb go
devvmlslsqnjibpjcmndmqdvgfmhcsvgzrbicuuv
jgfthudlg. Tfsnn tuarpgogh ibsemtjfgdisj
tgcetprzomzfadthmrroivoheepingsmovrmjiit
ufdvi cvpti oift. Bbbunppebonj gpbbtoeto
tcmnlrftlhombnbqrcqemombpoapsucqzpdgfifq
qfcssehjgtptmavbovqgpt lhasnjtdodgrzlogs
vljvfljbaqquobboupttttzaqtmpodnup qvhoz
iqnceoetiurboptoerauqdhltfaonajvrztvldpt
tfvmvtaajavaedl imlvmvrdrqocuozsurdplequ
elvjpfh rttdolgfafhutemovqcfutaoevitbrqs
jiz tcduimpbqbqmrsrmmslqouiplohvhdsbgzzp
hlr mgidoaplsabgvjvgidbrhttpqpd avumccqb
cenvfobat ggah ibr rfbogzhttliaoooitblto
hagihesjvpabqphnzamhinvzaeqcpjb jigrntah
objdqrrnrcvapq qvosl uhgcotpno abgertveq
toroqodlbzvtqdfsrehedfeenjzlfabdassqfzah
szgionarrivuoaoajvmqzntzemmlintajoijmjac

@Vioz- I am assuming that the RNGs are all not truly random, and they don't need to be. What I mean is that if the PRNG was made truly random, it should be able to produce the library in its entirety.

"Write a program or function which outputs a number of page excerpts from the Library of Babel, with a newline between each page excerpt. " I don't understand this. The example output looks like one page from a book to me, not a number of pages

Can a page start or end with a symbol? Can there be a space before a symbol?

@Vioz- Yes, it can, as long as all other rules are followed. Since both non-space symbols must be followed by a space, there cannot be a space before a symbol as this would violate the <=2 symbol rule.

I assume no outputed page can ever be a duplicate of another one?

Well because in that case the condition that the program should "theoretically perfectly replicate the entire Library of Babel " is kind of meaningless because a program that generates a 40 lines 40-chars wide page with completely random characters will eventually replicate the library of babel, given (a lot) of time

@Fatalize The idea is to weed out programs that generate an entire field of alphabetic characters and convert the first few characters into punctuation (or similar loophole abuse).

Your first line is 41 characters.  How is that legal?

@NotthatCharles Made a typo while editing in some additional concerns, fixed. Thanks.

The only part of point 3 I'm certain I understand is the first sentence. What do you mean by "twice in a row" and, in particular, what is the distinction between that and "consecutively"?

@PeterTaylor (,|\s|\.){3} is illegal

Ok, so it comes down to  "There must be a space immediately following every full stop and comma, and a letter immediately following every space". Modulo the cases which would make it contradict point 4, which allows non-alpha characters to end the page.

Lua, 353 346 bytes
Because of how lengthy the Pyth answer is and the fact that I know Lua could never even come close to Pyth I feel like I am missing a rule...
Code:
math.randomseed(os.time())g="abcdefghijklmnopqrstuvwxyz ,."for i=1,io.read() do
print(" ")for i=1,40 do k=0h=0v=0 print("")for j=1,40 do c=math.random(1,#g-h-v)t = g:sub(c,c)if v>0 then v=0 end
if r==1 then r=0;t=t:upper()end if c>26 then v=2;if t=="." then r=1 end k=k+1;if c>27 then t=t.." " end if k>1 then h=2 end end io.write(t) end end end

Probably can be golfed down quite a bit, but this is it for now.

Pyth, 125 72 bytes
VQV1601=+kO+G",. "Iqek\,=+k+dOG)Iqek\.=+k+dOrG1)Iqekd=+kOG))VhcckJ40JN)d

Try
it online here.
I finally golfed this down to a reasonable size. And by "golfed down" I mean "rewrote entirely". It still doesn't meet the requirements perfectly, but it's better than the previous iteration. I even have a breakdown now:
  O+G",. "     Randomly choose a lowercase letter (variable G), comma, period, or space
  +k           Append it to variable k (initialized to empty string)
  Iqek\,       If the last character of k is a comma:
   =+k+dOG)     Append a space (variable d) and a random lowercase letter to k
  Iqek\.       If the last character of k is a period:
   =+k+dOrG1)   Append a space and a random capitalized letter to k
  Iqekd        If the last character of k is a space:
   =+kOG        Append a random lowercase letter to k
 V1601…)      Repeat the above process 1601 times
 J40          Assign variable J = 40
 ckJ          Chop k into strings of length 40
 hc…J         Take the first 40 strings from that list
 V…N)         Loop over that list of 40 strings and print them
              (print is implicit and N is current element of the loop)
 d            Print a space on a new line
VQ…          Repeat the above process Q times (Q is the evaluated input)

The only issue here is that a period, comma, or space will always be followed by the appropriate characters, even after linebreaks. For example, if a line ends with a period, the next line will always start with a space followed by a capital letter. I do not think this is what the question asked for.

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Fill empty spaces by filling empty blanks
Write a function (such as placeAt) that takes an array of non-negative integers and an index that is a non-negative integer. It should place a 1 at the given index, possibly shifting other entries by one spot to vacate that spot, with 0's standing for empty spots.

If the entry at the desired index is 0, fill it with a 1.
Otherwise, look for the nearest 0 to the left of the index. Shift entries one spot left into that 0 to make room, then fill the index with a 1.
If there's no 0 to the left, do the same going right.
If neither is possible (i.e. if there is no 0), return the array unchanged.

The items are 0-indexed. Function name can be anything you want.
Examples:
(Letters stand for any positive integer values.)
[a, b, 0, c, d, 0] placeAt 2    // output [a, b, 1, c, d, 0]    place 2 is 0, just fill
[a, b, 0, c, d, 0] placeAt 3    // output [a, b, c, 1, d, 0]    place 3 is filled, shift items left
[a, b, 0, c, d, 0] placeAt 0    // output [1, a, b, c, d, 0]    place 0 is filled, can't shift left, shift items right
[a, b, 0, c, d, 0] placeAt 1    // output [a, 1, b, c, d, 0]    place 1 is filled, can't shift left, shift items right
[0, a, b, 0, c, d, 0] placeAt 2 // output [a, b, 1, 0, c, d, 0] place 2 is filled, shift items left
[0, a, b, 0, c, d, 0] placeAt 4 // output [0, a, b, c, 1, d, 0] place 4 is filled, shift items left (notice you keep shifting up until a 0)
[0, 2, 0, 2] placeAt 3          // output [0, 2, 2, 1]          place 3 is filled, shift items left

This is a code golf challenge. The shortest entry at the end of 9 days wins.

How do you know whether to shift left or right when both are possible? Also, what if there is no 0?

For [0, 2, 0, 2] placeAt 3, is it legal to output [2, 0, 2, 1]? Is the code required to actually be a function called placeAt? Note that some languages don't exactly have functions. "Throw an exception" might also not apply to some languages; I'd suggest allowing an output indicating an error.

Can the array have negative values?

I'm 99% sure I understand the OP's intentions with the rules of this challenge, so I've reorganized the post (it's in the queue right now) and I will attempt to answer questions. eguneys, you can correct any of my answers if need be.

@xnor Shifting left always takes preference over shifting right. If there is no 0, just return the original array. Also, [2, 0, 2, 1] is not a legal output, as you should always shift as few elements as possible, and you can name the function whatever you want.

@Vioz array contents doesn't matter. 0 represent empty non 0 represents full.

JavaScript (ES6), 85
Test running the snippet on any EcmaScript 6 compliant browser (notably not Chrome not MSIE. I tested on Firefox, Safari 9 could go)
(I found this without looking at any of the other answers, now I see it's very similar to rink's. Yet quite shorter. Probably I won't get many upvotes for this one)

F=(a,p,q=~a.lastIndexOf(0,p)||~a.indexOf(0))=>(q&&(a.splice(~q,1),a.splice(p,0,1)),a)

// Ungolfed
U=(a,p)=>{
  q = a.lastIndexOf(0, p)
  if (q < 0) q = a.indexOf(0)
  if (q >= 0) {
    a.splice(q, 1)
    a.splice(p, 0, 1)
  }
  return a
}

// TEST
out=x=>O.innerHTML+=x+'\n';

[ [['a', 'b', 0, 'c', 'd', 0], 2, ['a', 'b', 1, 'c', 'd', 0]] // place 2 is 0, just fill
, [['a', 'b', 0, 'c', 'd', 0], 3, ['a', 'b', 'c', 1, 'd', 0]] // place 3 is filled, shift items left
, [['a', 'b', 0, 'c', 'd', 0], 0, [1, 'a', 'b', 'c', 'd', 0]] // place 0 is filled, can't shift left, shift items right
, [['a', 'b', 0, 'c', 'd', 0], 1, ['a', 1, 'b', 'c', 'd', 0]] // place 1 is filled, can't shift left, shift items right
, [[0, 'a', 'b', 0, 'c', 'd', 0], 2, ['a', 'b', 1, 0, 'c', 'd', 0]] // place 2 is filled, shift items left
, [[0, 'a', 'b', 0, 'c', 'd', 0], 4, [0, 'a', 'b', 'c', 1, 'd', 0]] // place 4 is filled, shift items left (notice you keep shifting up until a 0)
, [['a', 'b', 'c', 'd'], 2, ['a', 'b', 'c', 'd']] // impossible
, [[0, 2, 0, 2], 3, [0, 2, 2, 1]]] // place 3 is filled, shift items left
.forEach(t=>{
  i=t[0]+''
  r=F(t[0],t[1])+''
  k=t[2]+''
  out('Test ' + (r==k?'OK':'Fail') +'\nInput: '+i+' '+t[1]+'\nResult:'+r+'\nCheck: '+k+'\n')
})

+1 because I just learned about the comma operator, and for beating me

@rink.attendant.6 but your use of && to join the splice is better than my comma

Julia, 122 bytes
Just a naïve implementation of the spec to get things started.
f(x,i)=(i+=1;x[i]==0?(x[i]=1):i>2&&x[i-1]==0?(x[i-1]=x[i];x[i]=1):i<length(x)-1&&x[i+1]==0?(x[i+1]=x[i];x[i]=1):error();x)

Ungolfed:
function placeAt(x::Array, i::Int)
    # Make i 1-indexed
    i += 1

    # Shift and modify the array as necessary
    if x[i] == 0
        x[i] = 1
    elseif i > 2 && x[i-1] == 0
        x[i-1], x[i] = x[i], 1
    elseif i < length(x)-1 && x[i+1] == 0
        x[i+1], x[i] = x[i], 1
    else
        error()
    end

    # Return the modified array
    x
end

Ruby, 208 bytes
def f(a,i)
  x=a.take(i).rindex(0);y=a[i+1..-1].index(0)
  if a[i]==0
    a[i]=1
  elsif !x.nil?
    a.delete_at(x);a.insert(i,1)
  elsif !y.nil?
    a.delete_at(y+i+1);a.insert(i,1)
  end
  a
end

Welcome to PPCG! Some simple golfing tips for Ruby: you don't need any indentation, so you can get rid of all the spaces. Then you also don't need the semicolons, because a single newline is the same number of bytes. Method calls at the end of a statement don't need parentheses, so you can do, e.g. .rindex 0, saving one byte each time. You can also save some bytes by using a proc instead of a method, which doesn't even have to be named: ->a,i{...}. The if/elsif/elsif can probably be shortened with a nested ternary operator ...?...:...?...:....

Thanks a lot for the kind advice. I'll look into it and see what I can do.

Haskell, 119 bytes
e=elem 0
r=reverse
f=(g.).splitAt
g(a,y@(x:b))|e(x:a)=r(h(x:r a)1)++b|e y=a++h y 1|1<2=a++y
h(0:r)n=n:r
h(a:r)n=n:h r a

Usage example:
*Main> mapM_ (print.uncurry f) [
                (2,[2,3,0,4,5,0]),
                (3,[2,3,0,4,5,0]),
                (0,[2,3,0,4,5,0]),
                (1,[2,3,0,4,5,0]),
                (2,[0,2,3,0,4,5,0]),
                (4,[0,2,3,0,4,5,0]),
                (3,[0,2,0,2]),
                (2,[2,3,4,5])  ]
[2,3,1,4,5,0]
[2,3,4,1,5,0]
[1,2,3,4,5,0]
[2,1,3,4,5,0]
[2,3,1,0,4,5,0]
[0,2,3,4,1,5,0]
[0,2,2,1]
[2,3,4,5]

How it works: Split the input list at the given position into left part a, the element at the position itself x and right part b. If there's a 0 in  a++x, make room up to first 0 in the reverse of a++x. If there's a 0 in x++b, make room there. If there's no 0 at all, combine all parts unchanged to get the original list again.

JavaScript (ES6), 98 bytes
Pretty much the same approach as my CoffeeScript answer but I'm short-circuiting to the extreme in order to save a return statement:
f=(a,x)=>(~($=a.lastIndexOf(0,x))||~(_=a.indexOf(0,x)))&&a.splice(~$?$:_,1)&&a.splice(x,0,1)&&a||a

Explanation
To easier explain, I have rearranged my code a bit:
// Declare function f with two arguments: array and position
f = (a, x) => {
    // Take the part of the array from beginning to x and find the last 0
    $ = a.lastIndexOf(0, x)

    // Find the first 0 after position x
    _ = a.indexOf(0, x);

    // indexOf returns -1 if they aren't found
    // ~1 == 0 so I am checking if either $ or _ is truthy (zeros were found)
    if (~$ || ~_)
       // If zeros were found in the left, use that.
       // Otherwise use the found zero in the right.
       // Delete it from the array
       // Array.prototype.splice will return an array which evaluates to truthy
       // and continues execution with the &&
       // Insert value 1 at position x, deleting 0 elements
       // The last value is returned
       return a.splice(~$ ? $ : _, 1) && a.splice(x, 0, 1) && a
    else
       // No zeros were found so just return the original
       // In the golfed code the if would have evaluated to false to cut into the || part
       return a
}

Here's some information on JS short-circuit evaluation.
Demo
At the moment this demo only works in Firefox and Edge due to use of ES6:

f=(a,x)=>(~($=a.lastIndexOf(0,x))||~(_=a.indexOf(0,x)))&&a.splice(~$?$:_,1)&&a.splice(x,0,1)&&a||a

// Snippet stuff
console.log = x => O.innerHTML += x + '\n';

console.log(f(['a', 'b', 0, 'c', 'd', 0], 2))
console.log(f(['a', 'b', 0, 'c', 'd', 0], 3))
console.log(f(['a', 'b', 0, 'c', 'd', 0], 0))
console.log(f([0, 'a', 'b', 0, 'c', 'd', 0], 2))
console.log(f([0, 'a', 'b', 0, 'c', 'd', 0], 4))
console.log(f(['a', 'b', 0, 'c', 'd', 0], 2))
console.log(f(['a', 'b', 0, 'c', 'd', 0], 1))

How does this work can you explain please.

@eguneys Explanation added

it doesn't work for f(['a', 'b', 0, 'c', 'd', 0], 2)

@eguneys Fixed. I forgot that CoffeeScript automatically adds one when using their shorthand slice [a..b].

doesn't work for f(['a', 'b', 0, 'c', 'd', 0], 1)

C, 154 bytes
p(a,l,i,c)int*a;{for(c=i;c+1;c--){if(!a[c]){for(;c<i;c++)a[c]=a[c+1];return a[i]=1;}}for(c=i;c<l;c++){if(!a[c]){for(;c>i;c--)a[c]=a[c-1];return a[i]=1;}}}

Passes the given test cases, a is the pointer to the array, l is the length of the array (I hope this doesn't break the brief), i is the index for the insert and c is used internally. Could possibly be improved by combining the left and right search for loops.
Example
int main(int argc, char * argv[]) {
    int a[] = {0, 2, 0, 2};
    p(a, 4, 3);
}

Ungolfed
Straight forward, and not really any tricks beyond K&R style declaration.
p(a,l,i,c) int *a; {
    /* Search left from i (also handles a[i] == 0) */
    for (c=i;c+1;c--) {
            if (!a[c]) {
                    /* Shift items left until i */
                    for (;c<i;c++) a[c]=a[c+1];
                    return a[i]=1;
            }
    }
    /* Search right from i */
    for (c=i;c<l;c++) {
            if(!a[c]) {
                    /* Shift items right until i */
                    for(;c>i;c--) a[c]=a[c-1];
                    return a[i]=1;
            }
    }
}

R, 87 bytes
f=function(a,i)if(0%in%a)append(a[-abs(min((b=which(a==0))*(1-(b<=i+1)*2)))],1,i)else a

Explanation
function(a,i)
if(0%in%a)                      # as long as a 0 exists
    append(                     # append 1 after i
        a[
          -abs(                 # remove absolute of min index
            min(                # minimum of adjusted index
              (b=which(a==0))*  # index of all 0's
              (1-(b<=i+1)*2)    # multiple -1 if <= i
              )
            )
        ]
        ,1
        ,i
    )
else                            # otherwise return untouched
    a

Tests
> f(c(2, 3, 0, 4, 5, 0) , 2)
[1] 2 3 1 4 5 0
> f(c(2, 3, 0, 4, 5, 0) , 3)
[1] 2 3 4 1 5 0
> f(c(2, 3, 0, 4, 5, 0) , 0)
[1] 1 2 3 4 5 0
> f(c(2, 3, 0, 4, 5, 0) , 1)
[1] 2 1 3 4 5 0
> f(c(0, 2, 3, 0, 4, 5, 0) , 2)
[1] 2 3 1 0 4 5 0
> f(c(0, 2, 3, 0, 4, 5, 0) , 4)
[1] 0 2 3 4 1 5 0
> f(c(0, 2, 0, 2) , 3)
[1] 0 2 2 1
>

CoffeeScript, 96 bytes
f=(a,_)->a.splice((if~($=a.lastIndexOf 0,_)then $ else a.indexOf 0),1);a.splice(_,0,1)if 0in a;a

C#, 265 bytes
Golfed (265 Characters)
static void placeAt(String[]Q,int P){int I;if(Q[P]=="0"){Q[P]="1";}else{I=Array.IndexOf(Q,"0");if(I>=0){if(I<P){for(int i=I;i<=P;i++){Q[i]=(i==P)?"1":Q[i+1];}}else if(I>P){for(int i=I;i>=P;i--){Q[i]=(i==P)?"1":Q[i-1];}}}}foreach(String s in Q)Console.Write(s+" ");}

With white spaces and indentations
static void placeAt(String[] Q, int P)
    {
        int I;

        if(Q[P] == "0")
        {
            Q[P] = "1";
        }
        else
        {
            I = Array.IndexOf(Q, "0");
            if (I >= 0)
            {
                if (I < P)
                {
                    for (int i = I; i <= P; i++)
                    {
                        Q[i] = (i == P) ? "1" : Q[i + 1];
                    }
                }
                else if (I > P)
                {
                    for (int i = I; i >= P; i--)
                    {
                        Q[i] = (i == P) ? "1" : Q[i - 1];
                    }
                }
            }
        }

        foreach (String s in Q)
            Console.Write(s + " ");
    }

Whole Program
using System;

class FillZero
{
    static void placeAt(String[] Q, int P)
    {
        int I;

        if(Q[P] == "0")
        {
            Q[P] = "1";
        }
        else
        {
            I = Array.IndexOf(Q, "0");
            if (I >= 0)
            {
                if (I < P)
                {
                    for (int i = I; i <= P; i++)
                    {
                        Q[i] = (i == P) ? "1" : Q[i + 1];
                    }
                }
                else if (I > P)
                {
                    for (int i = I; i >= P; i--)
                    {
                        Q[i] = (i == P) ? "1" : Q[i - 1];
                    }
                }
            }
        }

        foreach (String s in Q)
            Console.Write(s + " ");
    }

    static void Main()
    {
        String[] X = {"a", "b", "0", "c", "d", "0"};
        placeAt(X , 1);

    }

}

Test Cases

this doesn't work for ([0, 'a', 'b', 0, 'c', 'd'], 2)

You can save some chars by removing all unnecessary whitespace, for example String[] Q, int P to String[]Q,int P.

Hi @eguneys, thanks for pointing that out. I have modified the logic and thus works for all of your test cases. I have also updated the test cases image. The placing is done correctly, however the shifting results are different.

Hi @ProgramFOX, thanks for your valuable comment. I saved some 10 characters.

Python 2, 102 bytes
def f(a,i):
 x=(a[i-1::-1]+a[i:]+[0]).index(0)
 if x<len(a):del a[(x,i-x-1)[x<i]];a[i:i]=[1]
 return a

Calculates the index of the zero to be removed by concatenating the list reversed up to the insertion index with the part after the index in normal order, then finding the index of the first zero. A zero is added to the end to avoid ValueError exceptions when no zero is found. Then just delete, insert and return.


text:
Prefix Tree Traversal
Write a program that takes in (via stdin or command line) a string with the recursive form
PREFIX[SUFFIXES]

where

PREFIX may be any string of lowercase letters (a-z), including the empty string, and
SUFFIXES may be any sequence of strings with the recursive form PREFIX[SUFFIXES] concatenated together, including the empty sequence.

Generate a list of lowercase lettered strings from the input by recursively evaluating the list of strings in each of the suffixes and appending them to the prefix. Output to stdout the strings in this list in any order, one per line (plus an optional trailing newline).

Example
If the input is
cat[s[up[][]][]ch[e[r[]s[]]]a[maran[]comb[]pult[[]ing[]]]]

then the prefix is cat and and the suffixes are s[up[][]], [],
  ch[e[r[]s[]]], and a[maran[]comb[]pult[[]ing[]]]. Each suffix has
  its own prefix and suffixes in turn.
The output would be these 9 words in any order
catsup
cats
cat
catcher
catches
catamaran
catacomb
catapult
catapulting

because the input encodes this tree

and each of the 9 output words can be formed by traversing the tree
  from root to leaf.

Notes

Remember that the prefix may be the empty string, so something like
[donut[][]cruller[]]

is valid input whose output would be (in any order)
donut

cruller

where the empty line is for the empty string that the second suffix matches.
The suffix sequence can also be empty, so the trivial input case
[]

has a single empty line as its output:

You may assume that the input will only produce unique output words.

e.g. hat[s[]ter[]s[]] would be invalid input because hats is encoded twice.
Similarly, [[][]] is invalid because the empty string is encoded twice.

You may not assume that the input is as short or compressed as possible.

e.g. the 'e' node in the main example above could be combined with the 'ch' node, but that's doesn't mean the input is invalid.
Similarly, [[[[[]]]]] is valid, despite only encoding the empty string in a sub-optimal way.

Instead of a program you may write a function that takes the input string as an argument and prints the output normally or returns it as a string or list.

The shortest code in bytes wins.

Ruby, 119 115
t=['']
l=[0]
gets.chars{|c|c<?]?t<<''&&(l<<0)[-2]+=1:c<?^?(x=l.pop;t.pop==''&&(puts t*''if x<1;t[-1]='')):t[-1]<<c}

Example
Try it: http://ideone.com/NW0CNB
Description
The program gets the input from stdin and outputs the result to stdout.
It traverses the tree keeping the current branch in a stack. There's also a different stack, called weights which keeps track of the number of children of each node. This is needed in order to determine if a node is really a leaf, or it had children in the past.
The readable program:
stack = ['']
weights = [0]

gets.chars do |c|
  case c
  when '['
    weights[-1] += 1
    stack << ''
    weights << 0
  when ']'
    last_weight = weights.pop

    if stack.pop == ''
      puts stack.join if last_weight < 1
      stack[-1] = ''
    end
  else
    stack[-1] << c
  end
end

Haskell, 125 bytes
t=tail.p
p=g.break(=='[')
g(a,(_:t))=(:)&(map(a++).z)$t#[]
z[]=[""];z x=x
(']':u)#a=u:a
s#a=(#)&(a++)$p s
(g&f)(x:y)=g x$f y

The function is t (for traversal):
λ: t "cat[s[up[][]][]ch[e[r[]s[]]]a[maran[]comb[]pult[[]ing[]]]]"
["catsup","cats","cat","catcher","catches","catamaran","catacomb","catapult","catapulting"]
λ: t "[donut[][]cruller[]]"
["donut","","cruller"]
λ: t "[[[[[]]]]]"
[""]

Your code is 124 bytes, not 125 :)

i think the pattern (a,(_:t)) can be (a,_:t) instead

Java, 206 bytes
Defines a function that accepts a string as an argument and returns a list of strings. For an added bonus it returns strings in the same order as the question does.
int c,i;List a(String a){String b=a.substring(c,c=a.indexOf(91,c));List d=new ArrayList();for(;a.charAt(++c)!=93;)d.addAll(a(a));if(d.isEmpty())d.add("");for(i=0;i<d.size();)d.set(i,b+d.get(i++));return d;}

Example usage:
class A{
    public static void main(String[] args){
        System.out.println(new A.a("cat[s[up[][]][]ch[e[r[]s[]]]a[maran[]comb[]pult[[]ing[]]]]"));
    }

    int c,i;List a(String a){String b=a.substring(c,c=a.indexOf(91,c));List d=new ArrayList();for(;a.charAt(++c)!=93;)d.addAll(a(a));if(d.isEmpty())d.add("");for(i=0;i<d.size();)d.set(i,b+d.get(i++));return d;}
}

Expanded:
int c, i;
List a(String a){
    String b = a.substring(c, c = a.indexOf(91, c));
    List d = new ArrayList();
    for(; a.charAt(++c) != 93 ;)
        d.addAll(a(a));
    if (d.isEmpty())
        d.add("");
    for (i = 0; i < d.size();)
        d.set(i, b + d.get(i++));
    return d;
}

I will add an explanation tomorrow.

Python, 212 chars
def p(t,f="",o="",d=0):
 if[]==t:return
 b=[""]
 for c in t:d+=c=="[";b[-1]+=c;d-=c=="]";b+=[""]*(d==0)*(c=="]")
 for r in b[:-1]:i=r.index("[");w,s=f+r[:i],r[i:][1:-1];p(s,w);o+= ["",w+"\n"][""==s]
  if o:print o,

I was hoping to get under 200, but still I am pretty happy with this.

Javascript ES6, 142 bytes
s=>(o=[],x=_=>s[0]==']'?s=s.slice(1):0,(g=d=>{while(s&&!x())[o[d],s]=s.split(/\[(.*)/).concat``,x()?console.log(o.join``):g(d+1),o.pop()})(0))

Q: 70 Bytes
f:{,/'$({(z_x),y}\[();{`$x@&~x="]"}'w;-b])@-1+&0<b:(+/"]"=)'w:"["\:x}

defines a function f that accepts a string and return a list of strings (words)
As a lambda (anonymous function) we drop the first 2 chars f:, so length is 68 Bytes
Test
f "cat[s[up[][]][]ch[e[r[]s[]]]a[maran[]comb[]pult[[]ing[]]]]"

("catsup";"cats";"cat";"catcher";"catches";"catamaran";"catacomb";"catapult";"catapulting")
f "[donut[][]cruller[]]"

("donut";"";"cruller")
f "[[[[[]]]]]"

,""
Notes
,"" indicates a list of strings that contains only has an empty string
Symbols are atomic. Push/pop a symbol on the stack is a simple operation not affected by the lenght of the symbol (see explanation)
Explanation
Q is a cousin of APL (kx.com)
Pseudocode:

Splits string (arg x) at "[" char. Result (list of strings) in w
Counts "]" chars in each elem. of w. Result in b
Modifies each item in w to filter out character "]" and converts each string to a symbol
Generates a logical sequence (bitmap) to mark items >0 in b
Iterates over partial results with a stack: if item marked we must drop one of more symbols (according to value in b). Always append actual symbol to stack
After iterating we have all intermediate states of stack. We select previously marked states
finally for each result we convert symbols to strings and concatenate them

Cobra - 181
def f(s='')as String*
    for m in RegularExpressions.Regex.matches(s,r'(\w*)\[((?:(?<B>\[)|\w|(?<-B>]))*)](?(B)(?!))'),for r in.f('[(u=m.groups)[2]]'),yield'[u[1]]'+r
    if''==s,yield''

If the downvoter would leave a comment saying what is wrong with this, that would be appreciated.


text:
Barcodegolf: Generate a number's UPC
Just about every store nowadays uses Universal Product Code (UPC) barcodes to simplify the checking out process. If the name doesn't mean anything to you, you will surely recognize what they look like:

Format
The most common system is UPC-A, which uses 12 digits to represent each specific product. Each digit is encoded into a series of black and white stripes to allow machines to read the code, a length of seven bits. There are a total of 11 bits worth of patterns that indicate the beginning, middle, and end of the barcode. This comes to a total barcode length of 12 × 7 + 11 = 95 bits. (From now on, when binary is used to refer to the color of each bit, 0 is white and 1 is black.)
The beginning and end both have a pattern of 101. The digits are then divided into 2 groups of 6 and encoded as shown below, with a pattern 01010 between the left and right groups. This table lists the pattern for each number. Note that the pattern is different depending on if the digit is on the right or left side (This allows the barcode to be scanned upside down). However, the pattern for the right is the opposite (swap black for white and vice versa) of that of the left.

If you can't see the image above, this is each number's binary equivalent.
#   Left    Right
0   0001101 1110010
1   0011001 1100110
2   0010011 1101100
3   0111101 1000010
4   0100011 1011100
5   0110001 1001110
6   0101111 1010000
7   0111011 1000100
8   0110111 1001000
9   0001011 1110100

Example
Say you have the UPC 022000 125033. (Those aren't random numbers. Leave a comment if you figure out their significance.) You start with this boilerplate that is the same in every barcode:
101xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx01010xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx101

For the digits, you replace each one with the corresponding encoding for the side (left or right) it's on. If you're still confused, see the image below.

Here is the output in binary with | pipes separating the parts.
101|0001101|0010011|0010011|0001101|0001101|0001101|01010|1100110|1101100|1001110|1110010|1000010|1000010|101

Challenge
Write a program that outputs the UPC-A barcode for the user input. The image's dimensions should be 95 × 30 pixels, with each "bit" being one pixel wide and 30 pixels tall. Black stripes are in rgb(0, 0, 0) and white stripes are consistently transparent or rgb(255, 255, 255).
Notes

Take input from stdin or the command line, or write a function that takes a string or integer (note that input can have leading zeroes, and most languages remove them or convert the number to octal).
Output the image in one of the following ways:

Save it to a file with a name and format (PNG, PBM, etc.) of your choice.
Display it on the screen.
Output its file data to stdout.

You may not use libraries or builtins that generate barcodes (I'm looking at you, Mathematica), although you may use image or graphics libraries.
The last digit of a UPC is usually a check digit, but for these purposes you don't have to worry about it.

Examples
Here are some more examples to test your code with. The binary output is also given for convenience.
Input: 012345678910
Output:

10100011010011001001001101111010100011011000101010101000010001001001000111010011001101110010101

Input: 777777222222
Output:

10101110110111011011101101110110111011011101101010110110011011001101100110110011011001101100101

Scoring
This is code golf, so the shortest submission (in bytes wins). Tiebreaker goes to the earliest post.

Mmm... juicy fruit.

Can the input be taken in as an array? e.g. ["777777","222222"]

@vihan Hmm, I think that's a bit of a stretch. I'm going to say no.

First scanned UPC barcode ever!

@Dennis Yes, that's it!

This is brilliant. Barcodes have always fascinated me

Came here to provide the Mathematica solution, was disappointed to see it had been specifically disallowed. Sigh.

CJam, 58 57 bytes
'P1N95S30N[A1r:~"rflB\NPDHt":i2fbf=:R6<::!0AAR6>A1]s30*S*

Prints a Portable BitMap (ASCII) to STDOUT. Try it online.
How it works
'P1N95S30N     e# Push 'P', 1, '\n', 95, ' ', 30 and '\n'.

[              e#
  A1           e#   Push 10 and 1.
  r            e#   Read a token from STDIN.
  :~           e#   Caluate each character ('0' -> 0).
  "rflB\NPDHt" e#   Push that string.
  :i           e#   Cast each character to integer.
               e#   This pushes [114 102 108 66 92 78 80 68 72 116].
  2fb          e#   Convert each integer to base 2.
               e#   This pushes the representations for the right side.
  f=           e#   Select the proper representation of each digit in the input.
  :R           e#   Save the result in R.
  6<           e#   Keep the representations of the first six digits.
  ::!          e#   Negate each binary digit to obtain the "left" representation.
  0AA          e#   Push 0, 10, 10.
  R6>          e#   Push the representations of the last six digits.
  A1           e#   Push 10, 1.
]s             e# Collect in an array and cast to string.

30*            e# Repeat the resulting string 30 times.
S*             e# Join it, using spaces as separators.

Rev 1 BBC BASIC, 155 ascii chars, tokenised filesize 132 bytes
INPUTn$
FORi=91TO185p=i MOD2j=i MOD47IFj<42j+=i DIV141*42p=(j>41EORASC(MID$("XLd^bFznvh",VAL(MID$(n$,j/7+1,1))+1)))>>(j MOD7)AND1
IFp LINEi*2,60,i*2,0
NEXT

saved a few bytes by incorporating the offset of 43 into the i loop. In order to avoid breaking the MOD2 an additional 47 had to be added for a total of 90.
This moves the barcode further from the origin, as shown, if that is acceptable:

Rev 0 BBC BASIC, 157 ascii chars, tokenised filesize 137 bytes
INPUTn$
FORi=1TO95p=i MOD2j=(i+43)MOD47IFj<42j+=i DIV51*42p=(i>50EORASC(MID$("XLd^bFznvh",VAL(MID$(n$,j/7+1,1))+1)))>>(j MOD7)AND1
IFp LINEi*2,0,i*2,60
NEXT

Download interpreter at http://www.bbcbasic.co.uk/bbcwin/bbcwin.html
The default screen mode is black text on a white background. This differs from original BBC BASC.
Ungolfed version with test printing
Calculation of a data bar depends on IF j<42 and must all be done on one line. In the ungolfed version it is done in three steps. In the golfed version the last two steps are combined into a single huge expression p=...
I had to reverse the order of the bitmaps, because I use >>(j MOD 7) to access the bits, which means I access the least significant bit first. Once this is done, all the left bitmaps are conveniently in the ASCII range.
  INPUTn$
  FOR i=1TO95                            :REM iterate through 95 bars
    p=i MOD2                             :REM calculate colour of format bar 1=black
    j=(i+43)MOD47                        :REM repetition is 42 data bars + 5 format bars. offset and modulo. if j<42 it is a data bar and we must change p.

    REM if i DIV 51=1 we are in the second half, so add 42 to j. Find the bitmap for left hand value, from character j/7 of the input.
    REM i>50 evaluates to false=0 true=-1. XOR this with p to invert bitmap for right hand side. Shift and AND with 1.
    IF j<42 j+=i DIV51*42:p=ASC(MID$("XLd^bFznvh",  VAL(MID$(n$,j/7+1,1))+1  )) :p=(i>50EORp)>>(j MOD7) AND 1

    IF j MOD 7 = 0 PRINT                  :REM format test output
    PRINT ;p;                             :REM print test output
    IF p LINEi*2-2,0,i*2-2,60             :REM if p=1 plot bar. there are 2 logical units for each pixel.
  NEXT

Typical output, ungolfed version, with test output

JavaScript ES6, 225 bytes
s=>`P1
30 90
`+([...`101${(f=(z,j)=>[...j].map(i=>`000${z[+i].toString(2)}`.slice(-7)).join``)([13,25,19,61,35,49,47,59,55,11],s[0])}01010${f([114,102,108,66,92,78,80,68,72,116],s[1])}101`].join` `+`
`).repeat(30).slice(0,-1)

Could of been shorter with ES7 features but I'm not sure about their support so I'm sticking with ES6. I'm also assuming an input as an array. The output is a PBN file. There is also lots of golfing to do.
If I did anything wrong leave a comment and I'll be sure to fix it

I think you mean PBM file...

Perl, 153 bytes
substr($_=<>,6,0)=A;y/0-9A/=ICmSa_kg;0/;$s.=sprintf("%07b",-48+ord$1^($k++>6?127:0))while/(.)/g;$s=~s/0{7}/01010/;print"P1
95 30
".('101'.$s.'101'.$/)x30

Copy to a file barcode.perl and then run like this:
perl barcode.perl > output.pbm

then input the barcode number.
Explanation:
The bit patterns for the barcode digits are stored in a string and substituted for the input digits using the Perl y/// transliteration operator. Each value in the substitution string has 48 (ASCII '0') added from it, to avoid unprintable characters. Digits in the second half of the barcode are inverses of those in the first half.
The central pattern is set to 0000000 (a pattern that can otherwise never appear, encoded as 'A' and then '0') and then substituted with 01010 rather than handling its different length as a special case when sprinting.

Cobra - 218
do(s='')
    print'P1\n95 30'+('\n'+('101'+(for n in 12get Convert.toString(if((t=139+[2,14,8,50,24,38,36,48,44,0][s[n]to int-48])and n<6,t,~t),2)[-7:]+if(n-5,'','01010')).join('')+'101').toCharArray.join(' ')).repeat(30)

Javascript ES6, 199 bytes
n=>`P1 95 30 `+(101+(g=(a,...s)=>(``+1e12+n).slice(...s,-6).split``.map(m=>(1e3+a[m].toString(2)).slice(-7)).join``)(a=[13,25,19,61,35,49,47,59,55,11],-12)+`01010`+g(a.map(i=>~i&127))+101).repeat(30)

"the shortest submission (in bytes wins)". You need to count your code in bytes, so if using Unicode, that's 2 bytes per character, I think.

Bah, yea, I guess my un-unicoded answer is shorter then

Octave, 115 bytes
function b(s)
n='rflB\MPDHt'-0;r=dec2bin(n(s-47)',7)'(:)-48;v=[a=[1 0 1] ~r(1:42)' 0 a r(43:84)' a];v(ones(30,1),:)

Multi-line version:
function b(s)
   n='rflB\MPDHt'-0;
   r=dec2bin(n(s-47)',7)'(:)-48;
   v=[a=[1 0 1] ~r(1:42)' 0 a r(43:84)' a];
   v(ones(30,1),:)

n is the ASCII equivalent of the right-side digit codes (they were easier to enter than the left side as they were all displayable characters). After that, a straight decimal-to-binary conversion with some annoying type changes from char to numeric. v builds the final binary string and then we repeat it 30 times and output to console.
Sample output with only 2 of the 30 rows shown for brevity:
s = '777777222222';
ans =

 Columns 1 through 30:

   1   0   1   0   1   1   1   0   1   1   0   1   1   1   0   1   1   0   1   1   1   0   1   1   0   1   1   1   0   1
   1   0   1   0   1   1   1   0   1   1   0   1   1   1   0   1   1   0   1   1   1   0   1   1   0   1   1   1   0   1
...

 Columns 31 through 60:

   1   0   1   1   1   0   1   1   0   1   1   1   0   1   1   0   1   0   1   1   1   0   1   1   0   0   1   1   0   1
   1   0   1   1   1   0   1   1   0   1   1   1   0   1   1   0   1   0   1   1   1   0   1   1   0   0   1   1   0   1
...

 Columns 61 through 90:

   1   0   0   1   1   0   1   1   0   0   1   1   0   1   1   0   0   1   1   0   1   1   0   0   1   1   0   1   1   0
   1   0   0   1   1   0   1   1   0   0   1   1   0   1   1   0   0   1   1   0   1   1   0   0   1   1   0   1   1   0
...

 Columns 91 through 94:

   0   1   0   1
   0   1   0   1
...

Compressed output:
1010111011011101101110110111011011101101110110101110110011011001101100110110011011001101100101

I had originally intended to display the image, but sending output to the console saved me 9 bytes. You can display the results using imshow, but it displays 1 as white and 0 as black, so you have to invert the data first.
imshow(~v(ones(30,1),:));

Python 2, 174 bytes
I know it can be golfed.
The string s is the binary table in the question with the left half of the table as the left half of the string. The values are ANDed by 63 first if in the right half (remove first 1), then shifted by 63 to be printable ASCII.
BUG: Currently trying to fix a bug. The output of the first example is off by one digit of the barcode. If you figure it out, let me know please.
I=raw_input()
s="LXR|bpnzvJcekA[MOCGs"
x="".join(format(ord(s[int(I[i])+10*(i>5)])-63|1+63*(i>5),'07b')for i in range(len(I)))
L=len(x)/2
print"101%s01010%s101"%(x[:L],x[L:])

Or, I made have done the challenge completely wrong. Let me know in that case too.