Jump to content

I'm a software engineer, get me out of here: Difference between revisions

→‎{{header|J}}: extra credit -- first draft (need to confirm some issues which may lead to another draft...)
m (→‎Part 1: restore lost definition of "adjacent")
(→‎{{header|J}}: extra credit -- first draft (need to confirm some issues which may lead to another draft...))
Line 548:
One interpretation of this task would be that, for example, "4" means that it takes 6 hours to traverse that map position. Instead, it looks like "4" means we launch ourselves in one of eight directions and land four squares away -- this process takes one day. This concept adds some complexity to the task (we have to make sure we do not launch ourselves off the map, or outside the safe zones), but also reduces the size of intermediate results.
 
=== J Part 1 ===
 
Here's how we can find escape routes for el presidente:<syntaxhighlight lang=J>map=: <:,"_1 {.@>:@".@>>cutLF{{)n
Line 676:
11,11 12,12 13,11 17,15 20,18</syntaxhighlight>
 
=== J Part 2 ===
 
For troop movements, we assume that our troops move in exactly the same way as our president's gold convoy. (Note that this means that no cells are reachable from the safe zone. Which might be why it is the safe zone...)
Line 731:
11,21 10,20 9,19 9,16 9,9 15,3 15,8 15,5 15,2 14,2
12,21 10,19 9,18 8,18 13,13 13,11 17,7 15,5 15,2 14,2</syntaxhighlight>
 
=== J Extra Credit ===
 
Our <code>map</code> is a 23 by 23 matrix of "ranges" -- how far we get launched when we leave the cell at that location on the map. We use _1 to indicate locations which we ignore (spaces). We've preserved the original text of the map in <code>M</code> which is a 23 by 23 matrix of characters.
 
Locations are generally represented by a pair of indices (row, column) into the above structures. But for the floyd warshall algorithm we need a distance graph. To translate between the graph format and the map data structure, we have a list of cells. Cells are a base 23 representation of the row,column indices (In other words 9 represents row 0, column 9, while 23 represents row 1, column 0, and HQ has a cell value of (23*11)+11).)
 
<syntaxhighlight lang=J>Q=: cells i.($map)#.11 11 NB. HQ as a graph index
\:~ ~. HQ{graph NB. all path lengths starting at HQ
_ 6 5 4 3 2 1
($map)#:cells{~I._=HQ{graph NB. can't get there from HQ
2 18
4 3
18 20
($map)#:cells{~I.6=HQ{graph NB. 6 days from HQ
3 19
6 20
17 20
20 14
22 12</syntaxhighlight>
 
=={{header|Julia}}==
6,962

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.