Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 533 534 [535] 536 537 ... 796

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

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8010 on: September 27, 2015, 08:40:41 pm »

...Grr why did i look at this thread now I want to solve this problemmmmmmm....
Right? I told myself "no more than an hour, pal" and then this happened. "Maybe if I go over the logic one more time..."

It's worse because there's a time limit on the actual site.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8011 on: September 30, 2015, 03:53:55 am »

Hey guys I need to write a program for resolving the travelling salesman problem with the use of the greedy algorithm. The program itself is already written in C (as a concole application), but the teacher says it also needs a visualization to be made, that is a complete weighted undirected graph to be drawn on the screen. I know it's impossible to do it in the console window, and I don't possess any knowledge of win32api or anything. I suspect I could draw the graph by the means of the graph unit from Pascal, but in this case I'll have to rewrite the whole program which could be painfully difficult. What do I do?
Try to find a library specifically for printing graphs. igraph looks like it might be what you need.

http://igraph.org/c/doc/igraph-Generators.html
You can create graphs from a list of edges or (weighted) adjacency matrix.
« Last Edit: September 30, 2015, 03:58:46 am by Bumber »
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

RoguelikeRazuka

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8012 on: September 30, 2015, 09:02:06 am »

Hey guys I need to write a program for resolving the travelling salesman problem with the use of the greedy algorithm. The program itself is already written in C (as a concole application), but the teacher says it also needs a visualization to be made, that is a complete weighted undirected graph to be drawn on the screen. I know it's impossible to do it in the console window, and I don't possess any knowledge of win32api or anything. I suspect I could draw the graph by the means of the graph unit from Pascal, but in this case I'll have to rewrite the whole program which could be painfully difficult. What do I do?
Try to find a library specifically for printing graphs. igraph looks like it might be what you need.

http://igraph.org/c/doc/igraph-Generators.html
You can create graphs from a list of edges or (weighted) adjacency matrix.

Thanks! That's much appreciated. I've already handled it with the help of SDL, and If the teacher says it's not acceptable for whatever reason, I'll try this one (not sure about how it's possible to display graphs created with this library).
« Last Edit: September 30, 2015, 09:15:07 am by RoguelikeRazuka »
Logged

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8013 on: September 30, 2015, 09:19:04 pm »

What does object oriented programming do?

Also I was wondering how I could use a range in C++. I have an assignment where i'm suppose to have telephone rates for long distance calls.

For example from 00:00 to 06:59 the rates are .12 per hour. However what would happen if someone started at 06:00 and ended their call at 07:00? Well then I'd have to charge the first rate of .12 cents per hour and then a .37 cent per hour for the second hour. In my head it'd be something like this:

06:00 for 1 hour  = X(.12)
07:00 for 1 hour = X(.37)

My problem is getting that to display in a compiler. I have an idea of playing around with If statements but i'm having trouble visualizing this also. Any tips?

((No straight answers please. I'm trying to think harder about problems so I can be a better critical thinker.))
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8014 on: September 30, 2015, 09:38:53 pm »

What does object oriented programming do?

?

That's a very broad question. I think the answer is approximately "everything computable".

Anyway, ranges in general are represented in math by 0<x<7. In programming, that often doesn't work (there are languages that support that, but C++ is not one of those). Instead, you want to use something more like:

Code: [Select]
if (0<x and x<7) {
  //stuff
};

i haven't written C or anything too like it in a LONG time, so that if statement could be malformed, but I think the message goes through
« Last Edit: September 30, 2015, 09:42:24 pm by Putnam »
Logged

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8015 on: September 30, 2015, 09:43:52 pm »

Object oriented programming is really a way of organizing your program, and there are language features designed to support that.

Objects are a way of collecting variables together, and also adding functions that do something to that object. The template for an object is called a "class". you make a class, then create objects of that class.

One example would be a "Circle" class:

class Circle
{
   int radius;
   int x;
   int y;
   void Draw();
}

Then, you can make a bunch of circles as if they were regular data types:

Circle a;
Circle b;
a.x = 44;
a.y = 88;
a.radius= 100;
b.x = 25;
b.y = 120;
b.radius = 50;
a.Draw();
b.Draw();

^ this would create the circles and draw both of them

Another thing is that you can make a "Shape" class, which only declares the "Draw" function. Then, each actual shape (Circle, Triangle, Square, Rhombus) is declared as a child class of "Shape, but they have their own variables and implements the Draw function. e.g. only a circle has a "radius", that has no meaning for a triangle.

You can then put various "Shapes" into a list and loop through them, calling Draw for each one without needing to know which type each one is.
« Last Edit: September 30, 2015, 09:46:59 pm by Reelya »
Logged

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8016 on: September 30, 2015, 09:46:43 pm »

That last paragraph only works if the language supports duck typing, right?

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8017 on: September 30, 2015, 10:07:49 pm »

Yeah, C++ allows it too but it works a little differently under the hood.  Duck typing kind of implies that the language allows purely abstract or dynamically structured objects, but in C++ anyway you can only call a method on a list of objects if they all have the method as part of their definition.  Furthermore, since C++ has no global base class, you usually can only make lists / vectors of a single class and any inherited children anyway.
Logged
Through pain, I find wisdom.

Bauglir

  • Bay Watcher
  • Let us make Good
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8018 on: September 30, 2015, 10:35:40 pm »

That last paragraph only works if the language supports duck typing, right?
I think the last paragraph works without duck typing. With duck typing, however, if for some reason you wanted to, you could define a unique draw() method for each shape, and do away with the Shape class entirely. Alternatively, if the draw() method is defined in a Shape class, and needs to call functions defined inside the shape subclasses, and there's no guarantee they actually exist, then duck typing would be necessary.

I think.
Logged
In the days when Sussman was a novice, Minsky once came to him as he sat hacking at the PDP-6.
“What are you doing?”, asked Minsky. “I am training a randomly wired neural net to play Tic-Tac-Toe” Sussman replied. “Why is the net wired randomly?”, asked Minsky. “I do not want it to have any preconceptions of how to play”, Sussman said.
Minsky then shut his eyes. “Why do you close your eyes?”, Sussman asked his teacher.
“So that the room will be empty.”
At that moment, Sussman was enlightened.

Reelya

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8019 on: September 30, 2015, 11:30:49 pm »

Strictly, duck typing dynamically types things based on their interface only. i.e. a things "type" is determined by how it acts.

C++ allows this through templates, but c++ inheritance is strictly not duck typing, as what you can do with the children is determined by their type, not by their interface. If it was duck typing, then things with disparate unrelated classes are interchangeable, which is only true of things used as template parameters. As a result, C++ has compile-time duck typing, but not at runtime.
« Last Edit: September 30, 2015, 11:34:11 pm by Reelya »
Logged

i2amroy

  • Bay Watcher
  • Cats, ruling the world one dwarf at a time
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8020 on: September 30, 2015, 11:56:19 pm »

Honestly I've always seen duck typing as sort of taking a step from object oriented programming back in the other direction. In OO programing everything pretty much revolves around the classes and the inheritance between them. We make functions aimed at this class or that one, specifically (which automatically includes all of the classes that inherit from them). On the other hand duck typing is aimed at making functions based not on the actual class itself as normal in OO, but rather what methods you stick in them.

It's still OO programming at the root, of course, but I'd say that it's slightly less OO than many other things.
Logged
Quote from: PTTG
It would be brutally difficult and probably won't work. In other words, it's absolutely dwarven!
Cataclysm: Dark Days Ahead - A fun zombie survival rougelike that I'm dev-ing for.

Bumber

  • Bay Watcher
  • REMOVE KOBOLD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8021 on: October 01, 2015, 01:33:27 am »

Thanks! That's much appreciated. I've already handled it with the help of SDL, and If the teacher says it's not acceptable for whatever reason, I'll try this one (not sure about how it's possible to display graphs created with this library).
Well, the Google image results for igraph look promising at any rate.
Logged
Reading his name would trigger it. Thinking of him would trigger it. No other circumstances would trigger it- it was strictly related to the concept of Bill Clinton entering the conscious mind.

THE xTROLL FUR SOCKx RUSE WAS A........... DISTACTION        the carp HAVE the wagon

A wizard has turned you into a wagon. This was inevitable (Y/y)?

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8022 on: October 02, 2015, 08:18:03 am »

The Eval That Men Do (pdf) is a very punny article.

Subsections are titled...

See no Eval, Hear no Eval
True Eval
The Nature of Eval
The Root of All Evals
The Face of Eval
The Power of Eval
Necessary Eval?
The Eval Within


Also, I thought to myself today: if you are getting segfaults in the Python standard library, you should step back and think about how you got here and re-evaluate your life decisions.
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

breadman

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8023 on: October 02, 2015, 02:16:23 pm »

Also, I thought to myself today: if you are getting segfaults in the Python standard library, you should step back and think about how you got here and re-evaluate your life decisions.

I did that once.  Using the %z (timezone) sequence in datetime formatting would segfault.  I reported a bug, was asked to submit a gdb stack trace, and discovered some very odd conditions.  Nothing was obviously wrong with the python C code, so I'm guessing a compiler bug was to blame.  But yes, my life decisions:
  • Buy a cheap second-hand computer
  • Install Linux
  • Install LFS
  • Apply the Smashing Stack Protector patch to GCC
Could that patch have been to blame?  Or was it protecting me from a more insidious bug?
Logged
Quote from: Kevin Wayne, in r.g.r.n
Is a "diety" the being pictured by one of those extremely skinny aboriginal statues?

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8024 on: October 02, 2015, 04:11:59 pm »

It's harder to do dangerous things in languages like Python, but in my experience at least, causing crashes inside of the standard library of a language is caused by performing some kind of memory corruption.

As an example, I've stepped over the end of an array in C++ and somehow ended up with crashes in the destructor of the std::string class where I wasn't even doing any dynamic allocations of std::strings.  That took a while to track down, since Valgrind didn't even help because I stepped over the end of a stack allocated array.

I don't know what that particular patch for GCC does, but it sounds like it definitely could be responsible.  It's possible that Python's runtime might do some dangerous looking things with the stack for efficiency reasons that the patch trips over.  I seem to recall that the C++ std::string would do things like that in some versions and cause Valgrind to flip out because it detected what it thought were illegitimate memory reads and writes.

Might be worth trying to reinstall GCC and not apply the patch to see if it helps?
Logged
Through pain, I find wisdom.
Pages: 1 ... 533 534 [535] 536 537 ... 796