Hey guys what do you think of my highly optimized code :^)?
>Not using assembly
Come back when you're an actual programmer, kid.
I actually kind of like cin/cout, it's a guaranteed indicator that the poster is a first semester CS student and doesn't know shit.
>>59169662
What's better, passing in as an argument? Never really touched C++.
>>59169662
>College
>Implying
>>59169705
I'm fully convinced cin/cout was added to C++ to make it easier to do hello world.
>>59169589
> optimized
Streams are very inefficient senpai.
>>59169735
As opposed to what? printf? Give me a break.
Well, at least you're using CodeBlocks.
>>59169589
>no indentation
D R O P P E D
>>59169786
That's what makes it optimized desu
>>59169589
>no indentation
Unreadable.
>using a Windows IDE and probably a Windows compiler
>doesn't follow GNU standards
I barfed
>>59169825
the compiler doesn't see whitespace
>>59169827
What's a GNU standard?
>>59169825
Indentations and comments are stripped by the compiler...
ratefunction isntprime(argument) {
while (true) if (argument % Math.floor(Math.random()*100) === 0) break
return true
}
>>59169847
Example of the GNU standard:int
main (int argc, char *argv[])
{
struct gizmo foo;
fetch_gizmo (&foo, argv[1]);
check:
if (foo.type == MOOMIN)
puts ("It's a moomin.");
else if (foo.bar < GIZMO_SNUFKIN_THRESHOLD / 2
|| (strcmp (foo.class_name, "snufkin") == 0)
&& foo.bar < GIZMO_SNUFKIN_THRESHOLD)
puts ("It's a snufkin.");
else
{
char *barney; /* Pointer to the first character after
the last slash in the file name. */
int wilma; /* Approximate size of the universe. */
int fred; /* Max value of the `bar' field. */
do
{
frobnicate (&foo, GIZMO_SNUFKIN_THRESHOLD,
&barney, &wilma, &fred);
twiddle (&foo, barney, wilma + fred);
}
while (foo.bar >= GIZMO_SNUFKIN_THRESHOLD);
store_size (wilma);
goto check;
}
return 0;
}
return isPrime(input);
isPrime() is left as an exercise for the reader.
>>59169840
>>59169872
But it makes the source code smaller
>>59169988
who cares?
if you wanna compress text just tar and gzip it
>>59169988
Yes, we all get this. Stop being a smartass.
>>59169589
You need to be 18 years old to post here.
>>59169662
>>59169735
This is the worst kind of person
>>59169735
Tiers of C++ programmers:
>Newbie tier: thinks << syntax is so cool
>Disillusioned tier: le operator overloading is bad meme, le c++ is overcomplicated meme
>Ascended tier: found his inner peace, embraces the iostream
>>59169662
>t. someone who has never written C++ for a living
>>59169827
Kill yourself, you dumb fucking shit stain.
Cs101
>>59169589
Step it up.|_ {bowl $~}
::
++ prim
|= x/@
=+ i=2
|- ^- ?
?: =(x i) &
?: =(0 (mod x i)) |
$(i +(i))
::
++ poke-noun
|= a/@
~& ?:((prim a) [a %is-prime] [a %not-prime])
[~ +>.$]
--
>>59170131
Have you been following me around recently?
>>59169662
WTF are you supposed to do for "solve this puzzle" type command line shit???
>>59169589
I'm gonna hurt you
for i:=1 to trunc(sqrt(x)) you retarded faggot
>>59169589
>abusing namespace std;
>>59170320
printf
non-descriptive, cryptic code != Optimized code
I took the bait
OP you only have to try factors up the square root of x
>>59169589
>using the smiley with a carat nose
step up your game nigga and use scanf/printf
>>59171368
just fwrite to stdout
>>59169589
No sieve of eratosthenes. Kill yourself.
>>59171368
Why?
>not putting it all on a single line
3/10, see me after class
>>59171450
iostream is way slower than cstdio.
but, the compiler replaces your brain when you're using iostream, because it's using type safety.
>>59169589
You should only loop until sqrt(x), all the other divisors can be obtained from x/i, where i is an integer smaller than sqrt(x).
For example:
Let's obtain the divisors of 20
1 2 4 5 10 20
Sqrt(20) is somewhere between 4 and 5.
20 is 20/1
10 is 20/2
And 5 is 20/4
So it's useless to check numbers above sqrt(x). Try it out!
>>59169589
>"Enter a Positive Integer"
>1
>>59169589
>highly optimized
>not using inline functions
>O(n) prime checker
>iostream and not write()
>unportable system() bullshit because you're too stupid to run your shit properly
>implying more chars = more slow
unreadable dogshit, 2/10
>>59171902
>isPrime(1)
>skips the for loop because 2 > 1
>returns true
It works you stupid shit
>>59169589
What does no formatting have to do with optimization?
>>59169589
0/8 total piece of crap
>>59169988
>optimizing for disk space
WHAT YEAR IS IT?
>>59172121
1 is not prime
>>59172207
shut up, we are glad it finally works
>i<x
>"""highly""" optimized
Agh
>>59170298
Wew hoon
>>59171616
You can also first check 2, then start the loop at 3 and increment by two each time - if the number is divisible by any even number, it is divisible by 2 anyway.