text:
The Partition Problem - Sorting Stacks of Boxes
Just last night I was reading a book which had a chapter on the Partition Problem; the Partition Problem is basically about splitting a set of numbers into two smaller sets of equal size.
To visualize it, the book contained the following picture:

It shows how, given an input of k boxes, each with height n, you can create two stacks of boxes, each stack with half the height of the original stack (well, in this diagram, pile.)
If you were to write a function to do this, it might look something like:
>>> k = [3,4,3,1,2,3,3,2,1]
[3,4,3,1,2,3,3,2,1]

>>> partitionSolve(k)
[ [3,3,2,3], [1,4,2,3,1] ]

>>> sum(partitionSolve(k)[0]) == sum(partitionSolve(k)[1])
True

But this only solves for two stacks! What if we wanted to split the input into three equal stacks? Then we'd have to write another function!
>>> partitionSolveThree([3,4,3,1,2,3,3,2])
[ [3,4], [3,1,3], [2,3,2] ]

In fact, I want to be able to solve for N stacks:
>>> partitionSolveN(3, [2,1,1,2,3,1,2])
[ [2,2], [1,1,2], [3,1] ]

>>> partitionSolveN(4, [2,1,1,2,3,1,2])
[ [2,1], [1,2], [3], [1,2] ]

But, I'm lazy, and I don't want to have to start some language's shell every time I want to use this function, so I decide to create a program to do it for me.
The problem is, I can't figure out an efficient way to do it!
Your Task
Design a program which can solve the above problem, for any number N.
Your program should take input via stdin, and print its output to stdout.
Example:
C:\> echo 2343123321| solution.X
3323
14231

Input will be a single string of digits; the first specifying how many stacks the code should be broken into, and the rest represent the input stack. All numbers will be single digit, so you can think of it as a list delimited by empty strings ('').
The first character of input will be the N to solve for, so if the first character is a 6 your program will be expected to output 6 valid subsets, or an error. This number will always be between 1 and 9.
The rest of the input is the starting list, from which the sublists must be created. Each digit in here can be between 1 and 9, and they must all be used once and only once in the outputted sublists.
Output should then be a new-line delimited list of your output stacks, each stack should just be a sequence of the numbers within it.
Another few examples:
C:\> echo 334323321| solution.X
34
313
232

C:\> echo 3912743471352| solution.X
121372
97
4453

C:\> echo 92| solution.X
forty-two

If the given input has no solution, your program can print any error message it wants, as long as there are no digits in the error message.
Fewest number of bytes wins! Good luck!

Is it acceptable to not print anything at all if there's no solution?

@Zgarb Yes, but I really hope people put some thought into coming up with hilarious error messages. Upvoted your question for others to see.

This problem is NP-complete. You are not going to see algorithms that are faster than brute force.

@FUZxxl Why do you keep saying this? NP-complete means there are no polynomial time solutions, but doesn't exclude algorithms faster than brute force in general.

@FUZxxl Also, since the boxes are of size 1-9, I'm not even sure it's NP complete.

@orlp These are valid points.

How are we supposed to find out what N to solve for? Is it the first digit in the input? Does that mean that N is 1-9?

@orlp Yes. It is the first input digit, between 1-9. Thanks for your valid points FUZxxl's FUZzy logic (<- see what I did there? Hee hee).

@orlp the boxes are of size 0-9

@theonlygusti Please disallow boxes of size 0. It just adds more tedious code while not complicating the problem in any interesting way.

@orlp I think it complicates the code; the program must be smart enough to know that boxes of 0 have no sum, and can just be dumped anywhere. It adds barely any code.

@theonlygusti But it's entirely trivial. It doesn't add complexity, only annoyance.

I don't even know what a "size zero" box is. If we're pretending these are actual boxes, it doesn't make much sense.

@Geobits OK, seems like others agree. No 0 handling is required.

@orlp ^^ No zero handling required.

The second example doesn't seem correct. There are 3 3 in the output, but only 2 of them in the input (once you exclude the first character, since it's the output count). This answer does the same, but your other examples don't. Clarification?

@Geobits well spotted; fixed! As for the answer, that shouldn't be happening.

Out of curiosity, in which book did you read about it?

@hetzi The New Turing Omnibus - really, I don't find it to be written brilliantly, but the ideas within do interest me.

Python 2, 321 317 321 319
import itertools as l
t=raw_input();e=0;g=l.permutations(int(k)for k in t[1:])
try:
 while not e:
  a=list(g.next());c=[sum(a[:i+1])for i in range(len(a))];s=c[-1];d=int(t[0]);f=s/d;assert f*d==s;r=range(f,s,f);e=set(r)<=set(c);b=[`k`for k in a]
 for k in r[::-1]:b.insert(c.index(k)+1,'\n')
 print ''.join(b)
except:''

Some examples:
echo 43 | python part.py

echo 3912743471352 | python part.py
9124
7342
7135

echo 342137586 | python part.py
426
138
75

Thanks to theonlygusti for fixing the stdin input, and shaving off some chars and to Maltysen for pointing out a typo.

Great! It works manually, but for my bulk tester the input needs to be taken from STDIN; if you replace t=sys.argv[1] with t=raw_input() it will then work properly, and also save a few bytes along the way; I think you can knock off that import sys.

Why does the second example have 3 3's in the output, but only two in the input?

Oh I thought the 3 upfront should also be part of the solution. Guess there are some adjustments to make

But then why doesn't it happen in your other solutions?

Should be ok now

Yep! Looks good.

Why is there t=t=?

I think you can save a character with from itertools import* and then getting rid of l. everywhere.

Pyth - 73 69 bytes
Updated to match Pyth 4.0
Yay! Finally translated it. Likely huge room for golfing., but will be working on explanation. Finished explanation.
KmsdzJ.(KZFN*.pK.cUKtJ=km?:hNhdedgedZ>hNhdC,+]ZeN+eN]_1Iql{msdk1kB)EG

Uses brute force solution with a lot of help from itertools. Not really looking to golf any further because will be translating to Pyth.
from itertools import*
K=list(map(int,input()))
J=K.pop(0)
for N in product(permutations(K),combinations(range(len(K)),J-1)):
    k=[N[0][s:e]if e>=0 else N[0][s:]for s,e in zip((0,)+N[1],N[1]+(-1,))]
    d=list(map(sum,k))
    if d.count(d[0])==J:print(k);break
else:print()

It takes cartesian product to make all possible options of arrangements of input (uses perms) and all possible slices (uses combs). Then it checks and breaks on the first one and then prints.
K               K=
 m              Map
  sd            Convert to integer
  z             Over the input
J               J=
 .(             Pop from index
  K             K
  Z             Index zero
FN              For N in
 *              Cartesian Product
  .p            Permutations full length
   K            K
  .c            Combinations no replace
   UK           Of range(len(K))
   tJ           Length J-1
 =k             Set k=
  m             Map with d as loop var
   ?    gedZ    If d>=0 (hack to get around Pyth has no None slice index)
    :hN         Slice N[0]
     hd         From k[0]
     ed         Till k[-1]
    >hN         Else slice N[0]
     hd         From k[0] till end
   C,           Zip (This makes the partitioning index pairs)
    +]ZeN       [0]+N[-1]
    +en]_1      N[-1]+[-1] (Again, the -1 is for the hack)
  Iql{    1     If the set has len 1
      msdk      Map sum to k
   k            Implicitly print k
   B            Break and implicitly close out if
 )              Close out for loop
E               If we didn't break (Uses for-else construct in Python)
 G              Print alphabet as error message

Works on all the inputs, except it froze my computer on the really big one but should in theory.
Note: does not work on the online interpreter because it has a timeout.
Now the set thing give both a speed and bytes improvement so you can run it online: Try it here.

Just thought you should know - I'm making a change to Pyth that will break most past programs, including this one. Lambda parameters will only increment if the function is nested. It should be easy to update this, though. I think you only need to update the variables for m.

K, that seems like a good idea, ill update my most recent answers and all unaccepted ones if I find the time.

Your code does not give a correct answer for for instance 3121231223

@willem I don't think 3121231223 has a solution. It sums to 17 which is not divisible by3 .

Ok, is this Python 3? In my case I had trouble with the n,*L= and it still prints the last k from the loop when there should be no number output in that case

@willem ah, yes sorry the python code is wrong (the Pyth is correct though), i'll update it. And yes, the extended unpacking is from python3.

Could the end if/else be turned into a ternary? Also this produces no output for 3343233211

@aks. 343233211 sums to 22 which is not divisible by 3. I'll look into the ternary.

@aks. I don't think so. It is actually not an if-else but a for-else: https://docs.python.org/2/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops

But the code is still supposed to output something if there is no solution. At least for the online interpreter, it doesn't do that with 343233211, it just waits and waits. And ah, I only read the Pyth, and didn't see that it was a for-else.

@aks. Like a bunch of the others it prints a blank line. I could make it print a few other preinitialized vars for the same size, though.

Oh, maybe I just didn't wait long enough? How long did it take? I waited for a couple minutes.

@aks. Yeah, this is completely brute force. There are multiple solutions usually, and it finds a hit pretty quick. But ones without hits keep on brute-forcing. But it should theoretically work.

Mathematica 154
f@n_:=Module[{g=IntegerDigits@n,d,a,r,s},d=First@g;a=Rest@g;
FirstCase[Subsets[Cases[Subsets@a,x_/;Tr@x==Tr@a/d],{d}],x_/;Sort[Join@@x]==Sort@a]];
f@Input[]

Standard input is entered by
f@Input[]

Examples with predetermined inputs:
f[334323321]

{{3, 4}, {3, 3, 1}, {3, 2, 2}}

f[3912743471352]

{{9, 7}, {7, 4, 5}, {1, 2, 4, 3, 1, 3, 2}}

f[342137586]

{{4, 8}, {7, 5}, {2, 1, 3, 6}}

f[42112312]

{{3}, {2, 1}, {2, 1}, {2, 1}}

Pyth, 72 Bytes
Such a close byte count to the other Pyth, but a completely different approach.
KmvdzJ.(K0=H/sKJ=KSK=JlKWK=NK=G])Fd_NIgHs+dGaG.(KxKdIqHsGaYGB;?YqJsmldYb

Try it here.
It is roughly equal to the following program, which was made through rethinking and slimming down my last answer (my last program didn't guarantee an answer):
Python 2, 242 Bytes
x=list(map(int,raw_input()))
y,S,b=x.pop(0),sum,[]
x.sort(reverse=1)
j,z,c=S(x)/y,len(x),0
while x:
 k,a=x[:],[]
 for i in k:
  if j>=S(a)+i:a.append(x.pop(x.index(i)))
 if S(a)==j:b.append(a);c+=len(a)
if c==z:
 for o in b:print o
else:print

Basic idea for solving without using permutations

Each stack must add up to k = sum of all boxes / n
When the list of all boxes is sorted from greatest to least, you can iterate over that list, adding/popping boxes to a stack so that k >= stack remains true. Once stack == k, that stack is 'finished' and can be added to a list of the solutions. It is clear why this works when you examine the solution it produces:
input: 3912643473522
output: [[9, 7], [6, 5, 4, 1], [4, 3, 3, 2, 2, 2]]

At the end, check if # of boxes in all solution stacks == length of input - 1 to see if all boxes were used, if not the input has no solution.

The Python is incorrect: Try it online!. (The Pyth answer doesn't work in the versions of Pyth I tried, but as it uses the same algorithm I assume it's incorrect too.) The issue is that your algorithm sometimes sorts an answer onto the wrong stack and then cannot move it.

05AB1E, 11 bytes
ć.Œʒ€SOË}н»

Try it online or verify all test cases.
Explanation:
ć            # Extract the head of the (implicit) input;
             # pushing remainder and head separately to the stack
             #  i.e. 2341 → 341 and 2
 .Œ          # Get all possible combinations of head amount of parts from the remainder
             #  → [[341,""],[34,1],[31,4],[3,41],[41,3],[4,31],[1,34],["",341]]
   ʒ         # Filter this list of parts by:
    €S       #  Convert the two parts to lists of digits
             #   i.e. [341,""] → [[3,4,1],[]]
             #   i.e. [31,4] → [[3,1],[4]]
      O      #  Take the sum of each digit-list
             #   → [8,0]
             #   → [4,4]
       Ë     #  Check if both are equal
             #   → 0 (falsey)
             #   → 1 (truthy)
        }н   # After the filter: leave the first result
             #  i.e. [[31,4],[4,31]] → [31,4]
          »  # Join it by newlines (which is output implicitly as result)
             #  → "31\n4"

If a list was allowed as output, it could have been 9 bytes instead:
ć.Œ.Δ€SOË

Try it online or verify all test cases.
Where the .Δ is a builtin for find_first, (which could have been used in the original 11-byter as well for the same byte-count, but filter ʒ with leave first н apparently is slightly faster for the given test cases).

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


text:
Compare array of decimal sum of Integers and exact fractional part
Develop a program which takes two arrays of decimal numbers, and compare the sum of whole numbers only and the decimal part. If the sums of the whole numbers are the same, and the decimal parts of Array a are a subset of the decimal parts of Array b, return True. Otherwise, return False.
Example-1 :-
Array a ={2.5,3.0,1.3}
Array b = {5.0,1.0,0.5,0.3}
Sum of whole numbers: Array a = 2+3+1 = 6 and Array b = 5+1 =6 --Matched
Individual fraction part: Array a = 2.5 = 0.5 and Array b = 0.5--Matched
Individual fraction part: Array a = 1.3 = 0.3 and Array b = 0.3--Matched
All the above are matched, so it returns true.
Example-2 :-
Array a ={1.7,2.3}
Array b = {1.2,0.5,2.3}
Sum of the whole numbers: Array a = 2+1 = 3 and Array b = 2+1 =3 --Matched
Individual fraction part: Array a = 1.7 = 0.7 and Array b = 0.2 or .5 or .3 --No Exact match
Individual fraction part: Array a = 2.3 = 0.3 and Array b = 2.3 = 0.3 -Matched
One of the conditions is not matched, so it returns false.

What is the winning criterion? Is it code golf?

Yes its code-golf forgot to add it

Well, add the [tag:code-golf] tag then.

I'm a little confused, can you clarify what you mean?

@ASCIIThenANSI sum(floor(a))==sum(floor(b)) and filter_nonzeros(fraction_part(a))==some_permutation(filter_nonzeros(fraction_part(b))) has to be true if I'm correct. @andyra42 Is this correct?

@randomra OK, I interpreted it a little further, and I think it means 'return true if the sum of just the whole numbers and the sum of the decimal parts in a are the same as b. I'm suggesting this as an edit, to clarify.

@randomra My edit is found here.

@ASCIIThenANSI I don't think you're supposed to sum the decimal parts. I think the sum of the integer parts needs to be equal, and the set of fractional parts of a needs to be a subset of the fractional parts of b.

@orip No, I said that, but it needs to be cleaned up a little. On the bright side, we have our first answer.

Please use the sandbox for proposed challenges before posting here: http://meta.codegolf.stackexchange.com/questions/2140/sandbox-for-proposed-challenges

JavaScript, 63 bytes
(a,b)=>a.reduce((s,n)=>s+~~(n),0)===b.reduce((s,n)=>s+~~(n),0);

Test it

const x=(a,b)=>a.reduce((s,n)=>s+~~(n),0)===b.reduce((s,n)=>s+~~(n),0);

const A = [2.5, 3.0, 1.3];
const B = [5.0, 1.0, 0.5, 0.3];

console.log(x(A,B)); // true

Welcome to Code Golf, and nice answer!

Mathematica 88 81
This should be easy to beat.
I was surprised that Rationalize was needed.
r=Rationalize;f=Floor;
(Tr[f@#]==Tr[f@#2] && Complement[r@Mod[#2,1],r@Mod[#, 1]]=={})&

(Tr[f@#]==Tr[f@#2] && Complement[r@Mod[#2,1],r@Mod[#, 1]]=={})&
@@ {{2.5, 3.0, 1.3}, {5.0, 1.0,0.5, 0.3}}

True

(Tr[f@#]==Tr[f@#2] && Complement[r@Mod[#2,1],r@Mod[#, 1]]=={})& @@
{{1.7, 2.3}, {1.2, 0.5, 2.3}}

False

You can shorten the FractionalPart by using Mod[n,1].

@LegionMammal978  You're right!  Thanks.

I think you can save some bytes with Infix and Prefix syntax: (Tr@f@#==Tr@f@#2&&r@Mod[#2,1]~Complement~r@Mod[#,1]=={})&

Python, 45 bytes
x=lambda a,b:sum(map(int,a))==sum(map(int,b))

Try it online!

Please put your code in a code block by surrounding it with three backticks on each end.

Also, anonymous function submissions are allowed, so you can remove the x= part to decrease your byte score by 2.

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:
Write an URL compressor
Today your goal is to invent URL compression. You must write two programs: a compressor and a decompressor.

The compressor will be called with one URL on stdin and its output will be read on stdout.
The decompressor will be called with the output of the compressor on stdin, and must produce the exact URL passed into the compressor to stdout.
The sum of the size in bytes of the compressor and decompressor source may be at most 1024 bytes.
Your answer must come with command line instructions to run your two programs. You're not allowed to pass in information of any kind through command line arguments - they should merely be to run the program.

The standard loopholes are not allowed. Additionally, your program is not allowed to keep and use any state of any kind between executions, not in files, environment variables, etc. Lastly, you may not use any built-in data compression routines if your language has them.
Scoring
I have taken all URLs found in the StackExchange dump of PPCG and collected them in one file, one URL per line. Your score will be the sum of the size of all compressed URLs in that file. Lowest score wins.

It is not guaranteed that your program is called with a valid URL. Your program must work for every input found in the test file, but doesn't have to work for any other input.
Your answer only has to work for the given URLs, and only has to optimize for those.

If the compressor is also the decompressor, is its size limit 512 or 1024 bytes?

@Dennis 512 bytes. You will have to give two programs, a compressor and a decompressor, even if they're identical.

The sentences in the last paragraph seem to contradict each other: everything in the test file seems to be a valid URL.

@NinjaBearMonkey That's not a contradiction, just coincidence. I did not check the file. It might very well only contain URLs, but if it contains something that's not an URL you should still be able to handle it.

I think there is a little contradiction with kolmogorov-complexity and the loopholes: The loopholes state that you cannot optimize your code for the test cases. This means we cannot just replace e.g. 'codegolf.stackexchange.com/', which would be a nice thing to have for a kolmogorov complexity challenge. Can you give us more detail on what the rules are relating to that?

@flawr I think in general kolmogorov-complexity explicitly encourages to optimize for the test case(s), so that it overrides the standard rules.  I'll edit into my question more explicitly that you have to optimize only for the test cases.

Various compression software on my computer cannot compress it any further than 126k, so I'm really eager to see if anyone can get less than that.

@orlp: You should change the clause to: You may assume that the input is always valid and can be found in the dump file. It's less confusing that way.

@sanchises: That's a rather unfair comparison. Call those utilities on individual URLs and they'll be totally useless.

@Dennis I know; I figured it would be nice to share what I think will probably a lower bound on our answers, and who knows? I've been surprised on PCG before... (perhaps some extreme code-golfing will allow one of the programs to include a large dictionary?)

Why there are so many http://cjam.aditsu.net?

CJam 308954 268306 bytes
Compressor (511 bytes)
0000000: 22 2f 25 2d 30 31 32 33 35 61 65 0a 2e 34 37 38  "/%-01235ae..478
0000010: 39 62 63 66 67 69 6c 6d 70 73 74 75 0a 36 41 42  9bcfgilmpstu.6AB
0000020: 43 44 45 46 49 4a 4b 4c 4d 53 58 5f 64 68 6a 6b  CDEFIJKLMSX_dhjk
0000030: 6e 6f 72 76 77 78 79 7a 97 a0 a5 a6 22 0a 4e 2f  norvwxyz....".N/
0000040: 5f 3a 2b 32 35 36 63 2c 5e 61 2b 3a 47 3b 22 63  _:+256c,^a+:G;"c
0000050: 6f 7f 6d 73 74 6e 67 6f 6c 6f 72 64 65 7f 85 83  o.mstngolorde...
0000060: 66 67 87 86 88 81 61 8a 63 8b 6b 61 82 80 2f 2e  fg....a.c.ka../.
0000070: 8e 65 8f 8d 90 68 91 63 92 78 93 65 94 8c 95 65  .e...h.c.x.e...e
0000080: 72 6f 6e 84 67 77 69 9a 6b 9b 69 74 68 96 61 69  ron.gwi.k.ith.ai
0000090: 98 69 6e 65 74 6e a1 65 6e 64 69 25 32 a5 30 a6  .inetn.endi%2.0.
00000a0: a6 77 77 a8 77 6c 65 72 65 2e 99 ac 2f ad 9c 9f  .ww.wlere.../...
00000b0: 73 81 af 89 2e b1 9e b1 96 65 a4 70 b4 9c b5 72  s........e.p...r
00000c0: 69 a5 42 b7 70 b9 74 62 8f b6 61 bc ae 61 72 b2  i.B.p.tb..a..ar.
00000d0: 2f 61 74 6c 6f 61 6d 74 6d 68 c3 c4 6c 65 b0 75  /atloamtmh..le.u
00000e0: c6 71 c7 b3 c8 63 ba 73 ca 88 cb 72 6f 61 6e 69  .q...c.s...roani
00000f0: 9d cf 75 d0 bb 67 d1 65 73 75 73 d4 97 b3 d5 6a  ..u..g.esus....j
0000100: c2 63 d7 c1 77 d9 8f 70 68 db bb 70 dc 73 75 74  .c..w..ph..p.sut
0000110: de a4 df 61 e0 98 90 85 e2 69 e3 d3 83 e5 8d a9  ...a.....i......
0000120: 2e 61 dd 76 97 6f e9 8c ea eb 66 ec da 6a 73 ee  .a.v.o....f..js.
0000130: 66 ef 69 f0 64 f1 64 f2 aa 70 cd a2 2f 2e f5 f3  f.i.d.d..p../...
0000140: f6 e1 f6 e6 73 f9 ae 61 6c 75 6e bf 34 70 79 fe  ....s..alun.4py.
0000150: 9d 63 74 fc 00 b8 b8 75 72 03 8f a5 43 64 6f 06  .ct....ur...Cdo.
0000160: 63 d6 73 ed c8 a7 a7 b8 a6 a6 a5 69 73 72 c2 75  c.s........isr.u
0000170: 74 69 82 bd 2f 2e 11 a3 12 67 49 14 43 15 41 16  ti../....gI.C.A.
0000180: 16 a3 74 07 73 72 fc d2 0d 69 74 2e c5 63 68 61  ..t.sr...it..cha
0000190: 73 e8 3f 20 63 5c 22 3d be 1e 6f 03 69 aa a5 39  s.? c\"=..o.i..9
00001a0: 60 a5 6f 66 22 32 2f 31 32 39 2c 31 32 37 66 2b  `.of"2/129,127f+
00001b0: 33 33 2c 2b 3a 63 22 5c 22 3c 3e 5c 5e 60 7b 7d  33,+:c"\"<>\^`{}
00001c0: 22 2b 6c 5f 34 3d 27 73 3d 3a 4c 37 2b 3e 40 7b  "+l_4='s=:L7+>@{
00001d0: 2f 5c 28 40 5c 2a 7d 2f 30 5c 7b 47 7b 31 24 23  /\(@\*}/0\{G{1$#
00001e0: 29 7d 23 5f 47 3d 3a 54 40 23 40 54 2c 2a 2b 34  )}#_G=:T@#@T,*+4
00001f0: 2a 2b 7d 2f 32 2a 4c 2b 32 35 36 62 3a 63 0a     *+}/2*L+256b:c.

Decompressor (510 bytes)
0000000: 22 2f 25 2d 30 31 32 33 35 61 65 0a 2e 34 37 38  "/%-01235ae..478
0000010: 39 62 63 66 67 69 6c 6d 70 73 74 75 0a 36 41 42  9bcfgilmpstu.6AB
0000020: 43 44 45 46 49 4a 4b 4c 4d 53 58 5f 64 68 6a 6b  CDEFIJKLMSX_dhjk
0000030: 6e 6f 72 76 77 78 79 7a 97 a0 a5 a6 22 0a 4e 2f  norvwxyz....".N/
0000040: 5f 3a 2b 32 35 36 63 2c 5e 61 2b 3a 47 3b 22 63  _:+256c,^a+:G;"c
0000050: 6f 7f 6d 73 74 6e 67 6f 6c 6f 72 64 65 7f 85 83  o.mstngolorde...
0000060: 66 67 87 86 88 81 61 8a 63 8b 6b 61 82 80 2f 2e  fg....a.c.ka../.
0000070: 8e 65 8f 8d 90 68 91 63 92 78 93 65 94 8c 95 65  .e...h.c.x.e...e
0000080: 72 6f 6e 84 67 77 69 9a 6b 9b 69 74 68 96 61 69  ron.gwi.k.ith.ai
0000090: 98 69 6e 65 74 6e a1 65 6e 64 69 25 32 a5 30 a6  .inetn.endi%2.0.
00000a0: a6 77 77 a8 77 6c 65 72 65 2e 99 ac 2f ad 9c 9f  .ww.wlere.../...
00000b0: 73 81 af 89 2e b1 9e b1 96 65 a4 70 b4 9c b5 72  s........e.p...r
00000c0: 69 a5 42 b7 70 b9 74 62 8f b6 61 bc ae 61 72 b2  i.B.p.tb..a..ar.
00000d0: 2f 61 74 6c 6f 61 6d 74 6d 68 c3 c4 6c 65 b0 75  /atloamtmh..le.u
00000e0: c6 71 c7 b3 c8 63 ba 73 ca 88 cb 72 6f 61 6e 69  .q...c.s...roani
00000f0: 9d cf 75 d0 bb 67 d1 65 73 75 73 d4 97 b3 d5 6a  ..u..g.esus....j
0000100: c2 63 d7 c1 77 d9 8f 70 68 db bb 70 dc 73 75 74  .c..w..ph..p.sut
0000110: de a4 df 61 e0 98 90 85 e2 69 e3 d3 83 e5 8d a9  ...a.....i......
0000120: 2e 61 dd 76 97 6f e9 8c ea eb 66 ec da 6a 73 ee  .a.v.o....f..js.
0000130: 66 ef 69 f0 64 f1 64 f2 aa 70 cd a2 2f 2e f5 f3  f.i.d.d..p../...
0000140: f6 e1 f6 e6 73 f9 ae 61 6c 75 6e bf 34 70 79 fe  ....s..alun.4py.
0000150: 9d 63 74 fc 00 b8 b8 75 72 03 8f a5 43 64 6f 06  .ct....ur...Cdo.
0000160: 63 d6 73 ed c8 a7 a7 b8 a6 a6 a5 69 73 72 c2 75  c.s........isr.u
0000170: 74 69 82 bd 2f 2e 11 a3 12 67 49 14 43 15 41 16  ti../....gI.C.A.
0000180: 16 a3 74 07 73 72 fc d2 0d 69 74 2e c5 63 68 61  ..t.sr...it..cha
0000190: 73 e8 3f 20 63 5c 22 3d be 1e 6f 03 69 aa a5 39  s.? c\"=..o.i..9
00001a0: 60 a5 6f 66 22 32 2f 5b 71 32 35 36 62 32 6d 64  `.of"2/[q256b2md
00001b0: 22 68 74 74 70 22 6f 27 73 2a 6f 22 3a 2f 2f 22  "http"o's*o"://"
00001c0: 6f 7b 34 6d 64 47 3d 5f 2c 40 5c 6d 64 40 3d 5c  o{4mdG=_,@\md@=\
00001d0: 7d 68 3b 5d 57 25 31 32 39 2c 31 32 37 66 2b 33  }h;]W%129,127f+3
00001e0: 33 2c 2b 3a 63 22 5c 22 3c 3e 5c 5e 60 7b 7d 22  3,+:c"\"<>\^`{}"
00001f0: 2b 57 25 7b 2f 5c 29 40 5c 2a 7d 2f 4e 0a        +W%{/\)@\*}/N.

Algorithm

Strip the <scheme>:// part from the URL.
Replace character pairs by unused code points in the 0 - 255 range.
This uses a static dictionary which is included in the source code.
Use arithmetic encoding on the modified input string.
To comply with the source code size limit, this is done by splitting the 256 code points into 4 groups and pretending the groups and the code points in a fixed group have equal probabilities.
Append a bit indicating the scheme to the resulting integer.
Convert the integer into a string.

Test cases
Create the source code files.
$ xxd -p -r > comp.cjam <<< 222f252d303132333561650a2e3437383962636667696c6d707374750a36414243444546494a4b4c4d53585f64686a6b6e6f72767778797a97a0a5a6220a4e2f5f3a2b323536632c5e612b3a473b22636f7f6d73746e676f6c6f7264657f8583666787868881618a638b6b6182802f2e8e658f8d9068916392789365948c9565726f6e846777699a6b9b69746896616998696e65746ea1656e64692532a530a6a67777a8776c6572652e99ac2fad9c9f7381af892eb19eb19665a470b49cb57269a542b770b974628fb661bcae6172b22f61746c6f616d746d68c3c46c65b075c671c7b3c863ba73ca88cb726f616e699dcf75d0bb67d165737573d497b3d56ac263d7c177d98f7068dbbb70dc737574dea4df61e0989085e269e3d383e58da92e61dd76976fe98ceaeb66ecda6a73ee66ef69f064f164f2aa70cda22f2ef5f3f6e1f6e673f9ae616c756ebf347079fe9d6374fc00b8b87572038fa543646f0663d673edc8a7a7b8a6a6a5697372c275746982bd2f2e11a3126749144315411616a374077372fcd20d69742ec563686173e83f20635c223dbe1e6f0369aaa53960a56f6622322f3132392c313237662b33332c2b3a63225c223c3e5c5e607b7d222b6c5f343d27733d3a4c372b3e407b2f5c28405c2a7d2f305c7b477b312423297d235f473d3a54402340542c2a2b342a2b7d2f322a4c2b323536623a630a

$ xxd -p -r > decomp.cjam <<< 222f252d303132333561650a2e3437383962636667696c6d707374750a36414243444546494a4b4c4d53585f64686a6b6e6f72767778797a97a0a5a6220a4e2f5f3a2b323536632c5e612b3a473b22636f7f6d73746e676f6c6f7264657f8583666787868881618a638b6b6182802f2e8e658f8d9068916392789365948c9565726f6e846777699a6b9b69746896616998696e65746ea1656e64692532a530a6a67777a8776c6572652e99ac2fad9c9f7381af892eb19eb19665a470b49cb57269a542b770b974628fb661bcae6172b22f61746c6f616d746d68c3c46c65b075c671c7b3c863ba73ca88cb726f616e699dcf75d0bb67d165737573d497b3d56ac263d7c177d98f7068dbbb70dc737574dea4df61e0989085e269e3d383e58da92e61dd76976fe98ceaeb66ecda6a73ee66ef69f064f164f2aa70cda22f2ef5f3f6e1f6e673f9ae616c756ebf347079fe9d6374fc00b8b87572038fa543646f0663d673edc8a7a7b8a6a6a5697372c275746982bd2f2e11a3126749144315411616a374077372fcd20d69742ec563686173e83f20635c223dbe1e6f0369aaa53960a56f6622322f5b7132353662326d642268747470226f27732a6f223a2f2f226f7b346d64473d5f2c405c6d64403d5c7d683b5d57253132392c313237662b33332c2b3a63225c223c3e5c5e607b7d222b57257b2f5c29405c2a7d2f4e0a

Verify their integrity.
$ cksum comp.cjam decomp.cjam
2293013588 511 comp.cjam
1577103568 510 decomp.cjam

Download the CJam interpreter.
$ wget -q wget http://downloads.sourceforge.net/project/cjam/cjam-0.6.4/cjam-0.6.4.jar

Create an alias for running the interpreter.
$ alias cjam='java -jar cjam-0.6.4.jar'

Set encoding to ISO-8859-1 to store each character as a single byte.
$ LANG=en_US

Prepare the test file.
$ wget -q https://gist.githubusercontent.com/orlp/fd3411259469ade4c65d/raw/bb6b088c18c444d28729abc870d6076ca594a6de/urls.txt

$ echo >> urls.txt

For each line in the test file, feed the URL to the compressor, append the output to urls-comp.bin and feed it back to the decompressor. Save the combined output of all decompressions in urls-vrfy.txt. This will take a few minutes.
$ >urls-comp.bin

$ for URL in $(<urls.txt); do
> echo $URL | cjam comp.cjam | tee -a urls-comp.bin | cjam decomp.cjam
> done > urls-vrfy.txt

Verify that all URLs were decoded appropriately.
$ cksum urls.txt urls-vrfy.txt
3445245739 588562 urls.txt
3445245739 588562 urls-vrfy.txt

Compute the score.
$ wc -c urls-comp.bin
268306 urls-comp.bin

How it works
Common
Push the string containing the first three character groups.
"/%-01235ae
.4789bcfgilmpstu
6ABCDEFIJKLMSX_dhjknorvwxyz����"

Split at linefeeds, flatten a copy of the resulting array and compute the symmetric difference of the resulting string and the string of all code points.
N/_:+256c,^

Append the result to the array which now contains all four character groups. Save the result in the variable G and discard it from the stack.
a+:G;

Push the array (let's call it A) containing all character pairs to be substituted.
"comstngolorde��fg����a�c�ka��/.�e���h�c�x�e���eron�gwi�k�ith�ai�inetn�endi%2�0��ww�wlere.��/���s���.����e�p���ri�B�p�tb��a��ar�/atloamtmh��le�u�qǳ�c�sʈ�roani��uлg�esusԗ��j�c��wُphۻp�sutޤ�a���i�Ӄit.�chas�? c\"=�oi��9`�of"
2/

Push the array [ 0 ... 128 ], add 127 to each element, append the array [ 0 ... 32 ], cast to Char and append the string "\"<>\^{}". The result is the string (let's call itS`) of all unused code points from 0 to 255.
129,127f+33,+:c"\"<>\^`{}"+

Compressor
...        " Generate G. Push A and S.                                        ";
l          " Read one line from STDIN.                                        ";
_4='s=     " Check if its 5th character is an 's'.                            ";
:L7+       " Save the result in L and add it to 7.                            ";
>          " Discard that many characters from the input string.              ";
@{         " For each character pair in A:                                    ";
  /        "   Split the input string at its occurrences.                     ";
  \(@\     "   Unshift one character C from S.                                ";
  *        "   Join the split string, using C as separator.                   ";
}/         "                                                                  ";
0          " Push 0 (accumulator).                                            ";
\{         " For each character C in the input string:                        ";
  G{1$#)}# "   Retrieve the index of the group C belongs to.                  ";
  _G=:T    "   Store the group in T.                                          ";
  @#       "   Push the index of C in T.                                      ";
  @T,*+4*+ "   Multiply the accumulator by the length of T and add the index. ";
}/         "                                                                  ";
2*L+       " Multiply the accumulator by 2 and add L.                         ";
256b:c     " Convert the accumulator (BigInteger) into a byte string.         ";

Decompressor
...        " Generate G. Push A.                                              ";
[q         " Start an array and read the whole input.                         ";
256b       " Convert the byte string into an integer.                         ";
2md        " Push quotient and residue of the division by 2.                  ";
"http"o    " Print 'http'.                                                    ";
's*o       " If the residue is 1, print 's'.                                  ";
"://"o     " Print '://'.                                                     ";
{          " While the integer is non-zero:                                   ";
  4md      "   Push quotient and residue of the division by 4.                ";
  G=_,     "   Push the corresponding character group and its length.         ";
  @\md     "   Divide the integer by the length. Push quotient and residue.   ";
  @=\      "   Retrieve the char corresponding to the residue from the group. ";
}h         "                                                                  ";
]W%        " End and reverse array.                                           ";
           " Since the elements are Chars, this yields a string.              ";
...        " Push S.                                                          ";
\W%{       " For each character in S reversed:                                ";
  /        "     Split the string at its occurrences.                         ";
  \)@\     "     Pop one character pair P from A.                             ";
  *        "     Join the split string, using P as separator.                 ";
}/         "                                                                  ";
N          " Push a linefeed.                                                 ";

Remarks
Decompression will work correctly only for the http and https schemes. The reasons are twofold:

The http part is hardcoded.
The arithmetic encoding uses the fact that <http|https>:// cannot be followed by a third slash.
Since the integer 0 encodes any arbitrary run of slashes (character 0 of group 0), we would have to store the URL's length or the number of leading slashes to support, e.g., file:/// URLs.

Impressive! and i appreciate the detailed explaination

BrainFuck: 550417
Encoder:
,,,,,[.,]

Decoder:
>++++++++++[-<++++++++++>]<++++.++++++++++++..----[.,]

It needs the url without linefeed and it expects 0 as EOF.
Example:
> echo -n "http://stackoverflow.com/" | beef encode.bf
://stackoverflow.com/
> echo -n "://stackoverflow.com/" | beef decode.bf
http://stackoverflow.com/

A novel abuse. I'm not sure whether or not to applaud.

Does it work with https?

@IsmaelMiguel Yes. As required it works with all the URLs in the list. https://x.org becomes s://x.org

MATLAB, 477161
Edit: something odd is going on here. When I fed the original list through a RAR compressor, it got it down to 122Kb. When I feed my compressed list, though, it can only get it down to 222Kb. So, basically I created a compression algorithm that will make it harder for other compression algorithms to work. How about that, huh... :)
Takes the input string, strips it of the http at the start, and then compresses the string into a 7-bit representation. Appends an 'x' or 'y' for the decompressor to now whether it is dealing with a complete block or not; this could have probably been done more efficient (perhaps a parity bit) but this will have to do for now (it will only decrease my score with about 10k). I only realized halfway this was not code-golf, so you'll have to do without descriptive variable names.
function t=compress(s);
s=s(5:end);
t='';
replacable='"<>\^`{}';
for(k=replacable)
    s=strrep(s,['%' dec2hex(k)],k);
end
l=numel(s);
for(i=1:8:l-mod(l,8))
    t=[t char(bin2dec(reshape(dec2bin(s(i:i+7),7),7,8)))'];
end
if(mod(l,8))
    t=[t s(l-mod(l,8)+1:l)];
    t(end+1)='x';
else
    t(end+1)='y';
end

Decompress:
function s=decompress(t);
l=numel(t)-1;
if(t(end)=='x')
    endfor=l-mod(l,7);
    endfor(l==endfor)=l-7;
else
    endfor=l-1;
end
s='http';
for(i=1:7:endfor)
    s=[s char(bin2dec(reshape(dec2bin(t(i:i+6),8),8,7)))'];
end
if(t(end)=='x')
    s=[s t(endfor+1:end-1)];
end

replacable='"<>\^`{}';
for(k=replacable)
    s=strrep(s,k,['%' dec2hex(k)]);
end

EDIT: fixed some bugs, added some %xx replacements; other than that I'm calling it a day because I'll never get to 300k with this approach.

This question is only not code golf if your code comfortably fits <= 1024 bytes. Otherwise you'll have to start golfing ;)

It's about 500, so that was a good waste of time.

Python (413649)
Compressor:
u=input()[4:]
for i,j in zip('"<>\\^`{}\t\r\v\f','s:// :// codegolf.stackexchange.com en.wikipedia.org/wiki cjam.aditsu.net jsfiddle.net golfscript.apphb.com ideone.com github.com stackoverflow.com esolangs.org i.stack.imgur.com'.split()):
 u=u.replace(j,i)
print(u)

Decompressor:
u='http'+input()
for i,j in zip('"<>\\^`{}\t\r\v\f','s:// :// codegolf.stackexchange.com en.wikipedia.org/wiki cjam.aditsu.net jsfiddle.net golfscript.apphb.com ideone.com github.com stackoverflow.com esolangs.org i.stack.imgur.com'.split()):
 u=u.replace(i,j)
print(u)

The algorithm is very simple. The http at the beginning is stripped because it is the same in all of the test urls. It then takes the most common domain names in the test file and substitutes each for a single ascii character, out of the characters not used in any. It also substitutes :// (http) and s:// (https) for individual characters.

authors: n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳


text:
Build a minimum-clue Sudoku unsolver
My attempt at stating this question, but with a more objective solving criterion.
Your task is to build a program or function that takes a solved Sudoku grid S in the format of your choice and attempts to generate a problem grid with as few clues as possible that has S as its unique solution. (It doesn't matter what method S is the unique solution by, including brute force, as long as the solution is provably unique.)

Your program will be scored by running it through a set of 100,000 solution grids found in this file (7.82 MB download), and adding up the number of clues in all 100,000 problem grids that your solution produces.
The Sudoku solutions in the above test file are expressed as an 81-character string, from left-to-right, then top-to-bottom. The code required to turn the input in the test file into a usable solution will not count towards your solution's byte count.
As in my Flood Paint challenge, your program must actually produce a valid output for all 100,000 puzzles to be considered a valid solution. The program that outputs the fewest total clues for all 100,000 test cases is the winner, with shorter code breaking a tie.

Current scoreboard:

2,361,024 - nutki, C
2,580,210 - es1024, PHP
6,000,000 - CarpetPython, Python 2
7,200,000 - Joe Z., Python

Also, you can be sure that any solution claiming less than 1,700,000 solutions is a phony, but I want to see just how low these can go.

C++ / Tdoku - 2,081,604 clues
Below are results from running random minimization using tdoku on each puzzle N times and taking the result with the least clues. Results are shown for various N as powers of 2. No heuristics are involved at all. Each minimization just takes a random permutation of range(81) and then tries to remove clues in that order, putting a clue back whenever its removal results in multiple solutions.
Of note is the fact that the curve isn't flattening quickly and lower numbers can clearly be achieved without being any smarter just by running for larger N.
# (1) fetch tdoku
git clone https://github.com/t-dillon/tdoku.git
cd tdoku

# (2) pick your compiler (recent clang is best for tdoku):
export CC=clang-8
export CXX=clang++-8

# (3) place ppcg_sudoku_testing.txt, minimize.cc (below),
#     and run.sh (below) in the current directory

# (4) build the tdoku solver library
./BUILD.sh

# (5) build minimize.cc
$CXX -std=c++11 -O3 -march=native -o minimize minimize.cc build/libtdoku.a

# (6) run with concurrency appropriate for your system.
#     results below were run on a 32core/64thread TR-2990WX
chmod a+x run.sh
./run.sh 64
    1:    2438970  0 sec
    2:    2377595  1 sec
    4:    2329366  2 sec
    8:    2288410  3 sec
   16:    2254275  7 sec
   32:    2223342  14 sec
   64:    2195642  27 sec
  128:    2174050  55 sec
  256:    2153351  109 sec
  512:    2127972  218 sec
 1024:    2105589  436 sec
 2048:    2091738  871 sec
 4096:    2081604  1740 sec

minimize.cc:
#include "include/tdoku.h"
#include <cstdio>
#include <cstring>
#include <fstream>

int NumClues(const char *puzzle) {
    int num_clues = 0;
    for (int i = 0; i < 81; i++) {
        if (puzzle[i] != '.') num_clues++;
    }
    return num_clues;
}

int main(int argc, char **argv) {
    int limit = std::stoi(argv[1]);

    std::ifstream file;
    file.open(argv[2]);

    std::string line;
    while (getline(file, line)) {
        char puzzle[81], min_puzzle[81];
        int min_clues = 81;
        for (int j = 0; j < limit; j++) {
            memcpy(puzzle, line.c_str(), 81);
            TdokuMinimize(false, puzzle);
            int clues = NumClues(puzzle);
            if (clues <= min_clues) {
                min_clues = clues;
                memcpy(min_puzzle, puzzle, 81);
            }
        }
        printf("%.81s %d\n", min_puzzle, min_clues);
    }
}

run.sh
#!/bin/bash

concurrency=$1

killall minimize 2>/dev/null
rm -f ppcg_?? ppcg_??.done
split -n l/$concurrency ppcg_sudoku_testing.txt ppcg_

for p in {0..20}; do
    t1=$(date +%s)
    lim=$((2**p))
    for f in ppcg_??; do
    ./minimize $lim $f > $f.done &
    done
    wait
    t2=$(date +%s)
    cat *.done | awk -F' ' -v t=$((t2 - t1)) -v n=$lim '{ x += $2 } END { printf("%5d: %10d  %d sec\n",n,x,t); }'
done

C - 2,361,024 2,509,949 clues
Remove clues starting from the last cell if a brute force solver finds only one unique solution.
Second try: use heuristic to decide in which order to remove clues instead of starting from the last. This makes the code run much slower (20 minutes instead of 2 to calculate the result). I could make the solver faster, to experiment with different heuristics, but for now it will do.
#include <stdio.h>
#include <string.h>
char ll[100];
short b[81];
char m[81];
char idx[81][24];
int s;
char lg[513];
void pri2() {
    int i;
    for(i=0;i<81;i++) putchar(lg[b[i]]);
    putchar('\n');
}
void solve(pos){
int i,p;
if (s > 1) return;
if (pos == 81) { s++; return; }
if (b[pos]) return solve(pos+1);
for (p=i=0;i<24;i++) p |= b[idx[pos][i]];
for (i = 0; i < 9; i++) if (!(p&(1<<i))) {
    b[pos] = 1 << i;
    solve(pos + 1);
}
b[pos] = 0;
}
int main() {
    int i,j,t;
    for(i=0;i<9;i++) lg[1<<i]='1'+i;
    lg[0] = '.';
    for(i=0;i<81;i++) {
    t = 0;
    for(j=0;j<9;j++) if(i/9*9 + j != i) idx[i][t++] = i/9*9 + j;
    for(j=0;j<9;j++) if(i%9 + j*9 != i) idx[i][t++] = i%9 + j*9;
    for(j=0;j<81;j++) if(j/27 == i/27 && i%9/3 == j%9/3 && i!=j) idx[i][t++] = j;
    }
    while(scanf("%s ",ll)>0) {
    memset(m, 0, sizeof(m));
    for(i=0;i<81;i++) b[i] = 1 << (ll[i]-'1');
    for(i=0;i<81;i++) {
    int j,k,l = 99;
    for(k=0;k<81;k++) if (m[k] <= l) l = m[k], j = k;
    m[j] = 24;
    t = b[j]; b[j] = 0;
    s = 0; solve(0);
    if (s > 1) b[j] = t;
    else for(k=0;k<24;k++) m[idx[j][k]]++;
    }
    pri2();
    }
    return 0;
}

Python — 7,200,000 clues
As usual, here is a last-place reference solution:
def f(x): return x[:72] + "." * 9

Removing the bottom row of numbers provably leaves the puzzle solvable in all cases, as each column still has 8 of 9 numbers filled, and each number in the bottom row is simply the ninth number left over in the column.
If any serious contender manages to legally score worse than this one, I will be astonished.

I mean, you could remove just the last one.

You could also just leave the whole thing solved, but neither of those would be a serious contender.

So why is this a serious contender?

It's not. That's why I said I'd be astonished if any serious contender managed to score worse than this non-serious contender.

Python 2 - 6,000,000 clues
A simple solution that uses the 3 common methods of solving these puzzles:
def f(x):
    return ''.join('.' if i<9 or i%9==0 or (i+23)%27 in (0,3) else c
        for i,c in enumerate(x))

This function produces clue formats like this:
.........
.dddddddd
.dddddddd
.ddd.dd.d
.dddddddd
.dddddddd
.ddd.dd.d
.dddddddd
.dddddddd

This can always be solved. The 4 3x3 parts are solved first, then the 8 columns, then the 9 rows.

PHP — 2,580,210 clues
This first removes the last row and column, and bottom right corner of every box. It then tries to clear out each cell, running the board through a simple solver after each change to ensure the board is still unambiguously solvable.
Much of the code below was modified from one of my old answers. printBoard uses 0s for empty cells.

<?php
// checks each row/col/block and removes impossible candidates
function reduce($cand){
    do{
        $old = $cand;
        for($r = 0; $r < 9; ++$r){
        for($c = 0; $c < 9; ++$c){
            if(count($cand[$r][$c]) == 1){ // if filled in
                // remove values from row and col and block
                $remove = $cand[$r][$c];
                for($i = 0; $i < 9; ++$i){
                    $cand[$r][$i] = array_diff($cand[$r][$i],$remove);
                    $cand[$i][$c] = array_diff($cand[$i][$c],$remove);
                    $br = floor($r/3)*3+$i/3;
                    $bc = floor($c/3)*3+$i%3;
                    $cand[$br][$bc] = array_diff($cand[$br][$bc],$remove);
                }
                $cand[$r][$c] = $remove;
            }
        }}
    }while($old != $cand);
    return $cand;
}

// checks candidate list for completion
function done($cand){
    for($r = 0; $r < 9; ++$r){
    for($c = 0; $c < 9; ++$c){
        if(count($cand[$r][$c]) != 1)
            return false;
    }}
    return true;
}

// board format: [[1,2,0,3,..],[..],..], $b[$row][$col]
function solve($board){
    $cand = [[],[],[],[],[],[],[],[],[]];
    for($r = 0; $r < 9; ++$r){
    for($c = 0; $c < 9; ++$c){
        if($board[$r][$c]){ // if filled in
            $cand[$r][$c] = [$board[$r][$c]];
        }else{
            $cand[$r][$c] = range(1, 9);
        }
    }}
    $cand = reduce($cand);

    if(done($cand))  // goto not really necessary
        goto end;    // but it feels good to use it
    else return false;

    end:
    // back to board format
    $b = [];
    for($r = 0; $r < 9; ++$r){
        $b[$r] = [];
        for($c = 0; $c < 9; ++$c){
            if(count($cand[$r][$c]) == 1)
                $b[$r][$c] = array_pop($cand[$r][$c]);
            else
                $b[$r][$c] = 0;
        }
    }
    return $b;
}

function add_zeros($board, $ind){
    for($r = 0; $r < 9; ++$r){
    for($c = 0; $c < 9; ++$c){
        $R = ($r + (int)($ind/9)) % 9;
        $C = ($c + (int)($ind%9)) % 9;
        if($board[$R][$C]){
            $tmp = $board[$R][$C];
            $board[$R][$C] = 0;
            if(!solve($board))
                $board[$R][$C] = $tmp;
        }
    }}
    return $board;
}

function generate($board, $ind){
    // remove last row+col
    $board[8] = [0,0,0,0,0,0,0,0,0];
    foreach($board as &$j) $j[8] = 0;

    // remove bottom corner of each box
    $board[2][2] = $board[2][5] = $board[5][2] = $board[5][5] = 0;

    $board = add_zeros($board, $ind);

    return $board;
}
function countClues($board){
    $str = implode(array_map('implode', $board));
    return 81 - substr_count($str, '0');
}

function generateBoard($board){
    return generate($board, 0);
}

function printBoard($board){
    for($i = 0; $i < 9; ++$i){
        echo implode(' ', $board[$i]) . PHP_EOL;
    }
    flush();
}
function readBoard($str){
    $tmp = str_split($str, 9);
    $board = [];
    for($i = 0; $i < 9; ++$i)
        $board[] = str_split($tmp[$i], 1);
    return $board;
}
// testing
$n = 0;
$f = fopen('ppcg_sudoku_testing.txt', 'r');
while(($l = fgets($f)) !== false){
    $board = readBoard(trim($l));
    $n += countClues(generateBoard($board));
}
echo $n;


text:
Official Ruby Inspector
Here is a simple ASCII art ruby:
  ___
 /\_/\
/_/ \_\
\ \_/ /
 \/_\/

As a jeweler for the ASCII Gemstone Corporation, your job is inspect the newly acquired rubies and leave a note about any defects that you find.
Luckily, only 12 types of defects are possible, and your supplier guarantees that no ruby will have more than one defect.
The 12 defects correspond to the replacement of one of the 12 inner _, /, or \ characters of the ruby with a space character ( ). The outer perimeter of a ruby never has defects.
The defects are numbered according to which inner character has a space in its place:

So a ruby with defect 1 looks like this:
  ___
 /\_/\
/_/  _\
\ \_/ /
 \/_\/

A ruby with defect 11 looks like this:
  ___
 /\_/\
/_/ \_\
\ \_/ /
 \ _\/

It's the same idea for all other defects.
Challenge
Write a program or function that takes in the string of a single, potentially defective ruby. The defect number should be printed or returned. The defect number is 0 if there is no defect.
Take input from a text file, stdin, or a string function argument. Return the defect number or print it to stdout.
You may assume that the ruby has a trailing newline. You may not assume that it has any trailing spaces or leading newlines.
The shortest code in bytes wins. (Handy byte counter.)
Test Cases
The 13 exact types of rubies, followed directly by their expected output:
  ___
 /\_/\
/_/ \_\
\ \_/ /
 \/_\/
0
  ___
 /\_/\
/_/  _\
\ \_/ /
 \/_\/
1
  ___
 /\ /\
/_/ \_\
\ \_/ /
 \/_\/
2
  ___
 /\_/\
/_  \_\
\ \_/ /
 \/_\/
3
  ___
 /\_/\
/_/ \_\
\  _/ /
 \/_\/
4
  ___
 /\_/\
/_/ \_\
\ \ / /
 \/_\/
5
  ___
 /\_/\
/_/ \_\
\ \_  /
 \/_\/
6
  ___
 /\_/\
/_/ \ \
\ \_/ /
 \/_\/
7
  ___
 /\_ \
/_/ \_\
\ \_/ /
 \/_\/
8
  ___
 / _/\
/_/ \_\
\ \_/ /
 \/_\/
9
  ___
 /\_/\
/ / \_\
\ \_/ /
 \/_\/
10
  ___
 /\_/\
/_/ \_\
\ \_/ /
 \ _\/
11
  ___
 /\_/\
/_/ \_\
\ \_/ /
 \/_ /
12

To clarify, the ruby cannot have any trailing spaces, right ?

@Optimizer Correct

@Calvin'sHobbies May we also assume the input does not have a trailing newline?

@orlp Yes. That's the whole point of may.

The rubies are symmetrical.  So shouldn't error #7 be the same as error #10, for example?

@DavidCarraher That's really a matter of convention. So no.

CJam, 27 23 bytes
F7EC5ZV4DI8G6]qBb67%J%#

Convert base 11, take mod 67, take mod 19 of the result then find the index of what you have in the array
[15, 7, 14, 12, 5, 3, 0, 4, 13, 18, 8, 16, 6]

Magic!
Try it online.

Ruby 2.0, 69 bytes
#!ruby -Kn0rdigest
p'×ñF<ìX‚É²Ÿ_'.index Digest::MD5.digest(gets)[0]

Hexdump (to faithfully show the binary data in the string):
00000000  23 21 72 75 62 79 20 2d  4b 6e 30 72 64 69 67 65  |#!ruby -Kn0rdige|
00000010  73 74 0a 70 27 d7 f1 46  3c 1f ec 58 82 c9 b2 9f  |st.p'..F<..X....|
00000020  5f 02 27 2e 69 6e 64 65  78 20 44 69 67 65 73 74  |_.'.index Digest|
00000030  3a 3a 4d 44 35 2e 64 69  67 65 73 74 28 67 65 74  |::MD5.digest(get|
00000040  73 29 5b 30 5d                                    |s)[0]|

Explanation:

The -Kn option reads the source file as ASCII-8BIT (binary).
The -0 option allows gets to read in the whole input (and not just one line).
The -rdigest option loads the digest module, which provides Digest::MD5.
The code then does an MD5 of the input, takes the first byte of the digest, and gets its index in the given binary string.

Lucky that MD5 is unique on first char itself

No luck is required. Each byte has 256 possibilities, so the first byte being different for 13 hashes isn't that unusual. But if they collided for any reason, I'd just use the second byte of the hash.

Write a Ruby inspector in Ruby. Naturally!

Next challenge: Inspect this post itself

Julia, 90 59 bytes
Definitely not the shortest, but the fair maiden Julia takes great care in the inspection of the royal rubies.
s->search(s[vec([18 10 16 24 25 26 19 11 9 15 32 34])],' ')

This creates a lambda function which accepts a string s and returns the corresponding ruby defect number. To call it, give it a name, e.g. f=s->....
Ungolfed + explanation:
function f(s)
    # Strings can be indexed like arrays, so we can define d to
    # be a vector of indices corresponding to potential defect
    # locations

    d = vec([18 10 16 24 25 26 19 11 9 15 32 34])

    # Check the specified locations for defects, returning the
    # defect number as the index where a space was found and
    # was not expected. If no spaces are found, 0 is returned.

    search(s[d], ' ')
end

Examples:
julia> f("  ___
 /\\ /\\
/_/ \\_\\
\\ \\_/ \/
 \\/_\\/")
2

julia> f("  ___
 /\\_/\\
/_/ \\_\\
\\ \\_/ \/
 \\/_\\/")
0

Note that backslashes have to be escaped in the input. I confirmed with @Calvin'sHobbies that it's okay.
Let me know if you have any questions or suggestions!

Edit: Saved 31 bytes with help from Andrew Piliser!

You can get rid of the for loop with search and array indexing. s->(d=reshape([18 10 16 24 25 26 19 11 9 15 32 34],12);search(s[d],' ')). I don't like the reshape, but I couldn't think of a shorter way to get a 1d array.

@AndrewPiliser: Thanks, I really appreciate your input! I edited to use your suggestion. Also, a shorter way than reshape() is to use vec(). :)

><> (Fish), 177 bytes
This is a long but unique solution. The program contains no arithmetic or branching apart from inserting input characters into fixed places in the code.
Notice that all the inspected ruby-building characters (/ \ _) can be "mirrors" in the ><> code that change the direction of the instruction pointer (IP).
We can use these input characters to build a maze from them with the code-modifying instruction p and at every exit (which created by a missing mirror in the input) we can print the corresponding number.
iiiiiiiii19pi1cpi18piiii2bpi27pii28pi3apiiiii37pi49pi36piiiii00pi45pii46p

    ;
   ;n
  ;nb
 ;n6S    0n;
 n3SB   cn;
 8SB!  4n;
 SB!  1n;
>B! U9n;
 ! U5
  U7n
 Uan;
 2n;
 n;
 ;

The S B U letters are the ones changed to / \ _ respectively. If the input is a full ruby the final code becomes:
\iiiiiiii19pi1cpi18piiii2bpi27pii28pi3apiiiii37pi49pi36piiiii00pi45pii46p

    ;
   ;n
  ;nb
 ;n6/    0n;
 n3/\   cn;
 8/\!  4n;
 /\!  1n;
>\! _9n;
 ! _5
  _7n
 _an;
 2n;
 n;
 ;

You can try out the program with this great online visual interpreter. As you can't input newlines there you have to use some dummy characters instead so you can input a full ruby as e.g. SS___LS/\_/\L/_/S\_\L\S\_/S/LS\/_\/. (Spaces also changed to S's because of markdown.)

CJam, 41 31 29 28 bytes
"-RI)11a!"q103b1e3%A/c#

As usual, for non printable characters, follow this link.
Try it online here
Explanation soon

Previous approach:
Pretty sure this can be reduced by changing the digits/conversion logic. But here goes the first attempt:
"<KJ[]\"O=":iqN-"/\\_ "4,er4b1e3%A/#

As usual, use this link for unprintable characters.
The logic is pretty simple

"Hash for each defect":i - This gets me the hash per defect as the index
qN-"/\\_ "4,er - this converts the characters to numbers
4b1e3%A/ - this is the unique number in the base converted number
# Then I simply find the index of the unique number in the hash

Try it online here

So close, I'm 1 character shorter than you!

Oh, I already have 28. Was too busy to update

I think my answer is optimal for Pyth. Pyth really needs a hash function (.h right now is useless because it uses the built-in unreliable and bad hash()), until then I can't do better.

JavaScript (ES6), 67 72
Simply looks for blanks in the given 12 locations
Edit Saved 5 bytes, thx @apsillers
F=b=>[..."0h9fnopia8evx"].map((v,i)=>b[parseInt(v,34)]>' '?0:d=i)|d

Test In Firefox / FireBug console
x='  ___\n /\\_/\\\n/_/ \\_\\\n\\ \\_/ /\n \\/_\\/' // no defects
;[...x].forEach((c,p,a)=>{
  a[p]=' ' // put a blank
  y=a.join('') // rebuild a string
  d=F(y) // check
  if (d) console.log('\n'+y+'\n'+d) // if defect, output
  a[p]=c // remove the blamk
})

Output
  ___
 / _/\
/_/ \_\
\ \_/ /
 \/_\/
9

  ___
 /\ /\
/_/ \_\
\ \_/ /
 \/_\/
2

  ___
 /\_ \
/_/ \_\
\ \_/ /
 \/_\/
8

  ___
 /\_/\
/ / \_\
\ \_/ /
 \/_\/
10

  ___
 /\_/\
/_  \_\
\ \_/ /
 \/_\/
3

  ___
 /\_/\
/_/  _\
\ \_/ /
 \/_\/
1

  ___
 /\_/\
/_/ \ \
\ \_/ /
 \/_\/
7

  ___
 /\_/\
/_/ \_\
\  _/ /
 \/_\/
4

  ___
 /\_/\
/_/ \_\
\ \ / /
 \/_\/
5

  ___
 /\_/\
/_/ \_\
\ \_  /
 \/_\/
6

  ___
 /\_/\
/_/ \_\
\ \_/ /
 \ _\/
11

  ___
 /\_/\
/_/ \_\
\ \_/ /
 \/_ /
12

@apsillers it's good and even better, thanks. As the input string always start with ' ',the leading 0 force the initialization of d to i at first loop, so the 'd=0' can be remove.

Slip, 123 108 + 3 = 111 bytes
^6 (`\\`_.?<?.?[ _]?|`_(`\.?(<.?|>)|`/.?.?>.?.?).?)| `_(`\.?<.?>?.?.?|`/(.?>.?.?.?|<`_))| `/\`_.?(.<.?>?.?)?

Run with the n and o flags, i.e.
py -3 slip.py regex.txt input.txt no

Alternatively, try it online.

Slip is a regex-like language which was made as part of the 2D pattern matching challenge. Slip can detect the location of a defect with the p position flag via the following program:
^6? `_[/\]|( `/|^6 `\)\`_

which looks for one of the following patterns (here S denotes here the match starts):
S_/    S_\    /_S    \_S    S/      _
                              _      \S

Try it online — coordinates are outputted as an (x, y) pair. Everything reads like a normal regex, except that:

` is used for escaping,
<> turn the match pointer left/right respectively,
^6 sets the match pointer to face leftward, and
\ slips the match pointer orthogonally to the right (e.g. if the pointer's facing rightward then it goes down a row)

But unfortunately, what we need is a single number from 0 to 12 saying which defect was detected, not where it was detected. Slip only has one method of outputting a single number — the n flag which outputs the number of matches found.
So to do this we expand the above regex to match the correct number of times for each defect, with the help of the o overlapping match mode. Broken down, the components are:
1 11:    `_`\.?<.?>?.?.?
2 10:    `/\`_.?(.<.?>?.?)?
4 9:     `_`/(.?>.?.?.?|<`_)
3 12:   ^6 `_`/.?.?>.?.?.?
5 7:    ^6 `\\`_.?<?.?[ _]?
6 8:    ^6 `_`\.?(<.?|>).?

Yes, that's an exccessive use of ? to get the numbers right :P

Haha, amazing. I need to add more types of output to my language.

Python 2, 146 88 86 71 bytes
The function f tests each segment location and returns the index of the defect segment. A test on the first byte in the input string ensures that we return 0 if no defects are found.
We now pack the segment offsets into a compact string and use ord() to recover them:
f=lambda s:sum(n*(s[ord('ARJPXYZSKIO`b'[n])-65]<'!')for n in range(13))

Testing with a perfect ruby:
f('  ___\n /\\_/\\\n/_/ \\_\\\n\\ \\_/ /\n \\/_\\/')
0

Testing with segment 2 replaced by a space:
f('  ___\n /\\ /\\\n/_/ \\_\\\n\\ \\_/ /\n \\/_\\/')
2

EDIT: Thanks to @xnor for the nice sum(n*bool for n in...) technique.
EDIT2: Thanks to @Sp3000 for extra golfing tips.

I think you can save chars by using an indicator-sum sum(n*(s[...]==' ')for ...).

Considering that the replaced chars are all after space, you can probably do something like <'!' instead of ==' ' for a byte. You can also generate the list with map(ord, ...), but I'm not sure how you feel about unprintables :)

C, 98 84 bytes
g(char*b){char*c="/'-5670(&,=?",*a=c;for(;*c&&!(*b=b[*c++-30]-32?0:c-a););return*b;}

UPDATE: A tad bit more clever about the string, and fixed an issue with non-defected rubies.
Unraveled:
g(char*b){
    char*c="/'-5670(&,=?",*a=c;
    for(;*c&&!(*b=b[*c++-30]-32?0:c-a);)
        ;
    return*b;
}

Quite straightforward, and just under 100 bytes.
For testing:
#include "stdio.h"
int main() {
    char b[100];
    scanf("%35c", b);
    printf("%d\n", g(b));
    return 0;
}

Input to STDIN.
How it works
Each defect in the ruby is located at a different character. This list shows where each defect occurs in the input string:
Defect 1: 17
Defect 2: 9
Defect 3: 15
Defect 4: 23
Defect 5: 24
Defect 6: 25
Defect 7: 18
Defect 8: 10
Defect 9: 8
Defect 10: 14
Defect 11: 31
Defect 12: 33

Since making an array of {17,9,15,23,24,25,18,10,8,14,31,33} costs a lot of bytes, we find a shorter way to create this list. Observe that adding 30 to each number results in a list of integers that could be represented as printable ASCII characters. This list is as follows: "/'-5670(&,=?". Thus, we can set a character array (in the code, c) to this string, and simply subtract 30 from every value we retrieve from this list to get our original array of integers. We define a to be equal to c for keeping track of how far along the list we have gotten. The only thing left in the code is the for loop. It checks to make sure we have not hit the end of c yet, and then checks if the character of b at the current c is a space(ASCII 32). If it is, we set the first, unused element of b to the defect number and return it.

Pyth, 35 31 28 bytes
hx"*6#,54@"C%imCds.zT67

Requires a patched Pyth, the current latest version of Pyth has a bug in .z that strips off trailing characters.
This version doesn't use a hash function, it abuses the base conversion function in Pyth to compute a very stupid, but working hash. Then we convert that hash to a character and look its index up in a string.
The answer contains unprintable characters, use this Python3 code to generate the program accurately on your machine:
garbage = [42, 22, 54, 35, 44, 28, 31, 53, 52, 64, 16, 11]
prg = 'hx"' + "".join(chr(c) for c in garbage) +'"C%imCds.zT67'
open("golf_gen.pyth", "w").write(prg)
print(len(prg))

Haskell, 73 bytes
f l=last[x|x<-[0..12],l!!([0,17,9,15,23,24,25,18,10,8,14,31,33]!!x)==' ']

Same strategy as many other solutions: looking for spaces at the given locations. The lookup returns a list of indices from which I take the last element, because there is always a hit for index 0.

05AB1E, 16 bytes
•W)Ì3ô;4(•₆вèðk>

Try it online or verify all test cases.
Explanation:
•W)Ì3ô;4(•        # Push compressed integer 2272064612422082397
          ₆в      # Converted to Base-36 as list: [17,9,15,23,24,25,18,10,8,14,31,33]
            è     # Index each into the (implicit) input-string
             ðk   # Get the 0-based index of the first space in the indexed characters
                  # (-1 if not found, which means the ruby had no defects)
               >  # And increase it by 1 (which is output implicitly as result)

See this 05AB1E tip of mine (sections How to compress large integers? and How to compress integer lists?) to understand why •W)Ì3ô;4(• is 2272064612422082397 and •W)Ì3ô;4(•₆в is [17,9,15,23,24,25,18,10,8,14,31,33].


text:
The Sound of Words
People have written many things allowing one thing to be visualized as another. Now I propose being able to translate letters to music! Its your job to write a program that takes a text file and outputs a sound file with each letter converted to a specific note from C3-C8.
Disclaimer - I don't actually expect the music to sound any good but I hope to be surprised.
Specifications

You take the name of a file as a string and the BPM (beats per minute) as an int
You make uppercase A to be the note C3
And go up a half-step for every character after in this order: ABCDEFGHIJKLMNOPQRSTUVWXYZ ()-,;.'"abcdefghijklmnopqrstuvwxyz
Yes, not every character will be used since that spans too many octaves.
You translate every character in the file in this way
Put the notes together at the given BPM as quarter notes
Either save as a sound file (I'm guessing midi will be the easiest, but anything is ok) or play it
Any sane input format is fine
No standard loopholes
This is code-golf, so shortest code in bytes wins!

Bonuses

Allow transposing of output - 50 bytes
Allow multiple tracks to be superimposed over each other by taking multiple files - 75 bytes
Join consecutive letters into one longer note - 50 bytes

Edit: Wow, we have negative scores. I'll be announcing the winner on Saturday.

When will you be deciding the winner?

Can we assume the input will not contain any unlisted characters? Or, what should we do when we encountered unlisted characters?

@apsillers In the Snap ! answer, he said that he'd allow undefined behavior.

I uploaded a sample; you were quite correct,it really doesn't sound any good...

MATLAB, 159-50-50-75 = -16
Sample input
Sample output
Generates pure sine sound waves, very funky (sawtooth is also possible, with an even better score, but that sounds a bit... too funky). Works as a function, so expects it a character array (['abc';'def']) with one row per 'track'. I think that is covered under 'any sane input format', but if the general consensus is that I need to read a file, I suppose I can change it. Input i is text tracks (of equal length), b beats per minute and t transpose (supply 0 for not transposed). It blends two sines into one by offsetting the sine input, so I got all three bonuses, giving me a negative score.
function v(i,b,t)
s=0;for r=1:size(i)
o=[];for k=i(r,:)
o=cat(2,o,sin(55*pi*2^((k-28+t)/12)*(numel(o)/2^13+(0:1/2^13:60/b))));end
s=s+o;end
sound(s/max(s))
end

Version using input file: 211-175=36
Input argument i now represents the file name, other parameters unchanged. Might not work on newer releases because I'm getting a warning that textread may soon be deprecated. EDIT: textread apparently automatically splits up at whitespaces, so I fixed that. Also, I think I may have accidentally contacted some aliens with the weird sounds made while testing.
function v(i,b,t)
i=textread(i,'%s','whitespace','','delimiter','\n');s=0;for r=1:size(i)
o=[];for k=i{r,:}
o=cat(2,o,sin(55*pi*2^((k-28+t)/12)*(numel(o)/2^13+(0:1/2^13:60/b))));end
s=s+o;end
sound(s/max(s))
end

Which version do you prefer? :)

Well, the spec says explicitly to take the input from a file...

@LegionMammal978 If you insist: .mat files are of a sane input format. Create a .mat file with a 'i' variable that has your text. Then, add load(i); at the start of line 2 of the top version. Score: -16+8=-8. I'll do this when your comment gets more upvotes than mine, or when the OP has an opinion :)

Snap! - 401 - 75 = 326
Try it online here.
I'm using this method of counting bytes for the program.

I added playing multiple sounds at once.
The basic structure is the same as the original (see below), but with the addition of launch{}. launch{} starts a new thread with the code inside, allowing for concurrency.
The code as text is:
set[c v]to[ABCDEFGHIJKLMNOPQRSTUVWXYZ ()-,;.'"abcdefghijklmnopqrstuvwxyz
set[l v]to(list>
ask[BPM]and wait
set tempo to(answer)bpm
repeat until<(answer)=[
ask[notes]and wait
add(answer)to(l
end
delete(last v)of(l
for each(i)of(l
launch{
repeat(length of(i))(#
play note(i(c)(letter(#)of(i)))for(0.25)beats

(i(h)(n))
report(call(JavaScript function ([h][n]) {[return h.indexOf(n)+48]})with inputs(h)(n

Original code, 308.

Lucky Snap! has MIDI playing built in. ;)
Unfortunately, it doesn't have an indexOf function, so i have to make an external JavaScript call, which is pretty expensive.
The repeat () (#) block comes from the iteration library.
The code can be written out as text like this, which is how i get 308 bytes:
set[c v]to[ABCDEFGHIJKLMNOPQRSTUVWXYZ ()-,;.'"abcdefghijklmnopqrstuvwxyz
ask[BPM]and wait
set tempo to(answer)bpm
ask[notes]and wait
repeat(length of(answer))(#)
play note(i(c)(letter(#)of(answer)))for(0.25)beats

(i(h)(n))
report(call(JavaScript function ([h][n]) {[return h.indexOf(n)+48]})with inputs(h)(n

Does SNAP have a collection/showcase you can add these to like Scratch does? Linking directly to a runnable version would be handy IMO.

Yes. I added a link to my project. Good idea. :)

Does it ignore -1 from indexOf? Right now it looks like if its not in the string, it does midi number 47.

@Maltysen The question never says what do to with input outside of the proper range.

True. I meant for it to be ignored but since I guess its my fault for not being specific enough, I'll allow it.

I believe you should not do BPM*025; BPM is simply the number of quarter notes per minute, not the number of measures/bars per minute

Mathematica, 219 - 50 - 75 - 50 = 44
c=CharacterRange;d=Import;EmitSound[Function[b,Sound[Split@Characters@d@b/.a:{__String}:>SoundNote[StringPosition[c["A","Z"]<>" ()-,;.'\""<>c["a","z"],a[[1]]][[1,1]]+#3-12,60Length@a/#2],{0,60StringLength@d@b/#2}]]/@#]&

Takes the list of input files, BPM, and number of half-steps to transpose by as input and plays the sound (from a piano, any other instrument would take more bytes.) Doesn't sound that bad!

JavaScript (ES6) 377 - 50 - 50 - 75 = 202
First, here's a runnable snippet that uses <input> fields instead of file-reads:

BMP: <input id="bpm" size=3 placeholder="BMP" value="120"> Transpose: <input size=3 id="transpose" placeholder="Transpose" value="0">

<input placeholder="Track" class="track">
<button id="add">Add Additional Track</button>

<button id="play">Play</button>

And now, the actual entry:
f=(n,b,z)=>{C=new AudioContext;b=6e4/b;s=n.map(m=>(x=new XMLHttpRequest,x.open("GET",m,0),x.send(),x.responseText));s.map(p=>{var o=C.createOscillator(t=setTimeout);o.connect(C.destination);o.start();[...p].map((c,i)=>t(_=>o.frequency.value=440*Math.pow(2,("ABCDEFGHIJKLMNOPQRSTUVWXYZ ()-,;.'\"abcdefghijklmnopqrstuvwxyz".indexOf(c)-21+z)/12),b*i)),t(_=>o.stop(),p.length*b)})}

The three arguments are an array of filepath strings to play concurrently, notes per minute, and number of half-steps to transpose all inputs.
With whitespace and comments:
f=(n,b,z)=>{
    C=new AudioContext;
    b=6e4/b;

    // fill s with the contents of each file
    s = n.map(m=>(x=new XMLHttpRequest,x.open("GET",m,0),x.send(),x.responseText));

    // play each track
    s.map(p=>{
        var o=C.createOscillator(t=setTimeout);
        o.connect(C.destination);
        o.start();

        // queue up each note with setTimeout
        [...p].map((c,i)=>
            t(_=>
                o.frequency.value=440*
                    Math.pow(2,
                            ("ABCDEFGHIJKLMNOPQRSTUVWXYZ ()-,;.'\"abcdefghijklmnopqrstuvwxyz".indexOf(c)-21+z)/12
                    ),
             b*i)
        );
        // queue up termination of those track
        t(_=>o.stop(),p.length*b)})
}

f(["file:///home/users/apsillers/notes.txt",
   "file:///home/users/apsillers/notes2.txt"],
  240, 5)


text:
Collatz sequence on a two counter machine
The Collatz sequence starting from a positive integer n is defined in this way:

if n is even then divide it by 2 (n' = n / 2)
if n is odd then multiply it by 3 and add 1 (n' = 3n + 1)

Repeat the above iteration until n reaches 1.
It is not known (it's a major unsolved problem in number-theory) if the sequence will eventually reach the number 1, regardless of which positive integer is chosen initially.
A Two Counter Machine (2CM) is a machine equipped with two registers that can hold a non-negative integer value and can be programmed with the following instruction set:
INCX    increase the value of register X
INCY    increase the value of register Y
JMP n   jump to instruction n
DJZX n  if register X is zero jump to instruction n,
        otherwise decrement its value
DJZY n  if register Y is zero jump to instruction n,
        otherwise decrement its value
HALT    halt (and accept)
PRINTX  print the content of register X

A 2CM program is simply a sequence of instructions, for example the following program simply copies the content of register X to register Y:
cp:   DJZX end
      INCY
      JMP cp
end:  HALT

Note that a 2CM is Turing Complete (i.e. it can compute every computable function with a suitable input encoding, but it is irrelevant here). Also note that the instruction set is a little bit different from the one in the Wikipedia article.
The challenge
Write the shortest 2CM program, that computes and prints the collatz sequence up to 1 and halts (the register X initially contains the starting value n and register Y initially contains 0). Note that the length of a 2CM program is the number of instructions used (not the length of the text).
For example, when started from X=3 it must print: 3 10 5 16 8 4 2 1 and HALT.
So you can use your favourite language to build a 2CM simulator/interpreter, but the final (shortest) code that you put in the answer must be in the 2CM language.

What program shall we write for the 2CM machine?

Does your program have to end in HALT or can you also let execution flow off the end?

@orlp: as written in the question (... up to 1 and halts ...) it must HALT

@MarzioDeBiasi So a program that just lets the instruction pointer flow off the end of the program is an error?

@FUZxxl: as written in the question the 2CM program must "... compute and print the Collatz sequence from n to 1 and HALT ...". For example, when started from X=3 it must print: "3 10 5 16 8 4 2 1" and HALT

@MarzioDeBiasi I don't understand your example program either, AFAIK it will just increment once and then halt.

@orlp: ouch I missed the jump, sorry

@MarzioDeBiasi The quoted text does not appear in the question and I don't find a similar paragraph either. You might want to edit that in.

@MarzioDeBiasi Ah! That's what you mean. It's weird that you put it in a block quote. Still, you might want to specify that each number is supposed to be printed out.

@FUZxxl: I wrote it in the same paragraph "... and prints ...", furthermore I added an example ?!?

@MarzioDeBiasi Okay, sorry, I can't read...

Is the input Gödel encoded? a 2CM is only Turing complete when the input is Gödel encoded.

@FUZxxl: NO, it is still turing complete with 2 registers, the only hack (for Turing completeness) is that the input/output must be encoded as 2^n  but for this question it is irrelevant. You don't need Godel encoding here.

what is the initial value of X and Y? (probably you need to get the input in X?)

@Nejc: as written in the question " .... the register X initially contains the starting value n and register Y initially contains 0 ... example ... X=3 ..." ?!?!?

@LegionMammal978: ??? The linked (wikipedia) article says "This example shows how to create three more useful instructions: clear, unconditional jump, and copy ...". In every case the instruction set for the question is slightly different (it's more "succinct"). ... mmm ... I'm new to codegolf, but it seems that people here don't pay much attention in what they read :-)

Here's a simple interpreter with basic debugging output.

Also, are the instructions 0- or 1-indexed?

@LegionMammal978 Doesn't matter for the code size.

@MarzioDeBiasi Seeing all these comments, let me recommend the sandbox (at least for your next challenge). Writing clear challenges is hard, and even if you think you've sorted it all out, there are often open questions for other users, which can be pointed out in the sandbox and addressed before you post the challenge on main and people start working on it.

What is the valid range of input?

@FUZxxl: valid inputs: any number greater than 0 on register X (while Y initially contains 0)

18 instructions
I was a bit disappointed that I arrived late on scene, as the minimalistic nature of the problem and the language make there (seemingly) only one general approach for a good answer. I got a 19-instruction answer fairly quickly, but I didn't feel like it brought enough to the table to post it. But after much head scratching, my hacky z80 assembly experience came through and I found a way to save an instruction by reusing a block of code for a purpose it wasn't meant for!
# Let N be the previous number in the Collatz sequence.

# Print N, and if N==1, halt.
# X=N, Y=0
Main:           PRINTX          # Print N.
                DJZX Done       # X=N-1 (N shouldn't be zero, so this never jumps)
                DJZX Done       # If N-1==0, halt. Otherwise, X=N-2.

# Find the parity of N and jump to the proper code to generate the next N.
# X=N-2, Y=0
FindParity:     INCY
                DJZX EvenNext   # If N%2==0, go to EvenNext with X=0, Y=N-1.
                INCY
                DJZX OddNext    # If N%2==1, go to OddNext with X=0, Y=N-1.
                JMP FindParity

# Find the next N, given that the previous N is even.
# X=0, Y=N-1
EvenNext:       INCX
                DJZY Main       # Y=Y-1 (Y should be odd, so this never jumps)
                DJZY Main       # If Y==0, go to Main with X=(Y+1)/2=N/2, Y=0.
                JMP EvenNext

# Find the next N, given that the previous N is odd.
# X=0, Y=N-1
OddNext:        INCX
                INCX
                INCX
                DJZY EvenNext   # If Y==0, go to EvenNext with X=(Y+1)*3=N*3, Y=0.
                JMP OddNext     # ^ Abuses EvenNext to do the final INCX so X=N*3+1.

# Halt.
Done:           HALT

I hope my interpreter didn't suck too bad :P Nice solution.

@orlp Worked like a charm. Thanks. :)

I really like your solution! Very nice abuse of EvenNext :)

19 instructions
I wrote my own interpreter because I'm fancy like that. Here is my solution for my own interpreter:
MP
 XE
 XE
HY
 XV
 XO
 JH
WX
VYM
 JW
LYM
 X
 X
OX
 X
 X
 X
 JL
EH

And here is what it looks like with syntax compatible to the other interpreter:
# x = n, y = 0
main:    printx
         djzx   end
         djzx   end

# x = n - 2, y = 0 on fallthrough
half:    incy
         djzx   even
         djzx   odd
         jmp    half

evloop:  incx
# x = 0, y = n / 2  on jump to even
even:    djzy   main
         jmp    evloop

oddloop: djzy   main
         incx
         incx
# x = 0, y = (n + 1) / 2 on jump to even
odd:     incx
         incx
         incx
         incx
         jmp    oddloop

end:     halt

Looks like we found the same solution, you were earlier though :(

@orlp That happens.

SCORE: 21
Here is my attempt:
main: prints X and jumps to finish (if X==1).
divisibility: makes a distinction if X%2==0 or X%2==1. Also copies X to Y and makes X==0. Jumps to either isDivisible (if X%2==0) or isNotDivisible (if X%2==1).
isDivisible: loop used when Y%2==0. For each decrease of Y by 2, it increases X by 1. When Y==0, jumps to main.
isNotDivisible: used when Y%2==1. It increases X by 1.
notDivLoop: loop used when Y%2==1. For each decrease of Y by 1, it increases X by 3. When Y==0, jumps to main.
finish: halts
main:           PRINTX              # print X
                DJZX main           # here X is always >0 and jump never fires (it is just for decreasing)
                DJZX finish         # if initially X==1 this jumps to finish
                INCX                # establish the previous state of X
                INCX
                                    # continue with X>1

divisibility:   DJZX isDivisible    # if X%2==0, then this will fire (when jumping Y=X)
                INCY
                DJZX isNotDivisible # if X%2==1, this fires (when jumping Y=X)
                INCY
                JMP divisibility    # jump to the beginning of loop

isDivisible:    DJZY main           # this jumps to the main loop with X=X/2
                DJZY main           # this jump will never fire, because X%2==0
                INCX                # for every partition 2 of Y, increase X (making X=Y/2)
                JMP isDivisible     # jump to beginning of loop

isNotDivisible: INCX                # X=0, increase for 1
notDivLoop:     DJZY main           # in each iteration, increase X for 3 (when Y==0, X=3Y+1)
                INCX
                INCX
                INCX
                JMP notDivLoop      # jump to beginning of loop

finish:         HALT                # finally halt

Supplied with 3 (using the interpreter supplied by @orlp), the produced result is:
3
10
5
16
8
4
2
1

19 instructions
found:    PRINTX       # print input/found number
          DJZX done    # check if n == 1
          DJZX done    # after this point x == n - 2
parity:   INCY         # after this loop y == n // 2
          DJZX even
          DJZX odd
          JMP parity
odd-loop: DJZY found
          INCX
          INCX
odd:      INCX         # we enter mid-way to compute x = 6y + 4 = 3n + 1
          INCX
          INCX
          INCX
          JMP odd-loop
even:     DJZY found   # simply set x = y
          INCX
          JMP even
done:     HALT

You can run it using my interpreter.

Duplicate of my answer.

@FUZxxl That's what I said an hour ago to you :P

Yes, you did. I wrote this so others realize the equality.


text:
Prepare to... die?
Background
One source of ennui in tabletop role-playing games is dealing with rolls involving many dice. Casting a Disintegration spell may be instantaneous, but rolling and adding together 40 dice certainly isn't!
A number of suggestions for handling this are discussed at rpg.stackexchange.com. Some of them, however, such as using a roller program or averaging dice, take away some of the fun and sense of control from the players. Others, such as rolling 4 dice and multiplying the total by 10, make the results far more swingy (while averaging dice acts in the opposite direction).
This question concerns a method of reducing the number of dice rolls without changing either the average result (mean) or its swinginess (variance).
Notation and math
In this question, we'll use the following notation to represent dice rolls:

ndk (e.g. 40d6) refers to the sum of n rolls of a k-sided die.
ndk*c (e.g. 4d6*10) describes multiplying the result by a constant c.
We can also add rolls (e.g. 4d6*10 + 40d6) and constants (e.g. 4d6 + 10).

For a single die roll, we can show that:

Mean: E[1dk] = (k+1)/2
Variance: Var(1dk) = (k-1)(k+1)/12

Using the basic properties of mean and variance, we can furthermore infer that:

Mean: E[mdk*a + ndl*b + c] = a.m.E[1dk] + b.n.[1dl] + c
Variance: Var(mdk*a + ndl*b + c] = a².m.Var(1dk) + b².n.Var(1dl)

Task
Given three integers n, k and r, your program should output a way of approximating ndk in at most r rolls, with the following constraints:

The solution should have the same mean and variance as ndk.
The solution should contain the largest possible number of rolls less than or equal to r, as more rolls produces a smoother distribution.
You should restrict your solutions to only using k-sided dice, unless you're aiming for the Bonus (see below).
If there is no solution (as r is too small), the program should output the string "I AM A SEXY SHOELESS GOD OF WAR!".
The parameters are passed in as a single space-separated string.
You may assume that 1 ≤ n ≤ 100, 1 ≤ r ≤ n and that k is one of 4, 6, 8, 10, 12 and 20 (the standard dice used in tabletops).
The output should be in the format described in Notation (e.g. 4d6*10+5), with optional spaces around +s but nowhere else.
Unit multipliers are also optional: both 4d6*1 and 4d6 are valid.

You may write a program or function, taking input via STDIN (or closest alternative), command-line argument or function argument. Results should be printed to STDOUT (or closest alternative) or returned as a string.
Examples
>> "10 6 10"
10d6
>> "10 6 4"
2d6*2+2d6+14
>> "10 6 3"
1d6*3+1d6+21
>> "10 6 2"
1d6*3+1d6+21
>> "10 6 1"
I AM A SEXY SHOELESS GOD OF WAR!

Scoring
Shortest code wins. Standard rules apply.
Bonus
-33% (rounded down before subtraction) if your program also return solutions that include valid dice other than k (where the valid values, as mentioned above, are 4, 6, 8, 10, 12 and 20). If you choose to do so, then you should always return such solutions when appropriate, and handle solutions that use multiple types of die. Example:
>> "7 4 3"
3d6+7

+1 For the OotS reference. ;) (Well and because it's a really nice challenge, actually.)

Maybe use our new $\LaTeX$ capabilities to swag up this question?

@UriZarfaty: I updated your formulas to use LaTeX. Hope that's alright. If you don't like it, you can just roll back the post and it'll go back to how it was before.

@AlexA. That's great, thanks.

I've rolled back the LaTeX edit, because unfortunately, it will be deactivated again for now.

#SadPanda - I thought this was going to be a code challenge reference to "Hello. My name is Inigo Montoya. You killed my father. Prepare to die."

Why isn't 40d6 used in the test cases at all? You went to the trouble of using it a bunch in the question...

@mbomb007 It should have been. I think it was just laziness on my part (to make manually figuring out the answers easier).

GolfScript (163 143 133 bytes)
~@:^\?,{^base 0-}%{0\{.*+}/^=},.{{,}$-1=..&{[[1$[1$]/,(3$@]'d*+'1/]zip}%^@{-}/@)*.2/\1&'.5'*}{];'I AM A SEXY SHOELESS GOD OF WAR!'}if

Online demo
When not mixing types of dice, the problem reduces to expressing n as a sum of no more than r squares, and k is irrelevant except for the calculation of the constant at the end. The bulk of this answer is the bookkeeping required to express the result in the desired format: the actual calculation is ^\?,{^base}%{0\{.*+}/^=}, to find the multiplication factors a, b, etc.; and ^@{-}/@)*.2/ to calculate the constant.
Dissection
~                # Stack: n k r
@:^\?,{          # Store n in ^, and for 0 to n**r
  ^base 0-       #   convert to base n and remove 0s.
}%               # Stack: k [arrays of up to r values from 1 to n-1]
{0\{.*+}/^=},    # Filter them to arrays whose sum of squares is n,
                 #   i.e. to multipliers which have the right variance
.{               # If any multiplier array passes the filter...
  {,}$-1=        #   Pick one with the greater number of rolls
                 #   Stack: k [multipliers]
  ..&{           #   Map each distinct multiplier a...
    [[           #     Gather in nested array for later zip
      1$[1$]/,(  #       Split a copy of the multipliers around a to count the as
                 #       Let's denote that count as m
                 #       Stack: k [multipliers] a [ [ m
      3$@        #       Copy k and rotate the a inside the nested array
     ]           #       Stack: k [multipliers] [ [m k a]
      'd*+'1/    #       Push an array ['d' '*' '+'] and close nested array
    ]zip         #       Giving [[m 'd'] [k '*'] [a '+']]
                 #       which will be printed as mdk*a+
  }%             #   Stack: k [multipliers] [string representations of dice]
  ^@{-}/@)*      #   Compute (n - sum(multipliers)) * (k + 1)
                 #   That's twice the constant we need to add to fix the mean
  .2/\1&'.5'*    #   And convert it to a renderable form, including .5 if needed
}{               # Otherwise clear the stack and push the error message
  ];'I AM A SEXY SHOELESS GOD OF WAR!'
}if

Python, 487 461 452 - 33% =  303 bytes
Since nobody else has done so, here is a solution that handles different types of dice. Like the other solution, it generates a range of possible solutions and filters them down. It uses the fact that (k+1)(k-1) = k^2-1 and two semi-loopholes in the spec (oops!): the lack of ban on printing the redundant form 0dk*a (which saves all of 5 bytes!), and the lack of running time restriction (it gets slow fairly quickly, though does run all the examples given).
from itertools import*
N,K,R=map(int,input().split())
S=lambda l:sum([x[0]for x in l])
s=[x for x in product(*[[(n,k,a)for n in range(N*(K**2-1)/((k**2-1)*a**2)+1)]for a in range(1,N+1)for k in[4,6,8,10,12,20]if a**2<=N])if sum([n*(k**2-1)*a**2 for n,k,a in x])==N*K**2-N and S(x)<=R]
if s:s=max(s,key=S);print"+".join(["%sd%s*%s"%x for x in s]+[str(int(N*(K+1)/2.-sum([n*a*(k+1)/2.for n,k,a in s])))])
else:print"I AM A SEXY SHOELESS GOD OF WAR!"

For prettier output add if x[0] after "%sd%s*%s"%x for x in s:
>> "7 4 3"
3d6+7
>> "10 6 3"
1d6*1+1d8*1+1d8*2+18
>> "10 6 2"
1d6*1+1d6*3+21
>> "10 6 1"
I AM A SEXY SHOELESS GOD OF WAR!


text:
ASCII Doodling: Laser in a Box
Sometimes when I'm doodling, I draw a rectangle, start with a diagonal from one of the corners, and then just trace out a line by "reflecting" it whenever I hit a side of the rectangle. I continue with this until I hit another corner of the rectangle (and hope that the aspect ratio of my rectangle was not irrational ;)). This is like tracing out the path of a laser shone into a box. You're to produce the result of that with ASCII art.
As an example, consider a box of width 5 and height 3. We'll always start in the top left corner. The # marks the boundary of the box. Note that the width and height refer to the inner dimensions.
#######    #######    #######    #######    #######    #######    #######
#\    #    #\    #    #\   \#    #\  /\#    #\  /\#    #\/ /\#    #\/\/\#
# \   #    # \  /#    # \  /#    # \/ /#    # \/ /#    #/\/ /#    #/\/\/#
#  \  #    #  \/ #    #  \/ #    # /\/ #    #\/\/ #    #\/\/ #    #\/\/\#
#######    #######    #######    #######    #######    #######    #######

The Challenge
Given the (positive) width and height of the box, you should produce the final result of tracing out the laser. You may write a program or function, taking input via STDIN (or closest alternative), command-line argument, function argument and output the result via STDOUT (or closest alternative), or via function return values or arguments.
You may use any convenient list, string or number format for input. The output must be a single string (unless you print it to STDOUT, which you may of course do gradually). This also means you can take the height first and the width second - just specify the exact input format in your answer.
There must be neither leading nor trailing whitespace on any line of the output. You may optionally output a single trailing newline.
You must use space, /, \ and # and reproduce the test cases exactly as shown.
Test Cases
2 2
####
#\ #
# \#
####

3 2
#####
#\/\#
#/\/#
#####

6 3
########
#\    /#
# \  / #
#  \/  #
########

7 1
#########
#\/\/\/\#
#########

1 3
###
#\#
#/#
#\#
###

7 5
#########
#\/\/\/\#
#/\/\/\/#
#\/\/\/\#
#/\/\/\/#
#\/\/\/\#
#########

22 6
########################
#\  /\  /\  /\  /\  /\ #
# \/  \/  \/  \/  \/  \#
# /\  /\  /\  /\  /\  /#
#/  \/  \/  \/  \/  \/ #
#\  /\  /\  /\  /\  /\ #
# \/  \/  \/  \/  \/  \#
########################

Perhaps a nice follow-up question, once this one has run its course, is to do this challenge with arbitrarily shaped boxes and starting points.

@sanchises I had actually considered that (and might still post it), but I decided to go with the rectangle in hopes that someone might come up with an explicit formula. I was also considering multiple starting points such that X would be necessary for crossings. Maybe next time. ;)

Relevant: http://i.imgur.com/6tXrIfw.webm

This would be perfect for an animation point. "Animate 1 burst (one slash) 1 cycle/ endless)"

Pyth, 43 41 39 bytes
K*\#+2QKVvzp<*QXX*dyivzQN\\_hN\/Q\#\#)K

Try it online: Pyth Compiler/Executor. Input the numbers in the following order: height first line, width second line.
Thanks to isaacg, who helped saving two bytes.
Explanation:
My solution doesn't trace the laser, it uses a simple pattern that includes the gcd. If m, n are the dimensions of the box, let d = gcd(m, n). The size of the pattern is exactly 2*d x 2*d.
E.g. the repeating pattern for 7 5
#########
#\/\/\/\#
#/\/\/\/#
#\/\/\/\#
#/\/\/\/#
#\/\/\/\#
#########

is
\/
/\

(gcd(7, 5) = 1, size of pattern is 2 x 2)
And the repeating pattern for 22 6
########################
#\  /\  /\  /\  /\  /\ #
# \/  \/  \/  \/  \/  \#
# /\  /\  /\  /\  /\  /#
#/  \/  \/  \/  \/  \/ #
#\  /\  /\  /\  /\  /\ #
# \/  \/  \/  \/  \/  \#
########################

is
\  /
 \/
 /\
/  \

(gcd(22, 6) = 2, size of pattern is 4 x 4)
My solution does the following thing for each of the lines: it simply generates one line of the pattern, repeats it a few times and cut's it at the end so that it fit's into the box.
K*\#+2QK   implicit: Q is the second input number (=width)
K          K =
 *\#+2Q        "#" * (2 + Q)
       K   print K (first line)

Vvzp<*QXX*dyivzQN\\_hN\/Q\#\#)K  implicit: vz is the first input number (=height)
VQ                               for N in [0, 1, ..., vz-1]:
           ivzQ                             gcd(vz,Q)
          y                               2*gcd(vz,Q)
        *d                           string with 2*gcd(vz,Q) space chars
       X       N\\                   replace the Nth char with \
      X           _hN\/              replace the -(N+1)th char with /
    *Q                               repeat Q times
   <                   Q           only use the first Q chars
  p                     \#\#       print "#" + ... + "#"
                            )    end for
                             K   print K

Since X supports "assigning" to strings, you can change m\  to *d and remove s.

@isaacg Good call. I thought about using *\  instead of m\  shortly, but discard it because it has the same size. Didn't think of the variable d and the unnecessary s.

C, 256 bytes
f(w,h){int i,j,x=1,y=1,v=1,u=1;char b[h+2][w+3];for(i=0;i<w+3;i++)for(j=0;j<h+2;j++)b[j][i]=!i||!j||i>w||j>h?i>w+1?0:35:32;while((x||y)&&(x<=w||y<=h))v=x&&w+1-x?v:(x-=v,-v),u=y&&h+1-y?u:(y-=u,-u),b[y][x]=v/u<0?47:92,x+=v,y+=u;for(i=0;i<h+2;i++)puts(b[i]);}

I can probably get this under 200, and I'll add an explanation later, but I might have a paper due in a few hours I should be doing  instead.

Fake internet points are worth more than an educational degree, I'm sure of it.

225 bytes

J, 85 bytes
Let g = gcd(w,h). The function fills the elements of a w/g by h/g matrix with g by g tiles, having /'s and \'s in their diagonal and anti-diagonal. The resulting 4D array is raveled into a 2D one (the inside of the box) then surrounded with #'s. (The numbers 0 1 2 3 are used instead of [space] / \ # and the numbers are changed to characters at the end.)
A direct position based computation of inside coordinate could maybe yield a bit shorter solution.
' \/#'echo@:{~3,.~3,.3,~3,,$[:,[:,"%.0 2 1 3|:((,:2*|.)@=@i.@+.){~[:(2&|@+/&:i.)/,%+.

Usage:
   6 (' \/#'echo@:{~3,.~3,.3,~3,,$[:,[:,"%.0 2 1 3|:((,:2*|.)@=@i.@+.){~[:(2&|@+/&:i.)/,%+.) 22
########################
#\  /\  /\  /\  /\  /\ #
# \/  \/  \/  \/  \/  \#
# /\  /\  /\  /\  /\  /#
#/  \/  \/  \/  \/  \/ #
#\  /\  /\  /\  /\  /\ #
# \/  \/  \/  \/  \/  \#
########################

Try it online here.

Desmos Calculator - Non Competing to Help Further Knowledge
Try it online!
Inputs:
h as height of box, with 0-indexing
w as width of box, with 0-indexing

Intermediates:
Let b = gcd(h,w),
Let c = |b-h%2b| Or |b-mod(h,2b)|

gcd(h,w) represents the greatest common denominator
A % B, as in Javascript, or mod(A,B), as in Fortran, represents the modulus operation, on the interval [0,B).

Formula, abbreviated:
(|b-(x+y)%2b|-c)(|b-(x-y)%2b|-c)=0

Outputs:
x as x position, 0-indexed, where the ball will land when released
y as y position, 0-indexed, where the ball will land when released

How it Works:
(|b-(x+y)%2b|-c)*(|b-(x-y)%2b|-c)=0
                ^ OR operation - |b-(x+y)%2b|-c=0 or |b-(x-y)%2b|-c=0
|b-(x+/-y)%2b|-c = 0
|b-(x+/-y)%2b| = c
|b-(x+/-y)%2b| = c means (b-(x+/-y))%2b = + or -c
b-(x+/-y)%2b = +/- c -> b +/- c = (x+/-y)%2b -> (x+/-y) = n*2*b + b +/- c
Where n is integer.  This will force patterns to repeat every 2b steps in x and y.
Initial pattern n=0: (x +/- y) = b +/- c -> y = +/- x + b +/- c
In the x positive and y positive plane only, these correspond to lines of positive and
negative slope, set at intercept b, offset by c on either side.

Program fails to meet final criterion - generating ASCII art of box and lines, so I'm submitting as non-competitive for information to help others complete the challenge.  Note that to get Desmos to work when c = 0 or c=b, a small offset factor of 0.01 was introduced, as Desmos seems to have bounds of Mod(A,B) of (0,B) instead of [0,B)