

Lattice Quadrilaterals on Project Euler - aabalkan
http://projecteuler.net/problem=453

======
ClayFerguson
Mind blower #2: How many different shapes can a brain with 4 neurons
recognize? 94. Evolution of vision neurons actually would have started out
using a "chance built" circuit that could solve this 94-item 'recognition'
problem. Then the DNA that solved the 94 would run repeatedly to recursively
form the rest of the retina, giving the brain higher resolution, but using
only one 94-pattern-solving DNA recursively. I think the major advancements in
neural nets will come about once we start "wiring up" brains in interesting
ways like this rather than the current "layer training" approach...The brain
is recursive, and needs recursive wiring to be simulated.

------
thearn4
Basically, you're looking for the rectangular equivalent of A189414
([http://oeis.org/A189414](http://oeis.org/A189414)).

Tricky problem, even for PE. I started to retool some earlier success with it
towards a quasi-DP approach, but have since got caught up in other things.

------
throwaway_yy2Di
Suggestion: use rot13 if you say anything potentially spoiler-y.

~~~
throwaway_yy2Di
Frgf bs sbhe cbvagf ba gur ynggvpr qvivqr vagb sbhe qvfgvapg tebhcf:

1) Gubfr jvgu n ercrngrq cbvag

2) Gubfr jvgu ng yrnfg bar tebhc bs cbvagf ylvat pbyvarne

3) Gubfr jvgu bar cbvag va gur (fgevpg) vagrevbe bs n gevnatyr bs gur bgure
guerr

4) Gubfr juvpu ner rdhny gb gurve pbairk uhyy

Lbh genafvgvba sebz (3) gb (4) ol zbivat gur vagrevbe cbvag bhg hagvy vg uvgf
gur rqtr bs gur gevnatyr (glcr (2))), naq shegure hagvy vg rkgraqf gur pbairk
uhyy, vagb n dhnqevygreny (4).

~~~
throwaway_yy2Di
Gubfr bs glcr (4) lvryq bar cbyltba bs gur glcr gur ceboyrz fcrpvsvrf -- n
pbairk dhnqevyngreny. Nalguvat ryfr jbhyq sbepr n yvar pebffvat.

Gubfr bs glcr (3) nqzvg rknpgyl guerr cbyltbaf (aba-pbairk).

(1) naq (2) tvir lbh abguvat.

~~~
throwaway_yy2Di
Bofreingvba: Gurer'f ~83 zvyyvba ynggvpr-nyvtarq evtug gevnatyrf, zbqhyb
genafyngvba. Lbh pna rnfvyl rahzrengr gubfr naq pnyphyngr xrl cebcregvrf, (v)
gur ahzore bs ynggvpr cbvagf ba rnpu bs gurve rqtrf, naq (vv) gur ahzore bs
ynggvpr cbvagf ba gurve vagrevbe.

Bs pbhefr vg'f rnfl gb nppbhag sbe genafyngvba: gurer'f (O+1-N) genafyngvbaf
bs fbzrguvat bs jvqgu N va na vagreiny bs jvqgu O. Fb (oebnqyl), lbh pna pbhag
gur cbffvovyvgvrf vaibyivat jvqgu-N bowrpgf, naq whfg zhygvcyl gung pbhag ol
O+1-N.

~~~
throwaway_yy2Di
Rahzrengvat gur pnfrf; nal sbhe cbvagf qrsvar n erpnagthyne "uhyy":

[(zva n_k, znk_k)] K [zva n_l, znk n_l)]

('n' enatvat bire gur sbhe cbvagf)

Va gur pnfrf bs vagrerfg (3) be (4), ng yrnfg guerr bs gur cbvagf yvr ba gur
rkgrevbe rqtr bs guvf uhyy. Vs (naq bayl vs) nyy sbhe qb, vg'f pnfr (4). Gur
pbhag bs cbyltbaf sebz guvf vf fvzcyl gur pbhag bs havdhr frgf bs 4-cbvagf
ylvat ba fhpu erpgnatyrf (pbzovangbevny sbezhyn: ovt grez vf N^2 O^2 (bar ba
rnpu rqtr -- # vf whfg gur cebqhpg bs rqtr yratguf), cyhf gur pnfrf jurer
cnvef bs cbvagf ner ba gur fnzr rqtr (funer k- be l-) (cbffvoyl _gjb_ cnvef --
guvax (2,0) (1,0) (0,1) (0,2)), zvahf gur pnfrf jurer gurl uvg gur fnzr
pbeare).

Va gur bgure pnfr, (3), guerr bs gur cbvagf ner ba gur erpgnatyr uhyy
(cbffvoyl jvgu n cnve ba gur fnzr rqtr). Va rnpu pnfr, gur vagrevbe ertvba vf
gur fhz+qvssrerapr bs frireny evtug gevnatyrf. Fb vs jr xrrc n ybbxhc gnoyr bs
gur ~83 zvyyvba eryrinag evtug gevnatyrf, jr unir na B(1) pnyphyngvba sbe gur
# bs cbvagf ba gur vagrevbe. (Jr trg guerr fbyhgvba cbyltbaf sbe rnpu bs
gubfr, bar sbe rnpu cbvag vafvqr gur erpgnatyr ohg bhgfvqr gur gevnatyr, naq
abar sbe gur barf juvpu yvr ba na rqtr).

Fb gung'f n fznyy B(1) pnyphyngvba sbe rnpu erpgnatyr. Jr pna whfg rahzrengr
guebhtu nyy erpgnatyr fvmrf (nyfb ~83 zvyyvba) naq gung'f vg.

~~~
throwaway_yy2Di
Ph'nglui Mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn!

------
susi22
Btw, the problem was solved by 61 people so far.

Random thoughts:

I think the mod is just there to distract or for hinting that you shouldn't
come up with a brute force method.

Observations:

1\. Assume an infinite grid. Add 3 random points _not_ on a line. Clearly,
they'll be a convex set (a triangle).

2\. Add a 4th point such that it is not on an existing line.

You've now a quadrilateral.

So for the case of Q(2,2) = 94 = choose(9,4) - 32. 32 is the number of points
that would make 3 of the 4 points lie on a line.

Come up with a recurrence relations and solve it.

~~~
throwaway_yy2Di
_You 've now a quadrilateral._

Or possibly three. If one point is in the interior of the other three, you get
three different, nonconvex quadrilaterals.

------
ClayFerguson
Traveling Salesman Problem... Will this algorithm work?

Algorithm:

1) Take a square space and divide it into 4 squares.

2) Find all 94 quadrilaterals that the 'nodes' can form.

3) For each quadrilateral, that has points in common with the original, do
recursion (I.e. go to step #1 for each of the 94)

4) Keep repeating until some minimal square size (resolution) is reached.

Find the path with the shortest 'Error' and that's an approximation to the
traveling salesman problem.

'Error' is defined as the sum of the distances of all travel waypoints to the
nearest quadrilateral path line.

------
Bootvis
I've solved about 60 problems on Project Euler but I've no clue about problems
where a mod suddenly shows up in the question. How do these type of questions
work?

~~~
thearn4
Usually, it either implies a possible simplification step (using something
like Fermat's little theorem), or its to reduce a huge answer to a range that
can feasibly be pasted into the input element on their site.

~~~
Someone
It also may mean that there is some recurrence relation in a sequence that

For example, the Fibonacci sequence, taken modulo 3 repeats every 8 numbers:

    
    
       1  1  2  3  5  8 13 21 34 55 89
       1  1  2  0  2  2  1  0  1  1  2
    

That makes it easy to answer such questions as "What is fib(3567^368857) mod
3?". Just compute 3567^368857 mod 8, and be careful to do the lookup right.

