
Hello, World - sethbannon
https://m.whitehouse.gov/blog/2015/05/17/hello-world
======
SMackinnon
Spoiler:

Bob always chooses the same as his flip, Alice always chooses the opposite of
her flip.

    
    
      B A
      H H - Bob chooses heads, Win
      H T - Alice chooses heads, Win
      T H - Alice chooses tails, Win
      T T - Bob chooses tails, Win

~~~
furyofantares
My experience arriving at this solution made me a bit curious as to how others
solved it. Was there reasoning involved before you arrived at a strategy and
verified it, or did the strategy just come to you? Did you try multiple
strategies, and if so, was there a method to generating/iterating on them, or
were they just coming to you and you tried them?

~~~
simplicio
Brainteasers tend to follow a particular pattern. The amount of information
the various Alices and Bobs and Charlies have seems at first glance to
obviously be inadequate to the task they're given. Then a closer examination
reveals that there's some sublte extra scrap of information, and you can
generally assume than that the answer is to use that to trace out the
possibilities to find the actual answer.

So knowing that, I just looked for what extra, non-obvious piece of
information A and B had. It seems impossible to guess what the results of a
coin-flip are in another room. But the players also know the result of their
own flip, and so basing a strategy on that extra info is certainly going to be
the answer. From there, since there are so few combinations of such a
strategy, getting the right answer is pretty trivial.

I like this brain teaser (and I suspect the reason that Felton likes it as
well) because it shows this general pattern for brain teasers very clearly.
The "extra" piece of information is pretty obvious with a moments thought. And
once you have it, the number of possible strategies using it is small enough
that you can see the correct one quickly.

A lot of other brain teasers require a lot of pen and paper work even after
you've guessed the "trick" in order to work through all the possiblities. So
this is sort of a nice, boiled down "essence du brainteaser".

~~~
CPLX
One of the main challenges, however, seems like it would rear its head as soon
as you leave the confines of a defined brain teaser, where you know for sure
that there is a "trick" even if you can't see it, and real world situations
such as in programming, where you don't yet know if the specific problem is
solvable at all.

~~~
furyofantares
I noticed something similar when I was studying math: Exercises of the variety
"Prove x" or "Disprove x" were much more than twice as easy as exercises of
the variety "Prove or disprove x".

------
rjtobin
Some discrete mathematicians are interested in this sort of problem, which
they call "simultaneous hat guessing". There are quite a few papers, in case
anyone is interested and unfamiliar with this sort of thing.

Another fun problem, probably better known, is sequential hat guessing: take
100 people in a line, arranged so that each person can see everyone in front
of them, but no-one can see any of the people behind them. Everyone is given
either a red or black hat to wear, but no one can see the color of their own
hat, or the hat of anyone behind them. So the person at the back of the line
can see everyone's hat but their own, the next person can see everyone's hat
except the first person and their own, etc.

Now starting with the back of the line, each person is asked to publicly guess
the color of their hat. The participants are allowed to agree upon a strategy,
how many people can they guarantee guess correctly?

Things get crazy if you allow an infinite countable line of people, and put
ear-muffs on anyone so that no one gets to hear anyone else's guess.
Surprisingly, you can still save almost everyone (if you allow the axiom of
choice).

~~~
d0m
Yes, this is a great one. Unless I'm mistaken, the best strategy has
potentially one error, but all the rest would get it right, yes?

~~~
rjtobin
that's exactly it

------
thewarrior
I haven't looked at any of the solutions. Or any of the other comments.So at
the risk of posting a redundant comment :

Alice guesses that Bob's coin is the same as hers. Bob guesses that Alice's
coin is the opposite to hers.

It's fairly straightforward. I'd like to know the computer science angle to
this though.

EDIT: From the computer science that I know :

We need to find an invariant that all permutations of coin flips always
satisify. Intuition tells us that Alice's coin might be the same as Bob or
vice versa :

If you construct a truth table :

    
    
      Alice  Bob     Alice's Coin same as bob    Bob's opposite to Alice
    
      H      H               YES                            NO
    
      T      T               YES                            NO
    
      H      T               NO                             YES
    
      T      H               NO                             YES
    

The expression :

    
    
      Alice's coin same as Bob || Bob's opposite to Alice
    

Always evaluates to true. So Alice can guess her flip and Bob can guess the
opposite.

But what if we had Alice , Bob and George and atleast one of them had to get
the other two right ?

Is there a general pattern ?

    
    
      Alice Bob George
      H     H   H
      H     H   T
      H     T   H
      H     T   T
      T     H   H
      T     H   T
      T     T   H
      T     T   T
    

Will try and figure it out over dinner :D .

------
est
This is off topic, but when the next president takes office, all of current
whitehouse.gov content will be gone and replaced, no?

~~~
trvr
I'm guessing they will do something similar to when Obama took office:
[http://georgewbush-whitehouse.archives.gov/](http://georgewbush-
whitehouse.archives.gov/)

~~~
zatkin
Very clever. So I'm assuming they just don't write any links that involve
using the full domain. (i.e. /somepage instead of
[http://www.whitehouse.gov/somepage](http://www.whitehouse.gov/somepage))

~~~
judk
Link rewriting is a standard feature of wget.

------
pelario
"Coding is exciting: you can decide what is supposed to happen, and the
computer will do it…the only limit is your skill and imagination!"

Someone didn't learn about the halting problem :-)

------
JacobEdelman
Bonus points: What if only one of them gets a coin to flip and then they must
both come to an agreement on what the result was. They can talk but the NSA
overhears everything they say and can crack every cipher they use. Can you
maximize the chance that the NSA can't guess who got that coin AND Alice and
Bob agree on the correct result?

Note: An open problem. You can look up cryptogenography for current results.

------
bandrami
From the first link: I find it difficult to believe that in the entirity of
Jimmy Carter's Navy career, he wrote zero lines of code.

~~~
cheapsteak
Jimmy Carter aside, what kind of code do navy people write?

~~~
jebblue
During Carter's era or today. In 90 I was trained for a year in computer
engineering for our sonar computer mainframe including Assembly. The idea was
that if we were on deployment and a bug caused a problem we could potentially
figure it out and maybe fix it without stopping the mission. I was programming
on my own for 8 years prior to that as a hobby so was actually correcting the
instructor on a couple of occasions. There is also the rate DT which does
programming all the time I think. I wanted to get into that rate but the wait
was a year and I was impatient.

------
pokstad
Reminds me of Dr Ebert's hat problem:
[http://web.csulb.edu/~tebert/hatProblem/nyTimes.htm](http://web.csulb.edu/~tebert/hatProblem/nyTimes.htm)

------
giltleaf
I think I was slow coming up with this, but basically I wrote a lot of tables
out and came up with...SPOILER...

Alice always guessing the same as what she flips and Bob always guessing
different.

But - my question is this: Are there any other possible solutions to this
puzzle?

Either way, I'm pretty sure this is just an Illuminati code plot from the
White House to find the world's top coders and recruit them into some CIA
program.

------
titanomachy
OK, we get it, most HN readers were able to solve the puzzle in a minute or
two. Most of us have done interview problems much more difficult.

I'm more interested to know what people think about Obama's proselytizing of
computer science. It seems like a great move to me. Is he going about this in
a smart way? Do you think he'll get the results that he's looking for?

------
gigias
It seems too simple to be right, but can Bob just say heads all the time, and
Alice say tails all the time?

~~~
lobe
No, there are two different coins. So if Bob flipped heads (which Alice
guessed tails for) then they lose.

------
noreasonw
I solved (believe) the puzzle in 3 minutes.

A says B result is the same as A result. B says A result is different from B
result,

so that A covers (H,H) and (T,T), B covers (H,T) and (T, H), so always A or B
is true, so they always win.

------
mmcclellan
Just adding the Python test I used:

[https://gist.github.com/mmcclellan/4b01bf781393395526e3](https://gist.github.com/mmcclellan/4b01bf781393395526e3)

------
namelezz
One writes down what s/he sees. The other writes down what s/he does not see.

~~~
JacobEdelman
So, "a paper" and "a gigantic ostrich juggling American Space Kangaroo"?

~~~
namelezz
LOL. Good one!

------
pipermerriam
fun.

[https://gist.github.com/pipermerriam/d1b5a24230f2f9ec4446](https://gist.github.com/pipermerriam/d1b5a24230f2f9ec4446)

~~~
anishathalye
slightly less verbose:

[https://gist.github.com/1751cebe44d88dc7db15](https://gist.github.com/1751cebe44d88dc7db15)

~~~
tmhedberg
`zip toss toss` only produces 2 of the possible outcomes. Try `liftA2 (,) toss
toss` instead.

~~~
Veedrac
There's always [(a, b) | a <\- toss, b <\- toss]. It's not as Haskell-y, but
it's simpler.

------
idohealth
Can't Alice just always pick heads, and Bob always pick tales?

~~~
halter73
This fails if Alice flips heads and Bob flips tails.

------
startupfounder
> The puzzle is this: Can you think of a strategy Alice and Bob can use that
> is guaranteed to win every time?

Raise campaign finance from the wealthy so that they can make it past the
lesterland election[0].

Now that you have a war chest and are in the general election you just need to
raise more capital from the 0.1%, buy more advertising, hire the best staff in
Washington and bam!

I know this is not the coding question at hand, but a more important question
on how unequal our political system is and I couldn't forgo the opportunity to
ever so gently show the obvious reality - once you past the lesterland wealthy
elite and get their backing, winning is only a matter of time.

[0] [http://lesterland.lessig.org/](http://lesterland.lessig.org/)

~~~
happyscrappy
If Lessig's theory is correct then how in the world is pot being legalized?

------
alexashka
If the answer is 'at least one of them always write down "heads or tails"',
then lol

~~~
alexashka
I had assumed there was no real solution and figured it being a clever
semantic play.

I stand corrected, very nice puzzle :)

------
javert
I have zero respect for someone who would take a role like that.

~~~
hkmurakami
So you have no respect for a researcher who took rhe stand against Microsoft
in the Microsoft antitrust case?

~~~
javert
Absolutely. That makes him even worse.

"Antitrust" is a bogus concept.

It is never and was never in the public interest.

It is also a massive violation of the rights of companies and their
shareholders.

Consider that if Windows/IE were really that bad, people would have just
switched more readily to a Microsoft competitor. Desktop-quality Linux would
have come about/come about sooner, or something equivalent.

This is an example of the point that there is no such thing as a monopoly
unless it's created through legal channels (i.e. is granted by the
government).

There is _no business_ that can't be competed against with sufficient capital.

And the global economy accumulates spare capital over time (because in the
net, the species produces more than it consumes).

Even "natural monopolies" are a function of a mistaken way to implement
property rights, as opposed to being "natural." Because you can always build
underneath or around whatever is already there.

edit: This is a serious intellectual comment that deserves to be read. It also
matters a lot for our industry. Consider Google in Europe right now.

~~~
marvy
Ok, I've read it. I agree it is serious. But I think it's also wrong.
Monopolies can be abused in ways that make it almost impossible to compete
against them. Let's use Windows as an example. Some companies that sell
Windows boxes also sell Linux boxes. (Dell for example.) Of course, the Linux
boxes are less popular. But why not sell a computer that can dual boot? People
would be a lot more willing to experiment with Linux if they didn't have to
install it themselves. Indeed, around 1999 a young company was trying to
popularize its new operating system: BeOS. I am quoting from this site:

[http://birdhouse.org/beos/byte/30-bootloader/](http://birdhouse.org/beos/byte/30-bootloader/)

"[...] Be was engaged in enthusiastic discussions with Dell, Compaq, Micron,
and Hitachi. Taken together, pre-installation arrangements with vendors of
this magnitude could have had a major impact on the future of Be and BeOS. But
of the four, only Hitachi actually shipped a machine with BeOS pre-installed.
The rest apparently backed off after a closer reading of the fine print in
their Microsoft Windows License agreements. Hitachi did ship a line of
machines (the Flora Prius) with BeOS pre-installed, but made changes to the
bootloader -- rendering BeOS invisible to the consumer -- before shipping.
Apparently, Hitachi received a little visit from Microsoft just before
shipping the Flora Prius, and were reminded of the terms of the license."

~~~
javert
If Windows started sucking, people would switch. Demand would arise for a
better alternative. In the long run, companies and consumers are not going to
choose a significantly inferior product.

There are no specific examples that will get you out of this.

Actually, it Windows already kinda does suck, which is why so many people
(even companies) use Apple. And there are lots of other alternative OSs.

~~~
jamespo
Unfortunately the example given and the "windows tax" is a perfect example.
Microsoft had such size and control over the industry they could strangle
competitors at birth. Who knows what they would have done without this
tiresome legislation.

~~~
javert
If that were true, Linux, BSD, and Apple OS would not exist.

The only strength that is strong enough to strangle competitors at birth is
the long arm of the law.

In other words, the only way to keep out competition is to use force.

That is precisely what is disallowed in a free market, i.e., in a rights-
respection nation.

------
tempodox
_... Obama [...] became the first president to write a line of code ..._

Wasn't the Dictator of Singapore earlier with his Sudoku?

This is a ridiculous stunt, and it sets the wrong accents. Coding is being
hyped while the people who actually keep us alive and in good condition work 3
jobs and can't afford health insurance.

Meantime, Obama destroys the Constitution and betrays the People of the U.S.
to the NSA and their ilk like none did before. I think I'm getting sick.

~~~
eru
You mean the PM of Singapore? Anyway, they are obviously referring to POTUS's
only. (You can bet eg Dr Angela Merkel wrote some code in her time as well.)

