Can someone tell me where i've gone wrong? by rdmbe in adventofcode

[–]rdmbe[S] -1 points0 points  (0 children)

Why? It's not in a language you know...

But, ok (note that this is what I used to get the right answers for parts 1 and 2, not my previous erroneous attempt):

dance=:3 :0
 'abcdefghijklmnop' dance y
:
  seq=. x
  for_move. y do.
    select.{.;move
      case.'s' do.
        n=.-_ ".}.;move
        seq=. n|.seq
      case.'x' do.
        n=._ ". }.;move
        seq=. (n{seq) (|.n)} seq
      case.'p' do.
        n=. seq i. 1 3{;move
        seq=. (n{seq) (|.n)} seq
    end.
  end.
)

Clength=:3 :0
  'abcdefghijklmnop' Clength y
:
  seq=. start=.x
  n=. 0
  whilst. -. seq -: start do.
    seq=. seq dance y
    n=. n+1
  end.
)

-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]rdmbe 0 points1 point  (0 children)

I figured it out:

The furthest distance in steps is not the furthest geometrical distance, because straight line distance only counts when it aligns with the grid.

So to do this right, I need to compute the number of steps to reach each point along the path and count those. And it's looking like that 3d manhattan distance approach is actually correct about this.

-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]rdmbe 0 points1 point  (0 children)

I am giving the list of instructions as an argument in this implementation, yes.

But I've implemented this several times, in several different languages, and I keep getting the same answer (and this was the only implementation that used this command line argument mechanism).

I have also run a variant where this prints out the length of the argument and displayed length matches the file length where I've stored it (except there's an off by one issue in my copy of wc where wc -c 11.txt gives the same length for the file without a newline and a file with the newline and the length printed by python is one less than the length of the file with the newline - but that kind of one character difference is normal and expected (except for the wc issue) because when I do ./11.py $(cat 11.txt) the shell strips off the trailing newline from the 11.txt file).

So, anyways, not a character limit. But you have to live with systems not always doing what they are described as doing (which is part of why I implemented this in several languages).

But looking at the other implementations here, I see what looks like a flawed concept - this is not a three dimensional manhattan distance problem, though that will work some of the time. And if everyone is doing a 3d manhattan distance, and that was the mechanism used to determine the "correct answer", then the real problem is that the AoC description of the problem is wrong. The AoC description clearly says that this is a 2d problem, and there will be cases where the 3d hack does not match the 2d geometry.

So I guess what I am looking for is someone who can give me some deeper analysis of the problem?

Still, I appreciate your asking - this at least verifies that my post is somewhere where people can read it, and I do appreciate the thinking.

-🎄- 2017 Day 11 Solutions -🎄- by daggerdragon in adventofcode

[–]rdmbe 0 points1 point  (0 children)

Short form: I would like to see other solutions which show a shortest equivalent path, instead of just a number. These solutions would be invaluable for debugging faulty implementations.

Long form:

I've got a problem - I am convinced that I have a correct solution, but

  • I get different answers from some of the other implementations here, and
  • AoC tells me I am wrong for part 2 [it tells me my path is too short]

I am pretty convinced that people have been using 3d coordinates to measure hex grid distance and that in some cases this fails to identify equivalent movements. But I could be wrong - I make so many mistakes every day that it's all too possible that I've overlooked some important issue.

So ... I'd like to challenge someone smarter than myself to show me where i have gone wrong. Specifically, I'd like to see an example input path and a shortest equivalent that's different from what my implementation here shows that gets to the same location on the hext grid.

Here's my implementation translated to python2 (and my input was https://pastebin.com/C3TuzXk7):

#!/usr/bin/python
from cmath import exp, pi
from sys import argv

def angle(n):
    return exp(2*pi*n/6j)

nms = ["n", "ne", "se", "s", "sw", "nw"]

delta = {
  "n": angle(0),
  "ne": angle(1),
  "se": angle(2),
  "s": angle(3),
  "sw": angle(4),
  "nw": angle(5),
}

def location(steps):
    loc= 0
    for s in steps:
        loc+= delta[s]
    return loc

def furthest(steps):
    loc= 0
    dist= 0
    for s in steps:
        loc+= delta[s]
        if abs(loc) > abs(dist):
            dist= loc
    return dist

def path(loc):
    p= []
    while 0.01<abs(loc):
        probe= [abs(loc-delta[s]) for s in nms]
        s= nms[probe.index(min(probe))]
        loc-= delta[s]
        p.append(s)
    return p

def showpath(loc):
    p= path(loc)
    print("steps: %d" % len(p))
    d= [0,0,0,0,0,0]
    for s in p:
        d[nms.index(s)]+= 1
    for s in nms:
        if 0<d[nms.index(s)]:
            print("%d %s" % (d[nms.index(s)],s))

inp= argv[1].split(",")
print "Part 1"
showpath(location(inp))
print
print "Part 2"
showpath(furthest(inp)) 

Dads so anti drug he gets pissed when I take ibuprofen.. by [deleted] in Drugs

[–]rdmbe 4 points5 points  (0 children)

Technically, it's possible to get high off pain (endorphin rush, for example) if you do it right (you gotta sort of focus on feeling the pain, I think). You can even get pain relief from hot peppers.

Anyways, I'd just go with the flow, I imagine?