Open Side Menu Go to the Top
Register
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** ** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

10-26-2013 , 01:16 PM
Quote:
Originally Posted by kerowo
I didn't know you were a triny
racist ban
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-26-2013 , 06:01 PM
The bit thing is really cool. I sat down and tried the algorithm with base 2, 3, 4, 10, and lo and behold it all works out. One time about 15 years ago, I heard that there was a proof that no matter how we represented numbers, math would still be math. I never understood what that meant, but after converting things to letters and numbers and different bases, it really seems true. I'm sure the proof is pretty massive, but I like how general it all is. Heck, I could even do base 183756739 and it all works out.

I think that, given the the (+,-) 2 bit-shift, that works out okay, but I'm guessing that if you want generalized, then base ^ power is the way to go, though I guess I can't be sure until I sit down with a pencil and paper.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-26-2013 , 07:58 PM
Hamming..wat lol those dumb PhD folks with no clue about coding amirite?

I really hope there is an alien race with like base 5.23...would be amazing
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-26-2013 , 09:07 PM
I once watched some math stuff that talked about "turning into base x", but the equations were a bit strange.

Given: (12 * 5)
Then "convert to base 10":
(10 + 2) (10 - 5)

And I'm sure you can figure out the rest. Their claim was that you can do this in your head, but of course, this fails when talking about numbers with a large spread.

I created something I think it much better many years ago, and this is how I do quick multiplication in my head, since I don't have to keep track of so many variables.

Everyone's favorite algebraic equation is n = (x + y) (x -y) and from this is birthed a simple idea.

Try 12 * 14
This part is easily done in your head, but the math is (12 + 14) / 2 = 13

Then (13 + 1)(13 - 1) = 13*13 - 1 * 1 => 169 - 1 => 168


Another example:
8 * 16
=> (12*12 - 4*4)
=> 144 - 16
=> 144 - 4 - 12
=> 140 - 12
=> 140 - 10 - 2
=> 130 - 2
=> 128

You may wonder what happens when x/2 is not "whole":
17 * 14
=> (16 + 1) (14)
=> (15 + 1) (15 - 1) - 1 (carry 14)
=> 225 - 1 + 14
=> 224 + 14
=> 238

Of course, it still fails a bit with large numbers, but it is certainly less mental overhead than the original example. I never seen my technique anywhere else.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-26-2013 , 09:15 PM
Quote:
Originally Posted by daveT
I think that, given the the (+,-) 2 bit-shift, that works out okay, but I'm guessing that if you want generalized, then base ^ power is the way to go, though I guess I can't be sure until I sit down with a pencil and paper.
for base n you just change 2 to n

maybe it's more obvious what's going on if you "convert" from base 10 to base 10 in this manner:

Code:
int x = 123
digit_string = list(str(x))
ans = 0

for digit in digit_string:
    ans = ans*10 + int(digit)
    print(ans)
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-26-2013 , 09:25 PM
So, TIL that Ruby has multiple operators that are exactly the same as other operators but with different precedence.

Code:
session['ratings'] = params['ratings'] or session['ratings'] or ratings_hash
# now session['ratings'] is nil but ratings_hash isn't

session['ratings'] = params['ratings'] || session['ratings'] || ratings_hash
# does what I meant
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-26-2013 , 10:03 PM
yeah, that comes from ruby's crazy aunt perl.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 04:01 AM
Quote:
Originally Posted by Xhad
So, TIL that Ruby has multiple operators that are exactly the same as other operators but with different precedence.

Code:
session['ratings'] = params['ratings'] or session['ratings'] or ratings_hash
# now session['ratings'] is nil but ratings_hash isn't

session['ratings'] = params['ratings'] || session['ratings'] || ratings_hash
# does what I meant
Nothing weird about this -- "or" is a control flow that has a very specific use case which is not the one you are attempting above:

Quote:
The best way to think about the chains constructed with or is as series of fallbacks: try this, if that fails try this, and so on.
--http://devblog.avdi.org/2010/08/02/using-and-and-or-in-ruby/

In general ruby, unlike python, provides lots of way to accomplish the same thing (much like vim with all its shortcuts). This can be good or bad depending on the situation and your philosophy. It has the effect of making ruby more powerful and pithy in the hands of an expert but more confusing and prone to error in the hands of a beginner.

Because of its clean, almost English-like syntax and because of the popularity of RoR, Ruby has gotten an unfair reputation for being simple and easy to learn. In fact, it's surface simplicity hides a complex langauge which is quite difficult to learn well.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 07:06 AM
Hey guys, quick question..
I'm trying to write a method to see if a point (x,y) intersects a line which goes from (x0, y0) to (x1, y1)

What I got so far is I check the slope of the line by doing (y1-y0)/(x1-x0)
and then I check the slope of the imaginary line from (x,y) to (x1,y1) by doing (y1-y)/(x1-x)
If the slope of these two lines are the same and x0 <= x <= x1, then (x,y) intersects the line.

An example would be for the point (6.0, 6.0) and the line from (3.0, 4.0) to (9.0, 8.0)
the slope of the line is (8.0-4.0)/(9.0-3.0) = 4/6 = 2/3
and the slope of the imaginary line is (8.0-6.0)/(9.0-6.0) = 2/3
and 3.0 <= 6.0 <= 9.0 holds so (6.0, 6.0) does in fact intersect the line.

But when I check if the point (7.0, 6.66) for example intersects the same line I get that it doesn't intersect the line, even if it does. And I assume this is because the values I get from calculating the slopes of the two lines arent exactly the same, because (8.0-6.66)/(9.0-7.0) doesn't return exactly 2/3.

This might be more of a math question but does anyone have any idea how to do this differently so that I get the right outcome for points in which either the x or y value isn't an integer but a rational number
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 09:58 AM
Quote:
Originally Posted by DirtySprite
Hey guys, quick question..
I'm trying to write a method to see if a point (x,y) intersects a line which goes from (x0, y0) to (x1, y1)

What I got so far is I check the slope of the line by doing (y1-y0)/(x1-x0)
and then I check the slope of the imaginary line from (x,y) to (x1,y1) by doing (y1-y)/(x1-x)
If the slope of these two lines are the same and x0 <= x <= x1, then (x,y) intersects the line.

An example would be for the point (6.0, 6.0) and the line from (3.0, 4.0) to (9.0, 8.0)
the slope of the line is (8.0-4.0)/(9.0-3.0) = 4/6 = 2/3
and the slope of the imaginary line is (8.0-6.0)/(9.0-6.0) = 2/3
and 3.0 <= 6.0 <= 9.0 holds so (6.0, 6.0) does in fact intersect the line.

But when I check if the point (7.0, 6.66) for example intersects the same line I get that it doesn't intersect the line, even if it does. And I assume this is because the values I get from calculating the slopes of the two lines arent exactly the same, because (8.0-6.66)/(9.0-7.0) doesn't return exactly 2/3.

This might be more of a math question but does anyone have any idea how to do this differently so that I get the right outcome for points in which either the x or y value isn't an integer but a rational number
Well the first thing that jumps out to me is what kind of variables are you using? You should be using a floating point rather than int.

Also, I think a much more intuitive way of writing the method would just be to check if the point in question solves the equation of the line.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 10:00 AM
Also what language are you using?

Maybe post some code???
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 10:01 AM
just use some kind of Ratio class, or even a function that, given a fraction a/b, reduces its simplest form
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 11:37 AM
it's gonna be a long semester
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 12:54 PM
DS,

Are you supposed to check whether the point is on the line that passes through the given endpoints, or whether it's specifically on the line segment between them (and not on the line but outside the line segment)?

What happens to your function if the point you're checking is identical to one of the endpoints? What if x0 = x1?

If you can deal in integer ratios that would be ideal, but the practical way of doing the check with floating points would be to add in a small tolerance so that it counts as on the line if it's "close enough".
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 01:04 PM
Quote:
Originally Posted by DirtySprite
Hey guys, quick question..
I'm trying to write a method to see if a point (x,y) intersects a line which goes from (x0, y0) to (x1, y1)

What I got so far is I check the slope of the line by doing (y1-y0)/(x1-x0)
and then I check the slope of the imaginary line from (x,y) to (x1,y1) by doing (y1-y)/(x1-x)
If the slope of these two lines are the same and x0 <= x <= x1, then (x,y) intersects the line.

An example would be for the point (6.0, 6.0) and the line from (3.0, 4.0) to (9.0, 8.0)
the slope of the line is (8.0-4.0)/(9.0-3.0) = 4/6 = 2/3
and the slope of the imaginary line is (8.0-6.0)/(9.0-6.0) = 2/3
and 3.0 <= 6.0 <= 9.0 holds so (6.0, 6.0) does in fact intersect the line.

But when I check if the point (7.0, 6.66) for example intersects the same line I get that it doesn't intersect the line, even if it does. And I assume this is because the values I get from calculating the slopes of the two lines arent exactly the same, because (8.0-6.66)/(9.0-7.0) doesn't return exactly 2/3.

This might be more of a math question but does anyone have any idea how to do this differently so that I get the right outcome for points in which either the x or y value isn't an integer but a rational number

You can do this all with integers and not use a divide given that the size of your integers has enough bits. Play around with the equation of a line and you'll see how you can do this. Hint: you can do this and the constant in the line equation will cancel out.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 03:53 PM
It's written in Java and re EvilSteve I'm supposed to check whether the point is specifically on the line segment between 2 points

Code:
public boolean intersects(Point2D b) 
{
	double m = slope(); //slope of the line
	double d = (left.getY()) - (m*left.getX()); //the y-intercept


 
	if(b.getY() == m*b.getX() + d) return true; 
	else return false;
}
The if condition is equivalent to y = mx+b (equation of a line) and the above function works for points with non floating number coordinates.
But it still won't work properly as soon as I start checking points like (8.0, 7.33) etc. The problem is that the == operater assumes total precision

Last edited by DirtySprite; 10-27-2013 at 04:01 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 03:55 PM
So I haven't posted here much if at all before today. Hello Programming forum!

I've been working through Project Euler to shake off the rust and also to learn Objective-C, although it's been almost entirely C code so far with the exception of using NSString for string handling. Some thoughts on data types.

- I've started using long (64 bit) instead of int (32 bit) for everything. I'll use char for characters and BOOL for booleans but even though those are implemented as integer types, I'm not thinking of them as integers and the typing makes my intent clearer, but otherwise everything is a long. I don't like the idea of having to think about different types of integer so everything is 64 bits. I could see making an exception for very large arrays where memory capacity becomes a concern but in 99% of cases, using multiple integer types and remembering which one I used where feels like a waste of my time.

- Similarly for float, double. I just never use float, always use double. Or is long double the new double and I should go 128 bit all the way for floating point? And as an aside on the type naming, I'd prefer if the names were int32, int64 (or uint32, uint64 if you want unsigned) and float64, float128, etc. It doesn't matter so much to me since I'm only using one type of int, one type of float, but having to remember which types are implemented using which number of bits is kind of annoying. I realize those mappings are system dependent but if I'm writing code that expects an integer to be 64 bits, I like to know that it's actually 64 bits.

- I wish a class similar to Java's BigInteger existed in Objective-C for those rare cases when 64 bit isn't enough (ok so I still can't get completely away from thinking about multiple integer types, but with a 64 bit standard type the occasions when I need to become pretty rare). As far as I know there isn't one, but from this discussion on Stack Overflow I found JKBigInteger which is an Objective-C wrapper class using a C library that does what I want. Nice to have.

- I haven't made one yet but I think I'd like an Objective-C rational number class, and I think I'll implement it using JKBigInteger for numerator and denominator. My rationale is that if I'm going to the trouble of using integer ratios instead of floating point, it must be a situation where I value precision over performance and I don't want to have to think about the possibility of overflowing a 64 bit int numerator / denominator (and then using 64 bit num/denom approximations from there).

Thoughts on any of this?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 04:17 PM
Quote:
Originally Posted by DirtySprite
It's written in Java and re EvilSteve I'm supposed to check whether the point is specifically on the line segment between 2 points

Code:
public boolean intersects(Point2D b) 
{
	double m = slope(); //slope of the line
	double d = (left.getY()) - (m*left.getX()); //the y-intercept


 
	if(b.getY() == m*b.getX() + d) return true; 
	else return false;
}
The if condition is equivalent to y = mx+b (equation of a line) and the above function works for points with non floating number coordinates.
But it still won't work properly as soon as I start checking points like (8.0, 7.33) etc. The problem is that the == operater assumes total precision
The variable naming is confusing since the equation is y = mx + b but you're using d not b for the y intercept (and b for something else). But that's cosmetic.

1. I asked once but what happens with that slope calculation when the x coordinates of the endpoints coincide?

2. Since you're checking for equality of floating point values. Instead of:
if (a == b)

Try:
double tolerance = [0.000000000001 or whatever very small value];
if (a - b < tolerance && b - a < tolerance)

3. You're doing nothing to check that it's specifically on the line segment, based on your code anywhere on the line will do.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 04:29 PM
1. It returns infinity

3. Yes you're right, but it's easy to implement afterwards

Thanks I'll try allowing some tolance

edit: and oh yeah I messed up the variable naming. The equation should indeed be y = mx + d, given how i assigned the variable
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 05:33 PM
Quote:
Originally Posted by DirtySprite
1. It returns infinity

3. Yes you're right, but it's easy to implement afterwards

Thanks I'll try allowing some tolance

edit: and oh yeah I messed up the variable naming. The equation should indeed be y = mx + d, given how i assigned the variable
You absolutely do not need floats or doubles.

Here is a real big hint

y * delta x = delta y * x + b * delta x

Last edited by adios; 10-27-2013 at 05:38 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 05:56 PM
Quick question.

I want to learn how to create a very basic web app for intellectual stimulation, fun and facebook likes. I took a very good intro python class on coursera from Rice University and created this simple blackjack game - http://www.codeskulptor.org/#user15_rmDsG2TVCK_5.py. I want to put something similar to this on a standalone website.

Would going through codecademy.com and taking all the fundamental courses be good enough?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 06:11 PM
Quote:
Originally Posted by jjshabado
http://energycommerce.house.gov/hear...0%99t-disclose

Hilarious for anyone with any knowledge of technology.
I understandably didn't watch the whole thing and attempted to skip to the good parts, but I failed to see the humor. Just a bunch of self-protecting, apparent lack of communication, and the final takeaway that you shouldn't use anything with the initials "CMS."

I'll admit that the TAC hidden in the source code was sort of strange though.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 07:12 PM
Quote:
Originally Posted by daveT
I understandably didn't watch the whole thing and attempted to skip to the good parts, but I failed to see the humor. Just a bunch of self-protecting, apparent lack of communication, and the final takeaway that you shouldn't use anything with the initials "CMS."

I'll admit that the TAC hidden in the source code was sort of strange though.
Maybe we have different sense of humour?

The highlights that I can remember include:

1. Comparing the healthcare website to Facebook and claiming that Facebook cost less and supports hundreds of millions of users so whats wrong with the healthcare implementors.

2. A Republican bitching about there not being enough end-to-end testing and then immediately saying that there's no reason to turn on anonymous browsing immediately aside from politics (even though it wasn't tested).

3. A democrat making fun of the Republicans who kept demanding follow ups by 9am the next day and making it clear to everyone that the deadline was meaningless.

4. The general bull **** comments made by both sides of the aisle about the Shutdown.

5. The just general cluelessness about how code is developed. One Senator claimed that no private company would ever be releasing code regularly. That it would be tested, released, and then never touched.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 07:34 PM
I guess I missed those parts.

It was frustrating to see everyone claim that they did everything up to spec. Of course, all the bugs where due to someone else. If the government wants Facebook, then they should call Zuck up and see what they can do about it, but of course, that would require getting past all the security consultants who wouldn't accept anything but Java applets.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
10-27-2013 , 07:48 PM
Quote:
Originally Posted by gaming_mouse
Because of its clean, almost English-like syntax and because of the popularity of RoR, Ruby has gotten an unfair reputation for being simple and easy to learn. In fact, it's surface simplicity hides a complex langauge which is quite difficult to learn well.
If it makes you feel any better, Ruby seems to be usurping Python as the language du jour for beginning programers, I guess in part because of RoR and the apparent promise of a 6-fig job in 6 months, but from the meetups I've seen, RoR seems to be the goto language for new programmers, especially the women-focused ones. I've read the quote that "you don't need to know Ruby to use RoR" too many times, and it is the main reason I don't want to learn RoR or Ruby.

Interesting Q&A at a meetup I was at:

Q: Do you think Ruby on Rails is loosing ground?

A: Yes, but unfortunately, it is gaining new ground faster than people are abandoning it.

I also think that Python is a wolf in sheep's clothing as well. Then again, I can't imagine that there are any languages without a surprising learning curve.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote

      
m