News: 11 March 2016 - Forum Rules

Author Topic: One liner to print the alphabet.  (Read 7128 times)

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
One liner to print the alphabet.
« on: September 02, 2012, 02:51:43 pm »
for(char c = "A"; c <= "Z"; c++) cout << (char)c << ' ';

Now why I'm type casting with the same data type is because chars are ints as well. So without that type cast, the compiler would assume your talking about integers.

Tell me what you think.

LostTemplar

  • Hero Member
  • *****
  • Posts: 910
    • View Profile
    • au-ro-ra.net
Re: One liner to print the alphabet.
« Reply #1 on: September 02, 2012, 03:02:50 pm »
Uhm, congratulations?

henke37

  • Hero Member
  • *****
  • Posts: 643
    • View Profile
Re: One liner to print the alphabet.
« Reply #2 on: September 02, 2012, 03:14:09 pm »
Way too many characters, you can combine the loop iterator increment with the output. Also, you got the wrong type of quotes for the character literals.

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: One liner to print the alphabet.
« Reply #3 on: September 02, 2012, 04:42:14 pm »
Way too many characters, you can combine the loop iterator increment with the output. Also, you got the wrong type of quotes for the character literals.

You mean like "A" should be 'A' and "Z" should be 'Z'? Yeah, I suppose. I kinda just rushed through this post.

BRPXQZME

  • Hero Member
  • *****
  • Posts: 4572
  • じー
    • View Profile
    • The BRPXQZME Network
Re: One liner to print the alphabet.
« Reply #4 on: September 02, 2012, 05:14:36 pm »
So without that type cast, the compiler would assume your talking about integers.
No, it would assume a char unless told otherwise.
we are in a horrible and deadly danger

uyuyuy99

  • Guest
Re: One liner to print the alphabet.
« Reply #5 on: September 08, 2012, 05:10:57 pm »
I don't see what's so special about this. You could write a huge program on a single line if you wanted to... line breaks are just whitespace, they're not that meaningful.

Kiyoshi Aman

  • RHDN Supporter
  • Hero Member
  • *****
  • Posts: 2262
  • Browncoat Captain
    • View Profile
    • Aerdan's Blog
Re: One liner to print the alphabet.
« Reply #6 on: September 08, 2012, 05:30:30 pm »
Code: [Select]
print for ('A' .. 'Z');

My Perl one-liner is unbeatably shorter than your C++ one-liner. Now leave.

InfamousKnight

  • Sr. Member
  • ****
  • Posts: 321
    • View Profile
Re: One liner to print the alphabet.
« Reply #7 on: September 08, 2012, 05:37:10 pm »
Code: [Select]
print for ('A' .. 'Z');

My Perl one-liner is unbeatably shorter than your C++ one-liner. Now leave.

You just made perl look like the best language there is!

BRPXQZME

  • Hero Member
  • *****
  • Posts: 4572
  • じー
    • View Profile
    • The BRPXQZME Network
Re: One liner to print the alphabet.
« Reply #8 on: September 08, 2012, 07:01:37 pm »
I don't see what's so special about this. You could write a huge program on a single line if you wanted to... line breaks are just whitespace, they're not that meaningful.
They’re better when you’re not trying to do anything you’re going to have to look at again.

That means in languages tooled towards building lasting applications and systems (such as any C-like), you should avoid them, unless you’re submitting an IOCCC entry or something too clever by half like that.
we are in a horrible and deadly danger

Zoinkity

  • Hero Member
  • *****
  • Posts: 562
    • View Profile
Re: One liner to print the alphabet.
« Reply #9 on: September 08, 2012, 09:16:22 pm »
The great irony of Python: despite the style rules calling for clear code and avoidance of one-liners, it winds up being the source of the longest example on the wiki article.

The one case where whitespace should be avoided would be in small-memory systems, like old Basic machines or, as a modern example, graphing calculators.  Again, due to readability you'd want to avoid removing whitespace until after you're done debugging.

Never heard of IOCCC before, but wow there's some neat concepts there.

Kiyoshi Aman

  • RHDN Supporter
  • Hero Member
  • *****
  • Posts: 2262
  • Browncoat Captain
    • View Profile
    • Aerdan's Blog
Re: One liner to print the alphabet.
« Reply #10 on: September 09, 2012, 02:30:18 am »
Oh! Oh! Are we gonna complain about significant whitespace? Are we?

Because COBOL is far worse than Python.

BRPXQZME

  • Hero Member
  • *****
  • Posts: 4572
  • じー
    • View Profile
    • The BRPXQZME Network
Re: One liner to print the alphabet.
« Reply #11 on: September 09, 2012, 02:44:13 pm »
Quote
Phoenician is a dead language. Mayan is a dead language. Latin is a dead language. What makes these languages dead is the fact that no one speaks them anymore.
Maybe not so much the Latin, but I imagine this statement would come as a shock to speakers and scholars of Mayan languages.
we are in a horrible and deadly danger

Kiyoshi Aman

  • RHDN Supporter
  • Hero Member
  • *****
  • Posts: 2262
  • Browncoat Captain
    • View Profile
    • Aerdan's Blog
Re: One liner to print the alphabet.
« Reply #12 on: September 09, 2012, 06:38:56 pm »
Nahuatl is still alive and well, for instance, despite being diluted by, and in turn diluting, Spanish.

sa♥tsu

  • Hero Member
  • *****
  • Posts: 509
  • Back against the thin wall
    • View Profile
    • sa-two.yuudachi.net
Re: One liner to print the alphabet.
« Reply #13 on: September 11, 2012, 03:59:17 pm »
10 PRINT "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

Zoinkity

  • Hero Member
  • *****
  • Posts: 562
    • View Profile
Re: One liner to print the alphabet.
« Reply #14 on: September 12, 2012, 09:15:21 am »
Interestingly, we just got one of those learn Nahuatl <-> Portugese in 36 1/2 minutes types of books in the shop this week.

To be fair, three weeks ago we also got in one listing all the newly invented eclesiastical latin for modern stuff.  So, next time you're planning to use the ATM at the Vatican we've totally got you covered.