[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
>>55631938 ^ Fuck this guy QUICK !! CREATE A PROGRAM
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 32
Thread images: 1
File: killer_crow_GG.png (259 KB, 412x430) Image search: [Google]
killer_crow_GG.png
259 KB, 412x430
>>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!
>>
>>55632415
Literally 2d array and then basic distance formula from 6th grade. Are you stupid op?
>>
>>55632671
Do it then faggot
>>
>>55632707
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.
>>
>>55632731
were on board, it casually takes 3 minutes to do the program, you complain for no reason ---> get out nigger
>>
>>55632415
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.
>>
>>55632840
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
>>
>>55632903
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?
>>
>>55632415
>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.
>>
>>55632415
>this is my homework /g/ please do it bitches
>>
>>55632415


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 " << player.to_s
puts "Where do you want to go (u,d,l,r)?"
direction = gets.chomp

case direction
when "u"
if player[1] < 9
player_next[1] = player[1] + 1
elsif
puts "Not possible!"
redo
end
when "d"
if player[1] > 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
>>
>>55632415
http://pastebin.com/PcyGVyn9
In the glorious Rust language
>>
>>55636006
Why are you like this you retarded spermatozoon?
>>
>>55637135

Is there any message or are you just flaming?
>>
>>55636006
What language is this
>>
>>55636598
>Implying any of them are good
filtered
>>
Only 2 people have solved this easy fucking challenge. No wonder /g/ doesn't have a PhD.
>>
>>55632415
^ Fuck this guy = it's me again
Kill yourself faggot
>>
Try the homework board.

>>>/hm/
>>
>>55638263
bazinga.
>>
>>55637729
who needs a phd when u got ghb
>>
>>55629822
/g/ is getting worse, last time they even could calc some fibonacci numbers
>>
>>55636006
that looks disgustingly cute lmao
>>
>>55637643

Ruby

>>55638495

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: >>55636823

But fuck it, this is only /g/, so..
>>
>>55632415

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);
}
}
>>
>>55639337

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..
>>
>>55639834
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.
>>
>>55632731
try solving icpc challenges and then come here to talk shit about how easy they are.
Thread replies: 32
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.