>>55631938

^ Fuck this guy

QUICK !!
CREATE A PROGRAM THAT MUST

CREATE OBJECT IN AN AREA OF 10x10 SQUARES AND A PLAYER MUST MOVE TO FIND THIS OBJECT, EACH STEP PLAYER MADE YOU MUST TELL IF HE'S "Cold" or "Hot" (FAR OR CLOSE)

OR THIS BIRD WILL KILL YOU!

Other urls found in this thread:

pastebin.com/PcyGVyn9
twitter.com/SFWRedditGifs

Literally 2d array and then basic distance formula from 6th grade. Are you stupid op?

Do it then faggot

I spend my time programming useful shit and contributing to open source software instead of doing programming challenges designed for people who dont know how to program.

were on board, it casually takes 3 minutes to do the program, you complain for no reason ---> get out nigger

Determine what 'cold' or 'hot' means and calculate the distance between the player's point and the object's point and check it against the cold or hot values. Not even worth writing code for honestly, just a waste of time to do so. Even the solution to the problem takes all of 30 seconds to think about and figure out.

Just check the points around the object to detect and tell if the player is here or not, you don't need to calculate the distance for no fucking reason

You want to check every single point around the object as far as the 'hot range' as opposed to doing a single numerical calculation? The fuck?

>OR THIS BIRD WILL KILL YOU!

holy fucking shit its OR THIS BIRD WILL STAB YOU!

atleast get this fucking meme right.

You fucking suck at this op, kill yourself, beyond having a fucking easy problem to solve you fuck up the meme.

>this is my homework Sup Forums please do it bitches

This is far from beautiful, but it seems to work..

object = rand(9), rand(9)
player = rand(9), rand(9)
player_next = [player[0], player[1]]
tries = 0

until object == player do

puts "You are at " 0
player_next[1] = player[1] - 1
elsif
puts "Not psosible!"
redo
end
when "l"
if player[0] > 0
player_next[0] = player[0] - 1
elsif
puts "Not possible!"
redo
end
when "r"
if player[0] < 9
player_next[0] = player[0] + 1
elsif
puts "Not possible!"
redo
end
else
puts "Please enter u, d, l or r."
redo
end

tries += 1
if (player[0] - object[0]).abs < (player_next[0] - object[0]).abs \
|| (player[1] - object[1]).abs < (player_next[1] - object[1]).abs then
puts "colder"
elsif (player[0] - object[0]).abs > (player_next[0] - object[0]).abs \
|| (player[1] - object[1]).abs > (player_next[1] - object[1]).abs then
puts "warmer"
else
puts "the same"
end

player[0] = player_next[0]
player[1] = player_next[1]
end

p "You won in #{tries} turns!"

Why are there so many copycat bird threads lately?
And why can't they even get the opening post right?

>still not the good knifebird poster
fuck off

pastebin.com/PcyGVyn9
In the glorious Rust language

Why are you like this you retarded spermatozoon?

Is there any message or are you just flaming?

What language is this

>Implying any of them are good
filtered

Only 2 people have solved this easy fucking challenge. No wonder Sup Forums doesn't have a PhD.

Bump

^ Fuck this guy = it's me again
Kill yourself faggot

Try the homework board.

bazinga.

who needs a phd when u got ghb

Sup Forums is getting worse, last time they even could calc some fibonacci numbers

that looks disgustingly cute lmao

Ruby

Ehem, it's disgusting, I know.
Just a "quick and dirty" version without OOP or anything..

I could have made more abstraction, i.e. I really like this version here: But fuck it, this is only Sup Forums, so..

NO CROW YOU CAN'T HAVE MY KNIFE GIVE IT BACK CROW

r8 lads. OOP represent
void Main()
{
Random randomInstance = new Random();

Vector2 treasure = new Vector2
{
X = randomInstance.Next(11),
Y = randomInstance.Next(11)
};

Vector2 playerPosition = new Vector2();
float lastLength = float.MaxValue;

do
{
Console.WriteLine("You are at " + playerPosition + ". What's your next move?");
string input = Console.ReadLine();

switch (input)
{
default:
Console.WriteLine("That's not a direction!");
continue;
case "n":
if (playerPosition.Y > 0) playerPosition.Y--;
break;
case "s":
if (playerPosition.Y < 10) playerPosition.Y++;
break;
case "w":
if (playerPosition.X > 0) playerPosition.X--;
break;
case "e":
if (playerPosition.X < 10) playerPosition.X++;
break;
}

float newLength = (treasure - playerPosition).LengthSquared();

if (newLength < lastLength) Console.WriteLine("Warmer!");
else Console.WriteLine("Colder!");

lastLength = newLength;
} while (playerPosition != treasure);

Console.WriteLine("You won! The treasure was at " + treasure);
}

struct Vector2
{
public float X;
public float Y;

public float LengthSquared()
{
return X*X + Y*Y;
}

public static Vector2 operator -(Vector2 left, Vector2 right)
{
return new Vector2()
{
X = left.X - right.X,
Y = left.Y - right.Y,
};
}

public static bool operator ==(Vector2 left, Vector2 right)
{
return left.X == right.X && left.Y == right.Y;
}

public static bool operator !=(Vector2 left, Vector2 right)
{
return left.X != right.X || left.Y != right.Y;
}

public override string ToString()
{
return string.Format("({0}, {1})", X, Y);
}
}

This is C#, right?
Well, since you asked for feedback..
I think it's generally good, just two points:

At the switch-statement you write:
switch (input) {
case "n":
if (playerPosition.Y > 0) playerPosition.Y--;

That's not really OOP, since you didn't encapsulate the data. An OOP version would rater use a setter:
try
{
playerPosition.move("n")
}
catch (Exception e)
{
Console.WriteLine("You can't move there!");
}


..with the "move"-method within the Vector2 struct. Other wise I could just write playerPosition.X = 5000


..and OOP wants to prevent such things.


At another point, you wrote:
float newLength = (treasure - playerPosition).LengthSquared();

As I understand it you create a new instance of "Vector2" only to calculate the distance between two other "Vector2" structs, and than you just throw the new instance away?

That's a a lot of wasted ressources..

Better would changing the method "LengthSquared" like that:
public float Distance(Vector2 target)
{
return (this.X * target.X) + (this.Y * target.Y);
}


No need to crete a new instance of Vector2 here..

Thanks senpai.

A try/catch is slower than just comparing values, I didn't want to go full enterprise mode for a simple challenge.

You're absolutely right about the length thing, I kinda overlooked that.

try solving icpc challenges and then come here to talk shit about how easy they are.