

programming challenge - jaekwon
http://glyphtree.com/puzzles

======
benjoffe
The section under "Submission Directions" is exactly the same as the
directions here: <http://www.facebook.com/careers/puzzles.php> verbatim even
down to the exact version numbers.

Is there some standard testing package that these are both using? Otherwise it
seems fishy.

~~~
beaumartinez
I noticed that too. Googling the text yields quite a few matches; my guess is
either they think "Facebook does it, so we should do it like that too", or
it's a standard testing package or something.

[http://www.google.com/search?q=%22All+submissions+must+execu...](http://www.google.com/search?q=%22All+submissions+must+execute+in+a+*NIX+type+environment+\(sorry,+no+Windows+specific+solutions+are+accepted\).+You+are+not+guaranteed+any+libraries+or+plugins+beyond+what+is+part+of+the+language/interpreter+itself.+The+following+languages+are+accepted:%22)

------
tlb
The solution given is incorrect. It yields 29 white balls, while the following
yields 35.

    
    
      1 jar1:2
      2 
      3 jar2:3
      4 
      5 
      6 jar1:2 jar2:4
      7 
      8 
      9 jar2:6
      10 
      11 
      12 jar1:11 jar2:3
      13 
      14 
      15

~~~
Natsu
Honestly, I wish I were on the other end of this. I wonder how many solutions
I could find test cases to break even assuming I play nice and allow only
positive integers?

Yes, I really did imagine all kinds of cases involving zero time and negative
time rules (or having zero time to produce anything) and tried to conform them
to the spec, but most of them conflict with the output requirements. Not all,
though...

~~~
jaekwon
Thanks for your input Natsu, I edited the puzzle to require positive integers.

------
gacek
So how is this "challenge" more interesting than thousands of problems on
SPOJ, UVA, topcoder or project Euler?

~~~
jaekwon
I challenge you to create a more interesting problem.

~~~
daivd
How about the same problem, but with each Jar having:

a) a known fail percentage - 40% of the time the Jar fails and produces
nothing. Maximize expected win.

b) an unknown fail percentage, evenly distributed between 0 and 100%. Find a
strategy that maximizes expected win over many runs (each run has new fail
probabilities), by perfectly balancing between exploration of jars and
exploitation. If you can find an optimal (and practical) strategy for this one
I applaud you!

Also, I solved your example with a simple Python brute-forcer with < 1s run
time. I don't know if I care enough to write a parser of your file format just
to mail it in ;).

~~~
yousuffauzan
Under 1 sec is amazing. When you say brute force, do you mean that for the
first step (TS 1), you took all the three routes available, [0,0], [1,0],
[2,0] for jar 1 and 2. Cause that just makes the number of branches too many
to be solved in a reasonable amount of time. I would love to have a peek at
you code.

~~~
daivd
It is real brute force, but I do not investigate some stupid nodes. If I
choose to not use an available jar during a timestep, I disqualify that jar,
until another jar has been used, since there is no point in waiting to use a
jar unless you want to save your balls for another jar.

The code is ugly and undocumented. I think the same could be accomplished in
less than 10 lines of Haskell :). <http://pastebin.com/MfXK9fwS>

An implementation detail is that my branches are actually "jar1" "jar2" and
"stepforward". To use a jar many times, you do jar1, jar1, stepforward.

~~~
yousuffauzan
As my first erlang program, I tried to solve this problem. The code is very
ugly, and rather long for my taste, but it solves the thing in 917 steps. I
also took the case where if no output has been gotten in a particular
timestep, then do not consider any jars.

------
lisper
View source on the home page is interesting too.

~~~
Natsu
I was kind of hoping it would explain what Glyphtree is, but it's a
riddle/poem.

It has me wondering how 'loser' is defined and if a person can be their own
'friend' ... (read their riddle poem if that makes no sense to you).

~~~
sharpneli
"the world is a sphere, and friends don't cross each other."

My guess would be that the social graph needs to be planar (e.g embeddable on
a plane so that no edges go across eachother).

The world is a sphere can be interpreted in too many ways. One would be that
there exists a hamiltonian cycle for the graph and other would be that if you
do a depth first search you'd always hit yourself eventually.

My strong guess would be that 2 friends is the least and the most a loser may
have.

Biggest problem with too smart puzzles such as this is that there are way too
many ways to legitimately interpret them.

~~~
jaekwon
The social graph need not be planar, say if the world is a donut.

~~~
sharpneli
I'd consider that a minor adjustment as it would still essentially be a planar
graph (with periodic boundary conditions). Locally both of the cases look
identical.

Just checked wiki while writing this and toroidal embeddings are a subclass of
planar graphs.

~~~
jaekwon
I'm sorry, the puzzle is asking for a global property. The new text has the
adjustments.

~~~
sharpneli
I think I got it now. Don't read this if you are afraid of possible spoiling.

We are looking for a graph with highest possible minimum vertice count for any
single node. The answer is 6. This graph comes from simply making a hexagonal
tiling with node on center and vertices going trough edges. Any tiling with
more angles does not produce a planar graph and we'd have to insert polygons
with less vertices and thus less neighbours and therefore lowering the
smallest edge count.

~~~
lisper
I don't think it's possible to tile a sphere with hexagons. You have to throw
a couple of pentagons in.

<http://en.wikipedia.org/wiki/Geodesic_dome>

~~~
sharpneli
True. So for a spherical topology the largest minimum is 5. However for
toroidal topology the largest minimum is 6.

------
Swizec
This looks like a really cool challenge. Reminds me a bit of the knapsack
problem (<http://en.wikipedia.org/wiki/Backpack_problem>)

But something tells me the solution is going to be a lot less simple though.

~~~
uncompetence
If you treated this as a variant on the backpack problem, you run into trouble
as you can't properly memoize or use dynamic programming. You use 'timesteps'
as the size of the 'knapsack' since the number of balls is unbounded. At each
timestep, you cannot determine the the optimal solution to the subproblem and
you'd have to save every possible ball combination.

TL;DR - It gets to be a pretty messy/bad backpack and should probably be
solved another way

~~~
jules
Integer linear programming!

------
earl
If you run whois and check linkedin, you can figure out where the author most
likely works and what sort of things they do... No names since he probably
doesn't want to be googleable.

~~~
njckname2
You can tell the author is the user who submitted this to hacker news.

~~~
jaekwon
Yeah I don't care to be anonymous. I don't work at the moment, I'm building
connections and learning some business chops at an incubator to start a
business. If you want to change life on earth as we know it, you know where to
find me.

------
yousuffauzan
Another solution for white=35.

1

2 jar1:1

3

4 jar2:3

5 jar1:1

6

7 jar2:4

8 jar1:1

9

10 jar2:6

11

12

13 jar1:12

14

15

