I’ve only worked on the first part, but it was very cool and enjoyable to work on this! I think this is part art, part programmatic poetry and just fun, thank you!
Hello, could you help me please, i did this code
class Player {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
int lightX = in.nextInt(); // the X position of the light of power
int lightY = in.nextInt(); // the Y position of the light of power
int initialTx = in.nextInt(); // Thor's starting X position
int initialTy = in.nextInt(); // Thor's starting Y position
int thorPositionX = initialTx;
int thorPoistionY = initialTy;
String directionX = "", directionY = "";
// game loop
while (true) {
int remainingTurns = in.nextInt(); // The remaining amount of turns Thor can move. Do not remove this line.
// Write an action using System.out.println()
// To debug: System.err.println("Debug messages...");
if (thorPoistionY < lightY) {
directionY += "S";
thorPoistionY += 1;
} else if (thorPoistionY > lightY) {
directionY += "N";
thorPoistionY -= 1;
}
if (thorPositionX < lightX) {
directionX += "E";
thorPositionX += 1;
} else if (thorPositionX > lightX) {
directionX += "W";
thorPositionX -= 1;
}
You have to print your answer in each round. Please read the comments in your code if you do not know how to do it.
By the way, you can format your code properly by using the </> button in the formatting toolbar.
I’m using Javascript. In test case 3 (Easy Angle), Thor moves SW, as he’s supposed to, but he walks outside the barrier and misses his target. Any tips or hints on how to adjust the angle?
You don’t have to output SW for all the turns. You may print W instead when Thor is “south enough”.
// lightX: 31,4 87 87 88
// lightY: 31,4 87 87 88
// initialTx: 17,16 18,17 19,18
// initialTy: 31,4
var lightX, lightY, initialTx, initialTy int
fmt.Scan(&lightX, &lightY, &initialTx, &initialTy)
for {
// remainingTurns: The remaining amount of turns Thor can move. Do not remove this line.
var remainingTurns int
fmt.Scan(&remainingTurns)
// fmt.Fprintln(os.Stderr, "initialtx initialty...")
// A single line providing the move to be made: N NE E SE S SW W or NW
fmt.Println("SE")
this is my code im on language go it looks correct and it gets Thor to move se but not to the power source ;(
can someone help?
You print “SE” and Thor moves SE quite correctly. If you want Thor to move in some other directions, you have to add some code of your own.
Also, your code may be formatted properly if you use the </> button in the formatting toolbar. Your question should be outside the code, unformatted.
hi!
so i fond out that whatever direction that i put in the println Thor would go but whenever i try putting
multiple directions he wouldn’t move
at all .
can you help?
Have you read the hints to the left of the puzzle statement? Those should help you. You are supposed to output one direction per turn, the direction dependent on what the current location of Thor is in that turn.
hi!!
ok, so I figured out the top two, but I still cant figure out the easy angle and optimal angle.
Note that you aren’t restricted to a single direction for all the turns. For example, you may first instruct Thor to go NW/NE/SE/SW, and once Thor is good enough in one of the directions, you may then instruct Thor to go N/W/S/E for the rest of his journey.
Why my code is failling though its correct
var inputs = readline().split(’ ');
const lightX = parseInt(inputs[0]); // the X position of the light of power
const lightY = parseInt(inputs[1]); // the Y position of the light of power
const initialTx = parseInt(inputs[2]); // Thor’s starting X position
const initialTy = parseInt(inputs[3]); // Thor’s starting Y position
var ThorX = linitialTX
var ThorY = initialTY
// game loop
while (true) {
const remainingTurns = parseInt(readline()); // The remaining amount of turns Thor can move. Do not remove this line.
var directionX = "";
var directionY = "";
if (ThorX > lightX) {
directionX = "W";
thorX--;
} else (ThorX < LightX) {
directionX = "E";
thorX++;
}
if (ThorY > LightY) {
direction = "N";
thorY--;
} else (ThorY < LightY) {
direction = "S";
thorY++;
}
Print (directionY + directionX)
}
Because it is incorrect. Check all the variable names again - there are some typos.
By the way, you may format your code properly by using the </> button on the formatting toolbar.
Hello all, I have a quick question and first post on here ever so sorry in advance for formatting errors.
My code is as follows:
light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]
tx = initial_tx
ty = initial_ty
# game loop
while True:
remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line.
dirx = ""
diry = ""
if(ty > light_y):
diry = "N"
ty -= 1
elif(ty < light_y):
diry = "S"
ty += 1
if(tx > light_x):
dirx = "W"
tx -= 1
elif(tx < light_x):
dirx = "E"
tx += 1
print(diry + dirx)
I noticed if I move diry or dirx to the global scope before the while loop the last two tests fail. Why is that?
For example this causes a failed test:
light_x, light_y, initial_tx, initial_ty = [int(i) for i in input().split()]
tx = initial_tx
ty = initial_ty
dirx = ""
diry = ""
# game loop
while True:
remaining_turns = int(input()) # The remaining amount of turns Thor can move. Do not remove this line.
if(ty > light_y):
diry = "N"
ty -= 1
elif(ty < light_y):
diry = "S"
ty += 1
if(tx > light_x):
dirx = "W"
tx -= 1
elif(tx < light_x):
dirx = "E"
tx += 1
print(diry + dirx)
Fairly new to coding and still learning but I am really curious on this one because it genuinely confuses me.
In the last two cases, Thor has to move East/West further than North/South. If you output diry + dirx (e.g. SW) in the beginning turns, you will eventually reach a point where Thor is North/South enough and he doesn’t have to move in that direction again, and you will have to output dirx only (e.g. W).
In your second code, dirx is not reset to an empty string every turn. That means, even after Thor is North/South enough, dirx will still retain the previous value and will not become an empty string by itself. The output will then become wrong.
hello again!
I’m sorry but i do need help again i took a long brake from this app so I’m kind of rusty but I recently got back in it today, so when i but in a direction like E he goes that direction but whenever i put in multiple
directions he wont move at all, its quit frustrating. I’ve tried pretty much everything.
thanks soooo much for everyone’s help I really appreciate it.
What does the console say? Could you mention which case it is, and also copy and paste here your output and the error messages shown in the console?
Hello, can someone explain how this work
while (1) {
int remainingTurns; // The remaining amount of turns Thor can move. Do not remove this line.
scanf("%d", &remainingTurns);
char *directionX = ""; <===== How this work, why pointer to double comma cause, saving places of thor?
char *directionY = "";
if (thorY > lightY) {
directionY = "N"; <===== and how this connects with this double comma N?
thorY--;
Is there a bug in Java version? I have solved this in c# and code working ok
in the 3rd test there are 36 moves to complete the level but in Java there are only 18 moves
so you cant complete the level.
I’m able to solve the Java version of the 3rd test without any issue. There is no bug with that test.