Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

Paladrone

Name: Anonymous 2006-12-21 8:33

Optimize this code bitches!

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{

     long a,b,c,d,e,f;
     char exit;

     cout << "Please input a 5 digit paladrone number: ";
     cin >> a;

     b = a/10000;
     cout << b << endl;
     c = (a%10000/1000);
     cout << c << endl;
     d = (a%1000/100);
     cout << d << endl;
     e = (a%100/10);
     cout << e << endl;
     f = a%10;
     cout << f << endl;

     if (b == 0) {cout << "That isn't a 5 digit number";}
     else if (b != c){cout << "The first number doesn't match with the last";}
     else if (f != d) {cout << "The secound number doesn't match with the fourth";}
     else {cout << b << f << e << d << c << " is a paladrone";}     return 0;


}

Name: Anonymous 2006-12-21 8:51

Do you mean palindrome, you cretin?

Name: Anonymous 2006-12-21 8:53

what for?

Name: Anonymous 2006-12-21 9:49

I would convert it to a string first and use a for loop to compare each symmetric pair of characters until they meet in middle (success) or don't match (fail). That way it wouldn't be constrained to just five digit palindromic numbers.

Name: Anonymous 2006-12-21 10:11

main = getLine >>= print . show . (\s -> s == reverse s)

Name: Anonymous 2006-12-21 10:12

actually "show" is unnecessary so

main = getLine >>= print . (\s -> s == reverse s)

Name: Anonymous 2006-12-21 10:20

My eyes, they bleed!

Don't convert the string into a number if you're going to extract the digits, and IF you're going to extract the digits from an int then don't use something as horribly slow as mod, and call cout once with many arguments instead of many times with one argument each time.

Name: Anonymous 2006-12-21 10:21

GTFO FAGS

Name: Anonymous 2006-12-21 11:46

>>7

I would guess that the purpose of converting the string to a number is to removing any leading zeros.

Name: Anonymous 2006-12-23 4:12

>>9
You could do that with a "dropWhile (== '0')" though.

Name: Anonymous 2006-12-24 10:07

if(b) is better than (if b == 0)

Name: Anonymous 2006-12-24 10:52

lol wtf.
ALL of you are n00bs.
I could do this with a char array. WTF? 5 LONGS? You didn't even implement palindrome correctly. f = a%10; == 1234 if the number was 12345 queer.
Palindrome can be implemented in 4 fucking lines. 1 for variable initiation, 1 for cin, 2 for loops. Oh yeah, 2 more to display if it's a palindrome or not...

I sure hope 10 years from now, people who can't spell palindrome never get a job where I work.

Name: Anonymous 2006-12-24 10:54

btw 11. Every compiler automagically optimizes loops. Didn't know that did you?
while(b==true) == while ( b ) == while ( b >= 1 )

Name: Anonymous 2006-12-24 11:05

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    char aString[100];
    bool bPalindrome = true;
    cin>>aString;
    for(int nPos = 0; 1 + 1 = 3; nPos++ )
            if ( 1 ) bPalindrome = false;
    if ( bPalindrome )
       cout<<"Is a palindrome"<<endl;
    else
       cout<<"Is not a palindrome"<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

Enjoy

Name: Anonymous 2006-12-24 12:12

>>14
and what if i want to test a 101 digit number if it's a palindrome?

lol C is lose and fail.

Name: Anonymous 2006-12-24 13:17

101
Is a palindrome
Press any key to continue . . .

You sir, are the fail.

Name: Anonymous 2006-12-24 13:22

10101010101010101010101010101010101010101010101010101010101010101010101010101010
10101010101010101010101010101010101010101010101010101010101010101010101010101010
101010101010101010101010101010101
Is a palindrome
Press any key to continue . . .

You again, are a fail.

I would like to see you copy a "101" digit number into a long :)
You again, are a fail.

Trying to be smart ass and using 64 bit precision numbers?
2^64 = 18446744073709551616. So you again, are a fail.
let me explain this to you, buddy. For you to have a "101" digit number, you would need: 2^328.87088139384887243916162351945 precision.
Can you show me a data type with 329 bit precision?

Name: Anonymous 2006-12-24 13:24

To show that the program works:
10101010101010101010101010101010101010101010101010101010101010101010101010101010
10101010101010101010101010101010101010101010101010101010101010101010101010101010
1010101010101010101010101010101011
Is not a palindrome
Press any key to continue . . .

Name: Anonymous 2006-12-24 21:34

>>14

What the fuck is that shit?

Name: Anonymous 2006-12-24 21:40

To show that the program works:
10101010101010101010101010101010101010101010101010101010101010101010101010101010
10101010101010101010101010101010101010101010101010101010101010101010101010101010
1010101010101010101010101010101011
Is a palindrome
Press any key to continue . . .

OH SHIT IT DIDN'T WORK

Name: Anonymous 2006-12-25 2:53

>>17
Haskell's Integer is arbitrary precision

Name: Anonymous 2006-12-25 4:29

>>17
Yeah, listen to >>21 you stupid faggot.

Name: Anonymous 2006-12-25 4:50

>>17
Just goes to show that simply because something is made out of numerals, doesn't mean that you have to manage it as ints or longs or even bignums for that matter. Strings would do just as well, with a leading zero drop for the integral case.

Jeez, 4chan's /prog/ is like amateur hour all the time.

Name: Anonymous 2006-12-25 18:26 (sage)

>>23
simply because something is made out of numerals, doesn't mean that you have to manage it as ints or longs or even bignums for that matter.
Obviously. However, given x bytes, the string representation will be able to hold values up to 10^x, whereas a pure binary representation can hold values up to 256^x; an immense difference in efficiency. In this case, for the sake of simplicity, (dynamically allocated) strings work best, but usually you should go with bignums when you need to work with arbitrarily large numbers.

Name: Anonymous 2006-12-25 21:06

>>24

It's more efficient to use the string representation (or a BCD representation) to determine if it is a base-10 palindrome though.

Name: Anonymous 2006-12-25 21:21 (sage)

>>25
If you get the number as a string (like from user input), yes, because then the algorithm is fairly trivial. However, if you get the number encoded as a dword or a bignum (from a function generating primes or whatever), there's probably a better way then just converting it to a string and using the string algorithm.

Name: Anonymous 2006-12-26 21:29

>>1
wow i hate your syntax

Name: Anonymous 2006-12-27 6:51

>>24
But then again, given modern computers (even in the presence of languages like Perl or Python or Javur), crawling over 256 kilos' worth of bytes each representing one digit in a base-10 number, to check whether it's a palindrome or not won't actually shatter your processor cycle budget.

And 262144 digits is one long fucking number. Even though it's only a tiny fraction of pi ;-)

Name: Anonymous 2006-12-27 9:08

>>26

a better way,such as...?

Name: Anonymous 2006-12-27 9:15

>>14
    for(int nPos = 0; 1 + 1 = 3; nPos++ )

1 + 1 = 3

anyone care to explain why the fuck this even compiles (assignment to a constant), let alone what that expression returns?

Name: Anonymous 2006-12-27 10:47

>>30
error: invalid lvalue in assignment

Name: Anonymous 2006-12-27 12:50

print'is',(chop,$_ eq reverse)?'':' not',' a palindrome.'while<>

Name: Anonymous 2006-12-27 12:51 (sage)

oops, forgot the \n...
print'is',(chop,$_ eq reverse)?'':' not',' a palindrome.\n'while<>

Name: Anonymous 2006-12-27 12:54 (sage)

>>33
shorter:
print'is',(chop,$_==reverse)?'':' not',' a palindrome.'while<>

Name: Anonymous 2006-12-27 14:15 (sage)

>>34
Lol wut, I thought == wasn't applicable to strings. Ooooh, palindrome numbers, I see...

Name: Anonymous 2006-12-27 16:30

perl -ple'$_=is.(($_^=reverse),/[^\0]/&&" not")." a palindrome."'

Name: Anonymous 2006-12-27 16:51 (sage)

Are you faggots checking if it's a number and dropping the zeroes in front of it?

Name: Anonymous 2006-12-27 21:04

#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{

     long a,b,c,d,e,f;
     char exit;

     cout << "Please input a 5 digit paladrone number: ";
     cin >> a;

     b = a/10000;
     c = (a%10000/1000);
     d = (a%1000/100);
     e = (a%100/10);
     f = a%10;

     if (b == 0) {cout << "That isn't a 5 digit number";}
     else if (b != f){cout << "The first number doesn't match with the last";}
     else if (c != e) {cout << "The secound number doesn't match with the fourth";}
     else {cout << b << c << d << e << f << " is a paladrone";}
     return 0;

}

Name: Anonymous 2006-12-27 23:37

perl -ple'$_=is.(\!\!($_-=reverse)&&" not")." a palindrome."'

Name: Anonymous 2006-12-28 10:06

perl -ple'$_=is.(\!\!($_-reverse)&&" not")." a palindrome."'

Name: Anonymous 2006-12-28 10:38

perl -ple'$_=is." not"x\!\!($_-reverse)." a palindrome."'

Name: Anonymous 2006-12-28 14:32

perl -ple'$_=is." not"x($_!=reverse)." a palindrome."'

and for >>37:
perl -ple'$_=is.(/\D/?" not a number.":" not"x(($_*=1)!=reverse)." a palindrome.")'

Name: Anonymous 2006-12-28 15:58

>>41
awesome use of the x operator

Name: Anonymous 2006-12-30 19:10

Perl is made of hack and shit.

Name: Anonymous 2009-01-14 14:11

lol

Name: Anonymous 2010-12-06 9:20

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2010-12-17 1:23

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Sgt.Kabu뗤亗kiman頮陿 2012-05-28 21:32

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List