Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 191 192 [193] 194 195 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 887578 times)

MagmaMcFry

  • Bay Watcher
  • [EXISTS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2880 on: September 04, 2012, 06:02:15 pm »

Ooh. Clever :D I just realized that you hashed/stored them in a hash, the words xD

Perl... seems a bit too compactable for comfort D:

I assure you that this is completely readable if you've worked with Perl for a while.

But if you want some more readable programs, here are the most readable programs for various programmer types:

For mere C programmers:
Code: [Select]
my @filenames = ("thisFile", "thatFile", "thisOtherFile");
my %words = ();
my $num_unique = 0;
for (my $i = 0; $i < @filenames; $i++) {
$good = open(READ, $filenames[$i]);
if (!$good) {
die("Couldn't open filename " . $filenames[$i] . ": " . $! . "\n");
}
my $line_of_text;
while (defined($line_of_text = <READ>)) {
my @line_words = split(" ", $line_of_text); # NO I WON'T EXPAND THIS
for (my $i = 0; $i < @line_words; $i++) {
if ($words{$line_words[$i]} != 1) {
++$num_unique;
}
%words{$line_words[$i]} = 1;
}
}
}
print($num_unique);

For Perl beginners:
Code: [Select]
my @filenames = qw(thisFile thatFile thisOtherFile);
my %words;
my $num_unique;
for my $fn (@filenames) {
open READ, $fn or die "Couldn't open filename $fn: $!\n";
while (defined($line_of_text = <READ>)) {
for my $lw (split " ", $line_of_text) {
$num_unique += 1 - $words{$lw};
%words{$lw} = 1;
}
}
}
print $num_unique;

For intermediate Perl programmers:
Code: [Select]
my %words;
for my $fn (@ARGV) {
open READ, $fn or die "Couldn't open filename $fn: $!\n";
while (<READ>) {
%words{$_} = 1 for split " ", $_;
}
}
print scalar keys %words;

For me:
Code: [Select]
++$_{$_} for map {split} <>;
print scalar keys;
« Last Edit: September 04, 2012, 06:25:16 pm by MagmaMcFry »
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2881 on: September 04, 2012, 06:22:50 pm »

ahhhh you're right, I don't know what I was thinking,
I just woke up, sorry

well you'd still have to declare the variable with std::string, :P

Or char*, or char[].

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2882 on: September 04, 2012, 07:11:50 pm »

ahhhh you're right, I don't know what I was thinking,
I just woke up, sorry

well you'd still have to declare the variable with std::string, :P

Or char*, or char[].
well if you wanted to get picky, you could declare it as an int,
:P
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2883 on: September 04, 2012, 08:07:18 pm »

ahhhh you're right, I don't know what I was thinking,
I just woke up, sorry

well you'd still have to declare the variable with std::string, :P

Or char*, or char[].
well if you wanted to get picky, you could declare it as an int,
:P

Or any integral type, or any float type, or a streambuf*, or a function pointer accepting a std::ios, std::ios_base, or std::istream argument, or a void*.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2884 on: September 04, 2012, 11:19:01 pm »

thats what I meant  :-\

Anyways, I switch back and forth from learning c++, and programming little projects with it.
This current project is proving to be a headache, mainly because I haven't learned much of OOP yet, so I'm programming it without any OOP, it's about 2,600 lines long so far and maybe halfway done,
idk if I should press on with it, or stop and learn OOP, but the thing is, since it's already half way done without OOP, I would/should finish it without OOP, or else it would be all....mixed up.
so I think as soon as I finish it, i'm going to start OOP, also on my list of stuff to learn is:
Finish learning c++, (about maybe 1/2 to 4/7 done), and then learn OpenGL (I know SDL pretty well by now) and I got to learn threaded programming, and Network programming.  Soooo much stuff I want to learn

ohh and there is a girl moving in, in a few days, that wants me to teach her c++   >_<
« Last Edit: September 04, 2012, 11:23:12 pm by Valid_Dark »
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #2885 on: September 04, 2012, 11:29:03 pm »

-snip-
You should really be using initializer lists in the classes. They're faster than assigning them in a ctor.

e.g.
Code: [Select]
class SomeClass {
    public:
        int A;
        SomeClass(int a_in): A(a_in) {
            //Other Ctor stuff here
        };
        SomeClass(const SomeClass& other): A(other.A) {
            //Copy ctor stuff here
        };
}
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2886 on: September 05, 2012, 12:12:50 am »

Finish learning c++

BAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA

ohh and there is a girl moving in, in a few days, that wants me to teach her c++   >_<

Teach her Python. It's sexier.

-snip-
You should really be using initializer lists in the classes. They're faster than assigning them in a ctor.

e.g.
Code: [Select]
class SomeClass {
    public:
        int A;
        SomeClass(int a_in): A(a_in) {
            //Other Ctor stuff here
        };
        SomeClass(const SomeClass& other): A(other.A) {
            //Copy ctor stuff here
        };
}

Yes, I know that, but I didn't want to throw too many advanced/unrelated concepts into what was supposed to be a simple explanation. Not that it stopped me, but oh well. I thought about using initializer lists when I was typing it out, but decided not to and instead wait to see who would comment on it first. Congratulations.

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2887 on: September 05, 2012, 01:03:05 am »

Finish learning c++

BAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA

ohh and there is a girl moving in, in a few days, that wants me to teach her c++   >_<

Teach her Python. It's sexier.


I know, that's a laughable statement, basically I mean just finish my C++ book, I'm on page 650 or so out of 1300.
And I don't know python.
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2888 on: September 05, 2012, 02:41:37 am »

Your book doesn't cover half of C++, probably :P I mean, look at all those Boost libraries...

>.> Correct me if I'm wrong.

The crash course on vectors has inspired me to figure out how to actually try and simulate moving ships well, using the short information I picked up from Seamanship Through the Ages, and I discovered how to rotate a dot using trig xD The bad part(s) is that I don't know how this rotating stuff will mesh with a grid-locked graphics thingy. If I want multi-tile ships, and they turn something like 13.5 degrees, there's a small chance a middle portion would disappear. >.>
I also don't know how I would implement the vector-y parts, like how much force the a rudder places on a ship to make it turn, nor how vectors that originate from different parts of the ship interact, nor how exactly I would calculate hits or misses. Grr. >.>

And I haven't touched my IDE yet either :P
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2889 on: September 05, 2012, 03:15:31 am »

Your book doesn't cover half of C++, probably :P I mean, look at all those Boost libraries...

it covers a good amount of the Standard Library, and some low level stuff about how parts of c++ works,
it just doesn't have C++11 in it, because it's from before c++11 came out.

but anyways,
Good luck with your stuff
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2890 on: September 05, 2012, 08:15:47 am »

Your book doesn't cover half of C++, probably :P I mean, look at all those Boost libraries...

it covers a good amount of the Standard Library, and some low level stuff about how parts of c++ works,
it just doesn't have C++11 in it, because it's from before c++11 came out.

but anyways,
Good luck with your stuff

So your book doesn't cover half of C++. C++11 makes me giddy every time I think about it.

ECrownofFire

  • Bay Watcher
  • Resident Dragoness
    • View Profile
    • ECrownofFire
Re: if self.isCoder(): post() #Programming Thread
« Reply #2891 on: September 05, 2012, 11:24:33 am »

C++11 is amazing, but most of its features are basically lifted from Boost libraries. Except for the super awesome Meyer's singleton pattern thing being thread-safe, which was already implemented in GCC.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2892 on: September 07, 2012, 09:37:14 am »

So I got a copy of Microsoft Visual Studio 2010 Ultimate.

._.

Uh ... any nifty features I want to know about? >.>

Also, I was trying to learn SQL earlier today, and it was a new experience. I now wonder what I could do with an SQL database...

I wonder how you can "talk" to a server over the internet...? And how to specify a database to talk to? o_O So many questions. I do know that there's an SQL header file that lets a string in a program be changed to an SQL command and sent to a server, but little more than that.

Also, the vector things a while ago, they got me really thinking xD I think I could write up a class with all the relevant features I might need. I think I'll start with trying to make a normal parabolic flight course... I also think I can make a function that rotates a point by theta radians, with a pivot of another point. :D Trig saves the day!

May I ask what the dot product is used for? >.> I think I forgot.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2893 on: September 07, 2012, 09:58:50 am »

May I ask what the dot product is used for? >.> I think I forgot.

It allows you to compare how close two vectors are pointing. If two vectors are pointing in the exact same direction, the dot product of them is 1. If they're pointing in the opposite direction, the dot product is -1. (I may have mixed 1 and -1 around.) The dot product is 0 when the two vectors are perpendicular. And of course there are all of the values in between.

One example usage I can think of is this: say you have a sentry gun that aims and shoots at things. You have two vectors: the direction to the target, and the direction the turret is pointing. You only want it to shoot when it's aiming at the target.  But you can't just compare if the vectors are equal, it would never work. An excellent solution would be to get the dot product of the two vectors and only shoot when the dot product is over 0.95 or something.

Also: vectors are nothing. Quaternions and 4x4 matrices are where the fun begins.
Logged

Twiggie

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2894 on: September 07, 2012, 10:02:56 am »

May I ask what the dot product is used for? >.> I think I forgot.

It allows you to compare how close two vectors are pointing. If two vectors are pointing in the exact same direction, the dot product of them is 1. If they're pointing in the opposite direction, the dot product is -1. (I may have mixed 1 and -1 around.) The dot product is 0 when the two vectors are perpendicular. And of course there are all of the values in between.

One example usage I can think of is this: say you have a sentry gun that aims and shoots at things. You have two vectors: the direction to the target, and the direction the turret is pointing. You only want it to shoot when it's aiming at the target.  But you can't just compare if the vectors are equal, it would never work. An excellent solution would be to get the dot product of the two vectors and only shoot when the dot product is over 0.95 or something.

Also: vectors are nothing. Quaternions and 4x4 matrices are where the fun begins.
noooo. the dot product is 0 when the vectors are orthogonal. you can use it to find the angle between the vectors, given a.b=|a||b|cos(theta), but it does NOT scale from -1 to 1.

a.b / |a||b| does scale from -1 to 1, since its equal to cos(theta).
Logged
Pages: 1 ... 191 192 [193] 194 195 ... 796