From 48b5b55ae0a3b6872b5a01698bf14d33fcb9f97f Mon Sep 17 00:00:00 2001 From: Xavier Fontanet Date: Thu, 20 Jun 2024 21:26:14 +0200 Subject: [PATCH] loop the world forward successful --- src/main/java/cat/hack3/codingtests/marsrover/MarsMap.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/cat/hack3/codingtests/marsrover/MarsMap.java b/src/main/java/cat/hack3/codingtests/marsrover/MarsMap.java index 2c7e772..f962464 100644 --- a/src/main/java/cat/hack3/codingtests/marsrover/MarsMap.java +++ b/src/main/java/cat/hack3/codingtests/marsrover/MarsMap.java @@ -33,7 +33,12 @@ public class MarsMap { var newLongitude = currentPosition.getLongitude(); switch (direction) { case NORTH -> newLatitude--; - case SOUTH -> newLatitude++; + case SOUTH -> { + if (newLatitude+1 > height) + newLatitude=1; + else + newLatitude++; + } case WEST -> newLongitude--; case EAST -> newLongitude++; }