Pseudocode SolutionsPseudocode Solutions

☠️

X Marks the Spot

Week 2, 2026

All Solutions

Pseudocode Canvas | program52 | Pseudocode Solutions

//SET_MAX_EXECUTION_TIME=-1 //run on pseudocode.pro OUTPUT "Ensure you are running on the All Syllabuses/Extra Modules option - also download (https://program52.com/en/challenge/2026/2/map.jpg) the map as map.jpg and drag and drop it into this site" CONSTANT IMAGE_WIDTH = 1280 CONSTANT IMAGE_HEIGHT = 905 CONSTANT HEX_CHARS = "0123456789ABCDEF" TYPE BoundingBox DECLARE x, y, width, height : REAL ENDTYPE CALL CREATECANVAS("map", IMAGE_WIDTH, IMAGE_HEIGHT) CALL DRAWIMAGE("map", "map.jpg", 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT) DECLARE canvasBounds : BoundingBox DECLARE halfImageWidth, halfImageHeight : REAL DECLARE currentStrIndex, prevX, prevY, currentX, currentY, pairIndex : INTEGER DECLARE data, colourCode : STRING DECLARE dataPair : ARRAY[1:2] OF STRING OUTPUT "Paste all program input co-ordinate data:" INPUT data // data ← "" //can assign data to this variable rather than usign INPUT prompt halfImageWidth ← IMAGE_WIDTH / 2 halfImageHeight ← IMAGE_HEIGHT / 2 currentStrIndex ← LENGTH(data) dataPair ← getNextPair() prevX ← halfImageWidth + STR_TO_NUM(dataPair[1]) prevY ← halfImageHeight - STR_TO_NUM(dataPair[2]) // OUTPUT "Start X: ", prevX, " Start Y: ", prevY pairIndex ← 0 WHILE currentStrIndex > 0 DO dataPair ← getNextPair() // OUTPUT dataPair[1], " ", dataPair[2] currentY ← prevY + getMovement(dataPair[1]) currentX ← prevX + getMovement(dataPair[2]) IF pairIndex MOD 50 = 0 THEN colourCode ← getRandomHexColour() ENDIF CALL DRAWLINE("map", prevX, prevY, currentX, currentY, "red", 5) prevY ← currentY prevX ← currentX pairIndex ← pairIndex + 1 // OUTPUT prevX, " ", prevY, " ", currentX, " ", currentY CALL WAIT(1) ENDWHILE OUTPUT "Finished - click the in the middle of the 'X' drawn on the chart and check the console for the output co-ordinates" EVENT CLICK canvasBounds ← GETCANVASBOUNDS("map") OUTPUT "Click location: ", event.x - canvasBounds.x - halfImageWidth, ", ", halfImageHeight - (event.y - canvasBounds.y) ENDEVENT FUNCTION getNextPair() RETURNS ARRAY OF STRING DECLARE arr : ARRAY[1:2] OF STRING DECLARE currentNumStr : STRING DECLARE currentChar : CHAR DECLARE foundSpace : BOOLEAN DECLARE arrayIndex : INTEGER IF currentStrIndex = 0 THEN RETURN arr ENDIF currentNumStr ← "" foundSpace ← FALSE arrayIndex ← 2 WHILE foundSpace = FALSE AND currentStrIndex >= 1 DO currentChar ← MID(data, currentStrIndex, 1) IF currentChar = ' ' THEN arr[arrayIndex] ← currentNumStr foundSpace ← TRUE ELSE IF currentChar <> ',' THEN currentNumStr ← currentChar & currentNumStr ELSE arr[arrayIndex] ← currentNumStr currentNumStr ← "" arrayIndex ← arrayIndex - 1 ENDIF ENDIF currentStrIndex ← currentStrIndex - 1 ENDWHILE RETURN arr ENDFUNCTION FUNCTION getMovement(vector : STRING) RETURNS INTEGER DECLARE dir : CHAR dir ← LEFT(vector, 1) IF dir = 'N' OR dir = 'W' THEN RETURN STR_TO_NUM(RIGHT(vector, LENGTH(vector) - 1)) ELSE RETURN -STR_TO_NUM(RIGHT(vector, LENGTH(vector) - 1)) ENDIF ENDFUNCTION FUNCTION getRandomHexColour() RETURNS STRING DECLARE hex : STRING hex ← "#" FOR n ← 1 TO 6 hex ← hex & MID(HEX_CHARS, INT(RAND(16) + 1), 1) NEXT n RETURN hex ENDFUNCTION