Rashakil Fol 978 Super Senior Demiposter Team Colleague

The sieve of eratosthenes is slower than trial division. It takes Omega(n log n) operations when implemented naively, and Omega(n) operations with the best algorithm, which is just as good as trial division-based factorization.

StuXYZ commented: Sorry I was wrong, thanks. +3
Rashakil Fol 978 Super Senior Demiposter Team Colleague

This is a pretty easy assignment.

void main(int args) {
    cout >> "xxxxxxx\nx     x\nx xxx x\nx x   x\nx xxxxx\nx      \nxxxxxxx\n";
}
Murtan commented: I like it. (Its not what he wanted, but I like it anyway.) +3
Rashakil Fol 978 Super Senior Demiposter Team Colleague

This is the most retarded thread I have ever read.

Ezzaral commented: Nailed it on the head. +16
Rashakil Fol 978 Super Senior Demiposter Team Colleague

how thats really complicated. I 'm only a beginner. maybe this problem in project euler is not for me.
Thanks for your help

He made it waaay unnecessarily complicated.

#include <iostream>
#include <vector>

std::vector<int> mulTwo(const std::vector<int>& v) {
  std::vector<int> builder;
  int carry = 0;
  for (int i = 0; i < v.size(); ++i) {
    int s = v[i] * 2 + carry;
    carry = (s >= 10);
    builder.push_back(s[i] - 10 * carry)
  }
  if (carry)
    builder.push_back(1);
  return builder;
}

int sum(const std::vector<int>& v) {
  int sum = 0;
  for (int i = 0; i < v.size(); ++i)
    sum += v[i];
  return sum;
}

int main() {
  std::vector<int> n(1, 1);
  for (int i = 0; i < 1000; ++i) {
    n = mulTwo(n);
  }
  std::cout << sum(n);
}
iamthwee commented: exceeeeeeeeelent +17
Rashakil Fol 978 Super Senior Demiposter Team Colleague

F(N) = O(G(N)) reads that F of N is Big O of G of N

That's not a "solid definition", that's a description of how you read the notation out loud.

F(N) = O(G(N)) if there exist two constants c and k such that F(N) <= cG(N) for all n >=k

Now that's a solid definition. It means what it says: There are two numbers c and k, where it's true that if n >= k, then F(n) <= c*G(n).

Let's see how we might come up with this definition.

Suppose we want to have a few rules to follow whereby we can say that the function "g" is no bigger than the function "f". We could go with the following:

> "g <= f provided that for all real numbers x, |g(x)| <= |f(x)|"

Now, the trouble with that definition, practically speaking, is that most typical functions are then incomparable. There are places where |x^2| is greater than |x| and places where |x^2| is less than |x|. Also, it isn't useful at all to say that the function x -> 3x is any bigger than the function x -> 2x. These two functions are separated by a constant multiple, and that could be an artifact of how the code is written and what our definition of a "single instruction" is -- a constant factor can be corrected by getting hardware that's slightly faster, or a compiler that's slightly better. The important part is that …

darkagn commented: Excellent description +3
Rashakil Fol 978 Super Senior Demiposter Team Colleague

> How exactly are you expecting to talk to the system or any peripherals without making a call to the OS?

On some operating systems and some devices, you can do just that.

Freaky_Chris commented: lmao +2
Rashakil Fol 978 Super Senior Demiposter Team Colleague

You can figure out your first problem just by looking at your results. You're not printing the last 1 of each row. Why? Well, you're stopping too early in your loop that prints out the row's numbers.

For your second problem, if you temporarily added a few cout statements that showed the numbers you're adding, you'd see your problem very quickly.

You might not have to go through this effort -- I'm sure some shmuck will come along to tell you exactly what's wrong with your code.

cherryteresa commented: Guided me in the right direction. +1
Rashakil Fol 978 Super Senior Demiposter Team Colleague

csc is not in your path. Add the directory in which csc lives to your PATH environment variable.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

The IRC profanity filter has gone out of control.

<Rashakil> sss _ss
* DaniBot sets ban on *!*@dani-5F79DBC3.dyn.optonline.net
* You have been kicked from #DaniWeb by DaniBot (Watch your language!)
* Cannot join #daniweb (You are banned).

First of all, how is sss _ss profane? Second, why does it merit a ban, when using actual profanity merely gets you kicked?

Invisal got banned for sss _ss , too.

scru commented: Come join Kindowm and aid our protest! +3
Rashakil Fol 978 Super Senior Demiposter Team Colleague

If you're rotating 270 degrees (or any multiple of 2pi/4 radians), there's no reason to be using trig functions. Just replace (x,y) -> (y,-x). That's what your code simplifies to, once you replace cos(angle) with 0 and sin(angle) with 1. You don't really need to know trig for this, just congruent triangles :-)

Also, make a habit of thinking in radians (which is just a way of describing angles as a fraction of a full circle). It's useful. Always look upon degrees as inferior, except when navigating. It helps if you remember that 2pi is a fundamental constant, while pi is merely 2pi/2, and a quarter circle is 2pi/4, etc. The people who decided that 3.141... was worthy of a name while 6.283... was not were noobs.

Also, in your implementation above, you really shouldn't hard-code the constant 2pi/4. Write it as SOME_NAME_FOR_PI/2. The only reason for this is that your constant doesn't have all the digits you need -- and you don't want to go around copying some random mathematical constants all over the place, to 16 decimal places or whatever is needed to completely fill the floating point mantissa you're using. It's much easier to remember the name. You'll suffer inaccuracy from using a constant that only goes to a paltry 8 decimal places. And you're using floating point numbers which gives you inherent accuracy. For rotating integers 90 degrees, using floating point math is just immoral :-) You're getting errors not from the inaccuracy of …

Duki commented: thanks! good explanation +4
Rashakil Fol 978 Super Senior Demiposter Team Colleague

What in the fµck are you talking about?

christina>you commented: lmao +21
jbennet commented: i agree but dont use the f word -4
Rashakil Fol 978 Super Senior Demiposter Team Colleague

More specifically, one way is binary search. Given a range [low, high] in which your square root lies, you can test if the square of (low + high) / 2 is greater than the value you're square rooting or not. If it's greater, then your new range is [low, (low + high)/2], if less, then your new range is [(low + high)/2, high]. Keep narrowing this range in half until the value (low + high)/2 is either <= low or >= high (which it will be, eventually, because you're using doubles.)

You need to pick appropriate starting values of low and high, of course -- one choice is 1 and the number you're taking the square root of.

This algorithm is rather slow, requiring about 52 or 64 iterations for reasonable numbers (if you're using the double datatype), but if if the number you're square-rooting is very, very close to zero, it will have to run thousands of iterations before it terminates (because instead of running into the limits of a double's precision, you'll be descending down to lower and lower exponents). Maybe you'd then want to make 0 a special case, tested for at the beginning.

A faster algorithm to find the square root of x is to compute f(f(...(f(f(f(f(1))))...)), where f(y) = (x/y + y)*0.5, and where f is iterated sufficiently many times.

Killer_Typo commented: great explination +6
Rashakil Fol 978 Super Senior Demiposter Team Colleague
Aia commented: You can be a man of little words when you choose so. +6
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I love geek jokes SOOOOOOOO much because they make me feel so much more special than all the other people.

Only I can understand them, and the jokes remind me of how awesome I am. The puny-minded nincompoops who don't understand the jokes are wasteful idiots who should be shot.

HEREZ MY FAVORITE GEEK JOKE:

Why was six afraid of twenty?

Because twenty ate four hundred ninety-six!

HAHAHAHHAHAHAHAHAHAHAHAHAHHA!

People who don't understand that joke are pricks for living in the same universe as me.

Dave Sinkula commented: I don't get it. +13
Aia commented: I don't want to be a prick, so I am going to laugh, now. Hahahaha. +6
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I don't think there's any purpose to this. Getting knighted by an online forum is like getting a diploma for graduating kindergarten.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

> Instead of simply informing Dani when there's a technical glitch or hole, he demonstrates how it could possibly be used in a bad way.

I wouldn't say that. I decided that some people behave too materialistically about reputation points, as if they carried any meaning whatsoever. And I thought it would be fun. And it was.

>For example, not too long ago he created a thread that was full of profanity.

And I reported it twice! I was really just confused, because it seemed like there was no profanity filter at all anymore.

> as far as I know (someone correct me if I am wrong here), did not abuse his powers,

More out of laziness than benevolence :P

iamthwee commented: Briiiiiiiiiliant +12
arjunsasidharan commented: :) +3
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Rashakil defeats Nichito.

Aia commented: For the good match +6
Rashakil Fol 978 Super Senior Demiposter Team Colleague

> You and I don't take drugs not because the goverment prohibit it,
> nor because is expensive or hard to find.
But considering the fact that once these things get legalized, it won't be long before everyone starts taking it. Remember, the people around you influence you; evil is known to stick fast and hard.

I guess everybody will have to conform to ~s.o.s~'s standards of how people should live.

joshSCH commented: Happy Independence Day! :) +15
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Well it could be done,
IF
The water was 'heavy water'
Or
He put a special chemical on his feet that repels the water allowing him to 'walk' on it.

To quote some awesome teacher I had: Shut up, that's retarded.

Edit: Hey, maybe that comes across as mean-sounding. Whatever.

iamthwee commented: I didn't know your mom was a teacher. +11
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Criss Angel is fake. He's a bad magician; he's bad at being a magician. He's a fake magician, because to call him a magician would denigrate magicians who are good at what they do.

EnderX commented: Nicely put. +3
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I am very confused. How in the world are you going to implement a stack using function pointers?

Rashakil Fol 978 Super Senior Demiposter Team Colleague

What you've just described is selection sort, where you select the minimum element from an array and append that onto an array that you're growing.

Insertion sort takes out the first element of the remaining elements and inserts it into the right place. To sort [2 7 3 9 4], you'd sort in the following fashion, where the list on the left is the sorted list that we're building, and the list on the right is the unsorted list we're taking elements from:

[] [2 7 3 9 4]
-- take the 2 and insert it 'in the right place'
[2] [7 3 9 4]
-- take the 7 and insert it 'in the right place'
[2 7] [3 9 4]
-- take the 3 and insert it 'in the right place'
[2 3 7] [9 4]
-- take the 9 and insert it...
[2 3 7 9] [4]
-- take the 4 and insert it...
[2 3 4 7 9] []
-- we're done!

And the sorted list becomes [2 3 4 7 9].

Now, I've been using the word 'list' instead of array, but that's only because I'm speaking abstractly. You can do an insertion sort on an array, in the fashion described above, in-place. Instead of changing the sizes of two 'lists' (whatever that means in the context of programming), you can simply walk an index through the array, from 0 to …

Killer_Typo commented: a superb job man! +5
Rashakil Fol 978 Super Senior Demiposter Team Colleague

THE ADVENTURES OF ALYSSA P. HAIRYLEGS: EPISODE 1

A group of people decided to meet together in some building and enjoy some great food made by a neighbor of theirs. They all smoke and they're all happily enjoying a night of food. It's good and they pay their neighbor for the service of cooking it. Their neighbor decides to make this a regular thing, so he renovates his building's kitchen, adds tables, asks a few folks if they'd like to waitress there in exchange for money. They agree. The establishment has great food, lots of cool people, a nice view overlooking the western horizon and such.

Then Alyssa P. Hairylegs happens by and decides that this seems like it might be a nice place to eat. She waltzes in, foxtrots over to a table, tangos into a chair and opens a menu. She looks for any vegetarian entrées but can't find any. Approvingly, she orders a steak and lights up a cigar.

It's getting late, and the sun is setting. The building's interior is bathed in light from the setting sun. Alyssa asks a waitress if the windows could be shaded so that she doesn't have sunlight fall on her. The waitress tells her that there are no shades for the windows. Alyssa stands up and shouts, "I DEMAND TO SEE THE MANAGER! NOW!!!1"

The manager walks out of the manager's closet and asks her what the problem is.

Alyssa replies, "THE SUN IS ON …

Dave Sinkula commented: Can I use that as a bedtime story? :) +13
Rashakil Fol 978 Super Senior Demiposter Team Colleague

They just passed a law in Ohio making it illegal to smoke in indoor public places. I'm glad. If you can't go one meal in a restaurant without smoking you need to start backing off of it some.

Are you so full of yourself that you think it's your place to dictate how other people live their lives?

Aia commented: I don't have any doubt that's the case. +5
Rashakil Fol 978 Super Senior Demiposter Team Colleague

His posts made perfect sense to me.

WolfPack commented: Yes. Makes sense for me too. +10
Rashakil Fol 978 Super Senior Demiposter Team Colleague
joshSCH commented: F*** is a bad word.. -2
WolfPack commented: No need to have bad rep for typing 4 asteriks +10
Aia commented: I see a F and some asteriks. No word. +5
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I've given up though. It's too addicting.

Haw haw.

maravich12 commented: that was funny. +1
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I really don't see how raising children could be called child abuse. Some people here seem to have an irrational opposition to religion. Athiests and agnostics tend to behave just as nonsensically as religious people, when it comes to day-to-day life. Plus, they get all uppity when it comes to theological questions.

Personally, I felt like I was forced to go to Sunday school, because I was. I did not see the point of wearing funny shoes on Sunday mornings.

iamthwee commented: Agreed. Plus your funny shoes would have matched your funny face. Snap. +11
Rashakil Fol 978 Super Senior Demiposter Team Colleague

This is true. The government did prolong the depression. Roosevelt's new deal, and his efforts helped to end the depression too. The shift from classical to Keynesian economics occured here.. It was the government's fault for not doing anything at first, but it was also them who saved us from the depression. The federal reserve did a pretty shitty job too..

Roosevelt presided over eight or nine years of high double digit unemployment rates. This should be regarded as utter incompetence. The fact that the depression ended during his reign should be attributed to the fact that he was in office for thirteen years, and to keep a nation under depression for such a period of time requires deliberate effort.

Also, your view of Keynesian economics makes it seem that you've taken AP Macroeconomics. I'm going to assume you haven't looked at other schools of economic thought or simply looked at things in a more nuanced manner (since the Keynesian view is rather primitive) and suggest that you do more research on your own.

> there was almost a recession again in 1981 (I think), but the Fed actually acted, and the chairman Volcker saved us from certain death :)

No, Volcker deliberately caused the recession, viewing it as a necessary evil to kill inflation.

huh? The government makes money in the same way that a department store makes money. You buy something from a department store, and you give them money. This money becomes their …

Dave Sinkula commented: Ah. Reason. I like to see it here sometimes. +11
sk8ndestroy14 commented: that was good +3
Rashakil Fol 978 Super Senior Demiposter Team Colleague

If you want people to help you, you're better off isolating the problem and identifying what you don't understand. Using nonstandard header files that only work on obscure compilers isn't increasing the probability of people finding your problem, either.

I recommend that you take a more proactive stance towards avoiding mistakes. In particular, write your code in a more clear fashion. Match your braces' indentation levels; don't stack closing braces all on one line. Don't use magical numeric constants, and avoid monstrosities like for(x1=210,y1=34,x2=420,y2=140,i=4;i<8;i++,y1=y2+5,y2=y2+106) Can you really understand what this is doing? If so, then you're too smart, and you need to treat yourself like a dumb person when writing code. Incomprehensibilitude is best left for writers of tax law.

Salem commented: Lots of good advice. +7
Rashakil Fol 978 Super Senior Demiposter Team Colleague

To summarize: because the standard says so.

John A commented: Haha +13
Rashakil Fol 978 Super Senior Demiposter Team Colleague

If it's harsh then that means it's right.

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Don't think you can trick us into doing your homework for you! This is the oldest one in the book!

And here's a lame version that assumes reasonable input, has passed only one test case, and assumes 32-bit longs.

unsigned long extract_digits (unsigned long x, size_t n, size_t i) {
  static const unsigned long tenpows[]
    = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

  size_t len;
  if (x < 1000) {
    len = 1 + (len >= 10) + (len >= 100);
  }
  else {
    if (x < 1000000) {
      len = 4 + (len >= 10000) + (len >= 100000);
    }
    else {
      len = 7 + (len >= 10000000) + (len >= 100000000);
    }
  }

  x = x % (tenpows[len - i]);
  
  return (x / tenpows[len - i - n]);
}
WolfPack commented: ha ha ha. +7
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Ba

christina>you commented: /? -2
WolfPack commented: Equalizer +7
arjunsasidharan commented: :) +2
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I think ultimately the trick to pull off is to bend spacetime over on itself

While we're at it, let's run the engine with sunspots! Accelerate using negative gravity! Reroute power from the deflectors! Spiderwalk along lines of magnetism, for extra efficiency!

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Store the array alongside a 'multiplier value' that you multiply the elements of the array by when reading them (and divide by when writing...). Then have MultiplyAll simply change the multiplier value.

Also, keep a counter and increment it with every ZeroAll call. Store with each element in the array a value that tells what the counter's increment was the last time you wrote to it. If the ZeroAll counter is greater than the counter alongside your value, then treat the value as if it were zero.

~s.o.s~ commented: Good one.. ;-) +19
iamthwee commented: To counterbalance your star I'm sending you this. -2
Aia commented: I don't like your avatar, but still like you. - Aia :) +1
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Stalin doesn't deserve credit for stopping Hitler; it's the millions of Soviet soldiers who deserve the credit. All Stalin deserves credit for is for playing the following text adventure game.

Hitler is attacking you!
  1. Defend yourself.
  2. Send giant bunnies.
  3. Invent Tetris.
Your Choice: [b]1[/b]

Hitler loses!  HP/MP restored!
But you're still hungry.
christina>you commented: haha, I like the little attachment there. +8
Rashakil Fol 978 Super Senior Demiposter Team Colleague

He could just cout the string itself, so I take it this is just a test program for another project.

~s.o.s~ commented: Heh, that was really interesting. +18
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I'm from America, but I've been in Canada since this place changed its smileys.

John A commented: :-) +11
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I'd be a bit peeved if what I posted in what was purportedly a private forum for moderators only got copied and spread around publicly.

iamthwee commented: True, next thing you know our PMs go on public display? +9
Rashakil Fol 978 Super Senior Demiposter Team Colleague

The notion of a logic-driven society doesn't make any sense to me. I don't understand what you mean at all. Are decisions made... logically? From what premises are the logical reasonings made? It sounds to me like the only thing different from your idea of a right society from others' is that its logic is derived from the arbitrary axioms that you prefer, while others' are derived from different premises regarding righteousness. Would your society, by any chance, restrict mating to once every seven years?

EnderX commented: Nicely put. +1
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Communicating using noobspeak is simply unacceptable* when there are people here, not necessarily the original poster you're talking to, who are not from English-speaking countries and can barely put coherent English sentences together.

* i.e. evil

'Stein commented: I love the footnote. -'Stein +6
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Update!

jbennet commented: Have some consideration. Rep is not a game, some people actually take it seriously and no wonder people dont like you if you treat it that way. +11
Rashakil Fol 978 Super Senior Demiposter Team Colleague

Here's my rep page now:

The top two were for my "Do you like killing people?" question in the yes/no thread ^_^

Rashakil Fol 978 Super Senior Demiposter Team Colleague

cat five yarn dandy croznik yeltsinov... bufafu why captialization captialization. Punctuiton not is capituiton... but (aaah sunshiners) bartholemeu dancer.
Hafnium microspecules banfarfamate splarkingtonial satchezes.... (Zhoom baby, zhoom!)

Rashakil Fol 978 Super Senior Demiposter Team Colleague

Why? The only thing noobs need to know is how to write in complete sentences and use code tags. A little humility would be nice, too -- some people just expect a free homework service. The last thing we need is people measuring their self-worth based on how many posting games they play in.

Salem commented: Damn straight! - Salem +6
Rashakil Fol 978 Super Senior Demiposter Team Colleague

fork

spoon fied slummer kanting?

scru commented: genius. +6
Rashakil Fol 978 Super Senior Demiposter Team Colleague

I don't think that's what the question's asking, Lerner. It doesn't say that.

shmay, if you need to generate a number in the range [0, 37) with five random decimal digits after the decimal point, start by generating an integer in the range [0, 3700000], and then divide it by 100000.0. You might need to be able to handle up to 14 or 15 decimal digits, so you might need to generate multiple random numbers and piece things together, depending on the range of your random number generator.

For example, to generate a number in [0, 444) with 10 random decimal places, I'd first generate a number in [0, 4440000000), and divide that by 10000000.0. That gives the first six decimal places. Then I'd generate a number in [0, 10000) and divide that by 1e-10, for decimal places 7 through 10, and add that to the first number.

A simpler algorithm is to generate the decimal expansion one digit at a time. For example, if you want a double in the range [0, n), generate an integer in the range [0, n), and then generate ten decimal digits, multiplying the nth decimal digit by 0.1 to the nth power, adding these up, and then adding these to the integer you generated.

And if you want precision measured in binary digits, replace the powers of 10 with powers of 2 in the above algorithms.

~s.o.s~ commented: as expected from a Haskeller. ;-) ~s.o.s~ +17
Rashakil Fol 978 Super Senior Demiposter Team Colleague

It's a type. A datatype. Like int or long or size_t or unsigned char.

You know how in C, size_t is an unsigned integer large enough to represent any array size possible? The C++ std::string class provides string::size_type as an integer datatype large enough to represent any possible string size.

The 'find' member function returns the location of the first occurrence of a substring or character in a string. This return value is an integer (whose type is string::size_type). If the substring or character is not found, it needs some value to return that signals this fact. A library designer could have said, "okay, let's return -1 when the substring's not found." But instead, they return some integer value hardcoded as string::npos. It's probably -1. Code that uses string::npos is more readable than code that uses -1. (Since you can't assume that string::npos == -1, you have to use string::npos anyway.)

aderchox commented: really nice explanation thank you +0
Rashakil Fol 978 Super Senior Demiposter Team Colleague

mrclean, this question is complicated by the fact that you have multiple parameters to your first function, but only one parameter to your second function. Your second function runs in theta(n*n) time, yes. But take a look at your first function. Suppose you hold the value k fixed? Suppose you hold k fixed at 3, and then consider the running time as you vary n from 0 to an arbitrarily large number? You'll find that you run through the interior for loop approximately 3n times. If you fix k at any value, you'll find this to be the case, that you run through the interior loop approximately k*n times, if n is really large.

The interesting thing is, for values of n that are less than k, the growth pattern seems to be a theta(n^2). But after you increase n past the value of k, you'll find that the interior for loop gets run "k" extra times each time you increase the value of n by 1.

This leads to the interesting topic of what big O and big Theta notation really means. When you have multiple variables, it is not necessarily as straightforward an idea as when you have one. You could say that your first function has a running time Theta(k*n). What does that mean? You could consider the two directions in which you can grow the parameters of the running time function f(k,n) = k*n: increasing k while holding n constant and increasing n while …

~s.o.s~ commented: Good one - ~s.o.s~ +13