Problem 73 - hexagonal grid

Back to Problem Solutions forum

andrewdanine     2021-09-10 22:09:53

Is this problem broken? The test cases make no sense, how can the distance be a decimal number? How can I possibly 2 and slightly more than half hexagons to get to the origin?

Rodion (admin)     2021-09-11 05:12:45
User avatar

Andrew, Hi!

Is this problem broken?

...yet solved by 700+ people, as I see... probably, not broken :)

The test cases make no sense, how can the distance be a decimal number?

It's euclidean distance, not count of steps. Let's add this small clarification to the problem statement.

andrewdanine     2021-09-12 20:43:31

So how do you find this? When I tried to google for it, it requires the height and width of the hexagons.

https://stackoverflow.com/questions/20290140/calculate-grid-distance-between-hexagons

Rodion (admin)     2021-09-13 05:58:54
User avatar

it requires the height and width of the hexagons

sure :) and you should be able to figure out whatever dimensions of hexagons you like from the statement:

distance between centers of two adjacent cells (i.e. sharing a side) is 1.0

andrewdanine     2021-09-13 16:40:26

The height and width is 1x1 in that case, right? If so it doesn't work with the formulas I could find. I might be really dumb or something but some of these feel far more like math questions than programming questions...

Rodion (admin)     2021-09-13 17:06:30
User avatar

The height and width is 1x1 in that case, right?

No, I don't thinks this could be completely true as hexagon is not square! Simply "width and height" of hexagon are somewhat bewildering terms, you'd better avoid using them.

I might be really dumb or something

No, I guess it's all right with you :) Just take pencil and paper, draw few hexagons as a part of such grid, mark distances of 1.0 between their centers... Scrap some bits of school geometry and most probably that would help. Feel free to share your drawing if further hints are needed!

You see, it's a good example that answer at forum can give hint, but not necessarily understanding...

more like math questions than programming questions...

I'd say geometry... But dealing with graphics interface in programming, especially games, usually requires some minimal calculations, right. You will probably agree that programming "in abstract" unrelated to any real-world field is not always well-paid... :)

By the way generally there is nothing bad in skipping the problem to return to it later!

Please login and solve 5 problems to be able to post at forum