Hacker News new | past | comments | ask | show | jobs | submit | YogSothoth's comments login

I'm with you alex, I tend to only use classes when I've got to maintain state, I just use a function otherwise. Here's how I'd likely code this ...

  #include <iostream>
  #include <string>
  #include <cmath>
  
  using std::string;
  using std::cout;
  using std::endl;
  
  static bool findRoots(
     double a,
     double b,
     double c,
     double &rootOne,
     double &rootTwo,
     string &errMsg
  )
  {
     if(a == 0.0)
     {
        errMsg = "Parameter 'a' cannot be zero";
        return(false);
     }
  
     double discriminant = b * b - 4 * a * c;
  
     if(discriminant < 0.0)
     {
        errMsg = "Discriminant cannot be less than zero";
        return(false);
     }
  
     double dSqrt = sqrt(discriminant);
     double twoA  = 2 * a;
  
     rootOne = (-b + dSqrt) / twoA;
     rootTwo = (-b - dSqrt) / twoA;
  
     return(true);
  }
  
  int main()
  {
     double a[] = { 0.0, 2.0, 2.0 };
     double b[] = { 1.0, 3.0, 1.0 };
     double c[] = { 2.0, 2.0, 0.0 };
  
     double rootOne;
     double rootTwo;
     string errMsg;
  
     for(int n = sizeof(a) / sizeof(a[0]), i = 0; i < n; i ++)
     {
        cout << "a: " << a[i] << ", b: " << b[i] << ", c: " << c[i] << endl;
  
        if(findRoots(a[i], b[i], c[i], rootOne, rootTwo, errMsg))
        {
           cout << rootOne << " " << rootTwo << endl;
        }
        else
        {
           cout << errMsg << endl;
        }
  
        cout << endl;
     }
  
     return(0);
  }


thank you for your answer, but next time better use something like http://gist.github.com



I was waiting for that! :-P


A buddy of mine showed me a cool trick to avoid this type of problem. What you do is first use SELECT to see the records in question:

   SELECT * from some_table where idx >= 5
Then, once you are staring at the records that came back (and are sure they are the ones you want to delete), change SELECT * to DELETE (and change nothing else) and rerun.

   DELETE from some_table where idx >= 5
Pretty hard to get it wrong with this approach ;-)


Or even better, SELECT(*) FROM some_table - that way the developer won't be tempted to skip the step because of too many records scrolling through their screen... not that I learned that from personal experience or anything ;-)


Definitely second the recommendation of Lilith's Brood, I also found it very moving. I bought it based upon the strength of her (much) earlier short story Bloodchild which I found myself thinking about for weeks after I'd read it.


I'm very interested in how the book affected you. When you say you find it moving, can you describe in what ways?

For me, the word "moving" means that I was emotionally tied to the character(s). When they succeed, I succeed. When one dies, its heart breaking. But that's not how Lilith's Brood affected me. At some deep level I was very disturbed by the overtones of rape and subjugation by the aliens, but that at the same time these creatures loved the humans they bonded with in the same deep way we feel when we love another person. There was a big amount of alienation in that humans in the bondings were physically repulsed to be near each other even though they were deeply in love. That human beings could only be close via the alien partner, there was just something deeply wrong with that.

One of the reasons I respect that novel and can recommend it, but can't love it, is that Octavia Butler did such a magnificent job in telling the story in a way that it makes me feel as I do. That's rare.


Suppose you were a news outlet and suppose you were trying to maximize your company's profitability.

Clearly,when folks change the channel away from your program, your profitability goes down. So, you might do a bit of research to find out what tends to make folks change or not change the channel.

Your research could indicate that strong negative emotions, such as anger, sadness or fear tend to make the viewer fixate and not change the channel.

Finally, you might ask yourself, how should the news be presented so as to maximize profits?

In many cases, a news outlet's profitability is directly related to the amount of emotional distress it can generate in its viewers. Sure isn't something I want to support when looked at that way.


I think you got it - "If it bleeds, it leads". I can't fault them for maximizing revenues, but I'd advise everyone to avoid them, just like you'd avoid a casino or social gaming.


Why can't you fault a company for maximising revenues?


Reminds me of the Kentucky Fried Movie. During a 'commercial break' in the movie, a news caster chimes in with the headlines:

"Moscow in flames, missiles headed to New York, film at eleven"


The answer is always profit.

That doesn't make it okay or good or long termist.


Yep, when I ride my bike in the early morning, I purposefully do not wear light-colored or reflective clothing. I don't want to ever believe for a nanosecond that my safety is anyone's job but mine so I prefer to view the cars as actively trying to hit me and work to make it impossible for them to do so. The relationship (cars and bikes) is fundamentally adversarial in nature, best to act like it.



I cannot think of any exercise that's more likely to build up one's self control over time than meditation. The ability to keep one's attention squarely on the meditation object (typically the breath) for as long as one wishes improves self control and focus immensely over time.

If you've never experienced it, the feeling of having zero thoughts in your head for an extended period of time is just absolutely stunning/amazing/whatever - worth experiencing like you wouldn't believe.


Smacks a bit of Lamarckism doesn't it?

   http://en.wikipedia.org/wiki/Lamarckism


That's true, but I'm not sure that's a bad thing. Epigenetics is a pretty hot topic these couple of years. Straight from Wikipedia:

As reported in MIT's Technology Review in February 2009, "The effects of an animal's environment during adolescence can be passed down to future offspring ... The findings provide support for a 200-year-old theory of evolution that has been largely dismissed: Lamarckian evolution, which states that acquired characteristics can be passed on to offspring."

This was shown to happen in humans and does make intuitive sense - Mealy machines are more efficient than Moore machines!


Like the current folks in congress aren't nearly as smart as the folks who wrote the constitution.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: