![]() |
|
Count to 10 - Printable Version +- Southperry.net (https://www.southperry.net) +-- Forum: Social (https://www.southperry.net/forumdisplay.php?fid=14) +--- Forum: Rubik's Cube (https://www.southperry.net/forumdisplay.php?fid=58) +--- Thread: Count to 10 (/showthread.php?tid=42181) Pages:
1
2
|
Count to 10 - Hazzy - 2011-05-22 I've been reading some depressing stories about programming when a bit caught my eye: Quote:If you can successfully write a loop that goes from 1 to 10 in every language on your resume, can do simple arithmetic without a calculator, and can use recursion to solve a real problem, you're already ahead of the pack! Makes me wonder, how many ways can Southperry count to 10? Anything that a computer can run to print an output counts. JavaScript to C++. Python to Assembly. Guidelines:
Count to 10 - Erebus - 2011-05-22 Define "every language" does that include the obsolete ones? Count to 10 - Hazzy - 2011-05-22 Nevermind. If it's a 'language' in even the loosest sense it counts. Count to 10 - Eos - 2011-05-22 Got bored after the first three, since most others are just variations of these. VB
Spoiler
TSQL
Spoiler
C
Spoiler
Count to 10 - FenixR - 2011-05-22 I would give you a brohug if i were in front of you. This reminded me that i had to look up ways to find how to know when a number is even or odd while making algorithms (And later coding it), and now i remembered how to calculate multiples of any number to boot too ![]() Im still fairly new to programing and have to restart my education of it because of a few problems that i won't bother mention, but someone would be nice to explain this to me? "printf( "%d\n", x)" only one that didn't understand exactly what it says (I can guess, sort of, but i would rather know exactly what it is). Count to 10 - Kalovale - 2011-05-23 dante9898 Wrote:I would give you a brohug if i were in front of you. printf can be read as "print formatted", that is, printing something to the output in a formatted manner. You can dictate that the thing you print be an interger (d), a floating point value (f), a string (s) or possibly more. Basically, it's a function, it receives order to do something and HOW to do it, then do it. In your example: printf("%d\n", x) says to print x (whatever it may be) as an integer (%d part) - so it probably will cut off the decimal part if x is a floating point value. The \n part, if I'm not mistaken, universally means "insert a newline" where \ is the escape sequence so that n could mean new (and not the literal character n). As for the actual topic, I only know Java as of now (so probably I can do it in C and C++ after a 10-minute session digging up?), and here's the most obvious ways: Code: for(int i=1; i <=10; i++) {Code: int i = 1;Code: public static void addOne(int i) {Count to 10 - Eos - 2011-05-23 dante9898 Wrote:This reminded me that i had to look up ways to find how to know when a number is even or odd while making algorithms (And later coding it), and now i remembered how to calculate multiples of any number to boot too Modulo for both? dante9898 Wrote:Im still fairly new to programing and have to restart my education of it because of a few problems that i won't bother mention, but someone would be nice to explain this to me? "printf( "%d\n", x)" only one that didn't understand exactly what it says (I can guess, sort of, but i would rather know exactly what it is). C is a low level language, it does not have any natural ways to print values without explicitly casting them into a character string via a format conversion function like printf. The other languages you can just say print @variable and the engine knows to bring the value of the variable, but with C you have to be more specific, because print requires a character string and x is a number, therefore you need to convert x into a character string to print it, either via that function, or a more torturous route such as creating a character array and printing to that array the value of the variable. Could've possibly done a print( itoa(x)); as well. Count to 10 - shouri - 2011-05-23 R lol Wrote:seq(1:10) Matlab Quote:for(i=1:10) C++ Quote:for(i=1;i<=10;i++) C++ Recursive Quote:void main() The java one looks almost exactly like C++ cept it uses System.out.println(i); instead of cout<<i; Count to 10 - FenixR - 2011-05-23 Eosian Wrote:Modulo for both? Pretty much yes. I remember that i was taught that but forgot about it, while i got caught up recently on a problem that needed to find if a number was Odd and Even and could not remember the method to do so. Eosian Wrote:C is a low level language, it does not have any natural ways to print values without explicitly casting them into a character string via a format conversion function like printf. The other languages you can just say print @variable and the engine knows to bring the value of the variable, but with C you have to be more specific, because print requires a character string and x is a number, therefore you need to convert x into a character string to print it, either via that function, or a more torturous route such as creating a character array and printing to that array the value of the variable. Could've possibly done a print( itoa(x)); as well. This is still a little fuzzy but i can understand my way from what you and kalovale said, need to see it in action to completely understand it. Thx for the answers btw. Count to 10 - Fiel - 2011-05-23
Python
Count to 10 - Hazzy - 2011-05-23 Aww, I was hoping for some degree of creativity from you guys. ![]() Code: HAICount to 10 - shouri - 2011-05-23 Hazzy Wrote:Aww, I was hoping for some degree of creativity from you guys. I actually WAS considering posting this one xD Count to 10 - Eos - 2011-05-23 Hazzy Wrote:Aww, I was hoping for some degree of creativity from you guys. You stated elegence was the target, short and succinct. What did you expect? Count to 10 - Kalovale - 2011-05-23 Hazzy Wrote:Aww, I was hoping for some degree of creativity from you guys. Code: while(!derpington) {Count to 10 - GMSInfighter - 2011-05-23 Jeez, I gotta re-learn all this stuff. Haven't in years. I would post binary code but that's too simple compared to what you guys wrote =3= Count to 10 - Fiel - 2011-05-23 GMSInfighter Wrote:Jeez, I gotta re-learn all this stuff. Haven't in years. Indeed. Machine code is simpler than .NET Count to 10 - Luacake - 2011-05-23 Just for fun
Joy
Count to 10 - Eos - 2011-05-23 Fiel Wrote:Indeed. Machine code is simpler than .NET :f6: How so? vb.net is almost identical to the VB i posted. Even C# and C++.net work with the C examples I gave. Count to 10 - Fiel - 2011-05-23 Sorry, Eosian. Let me clarify. <sarcasm> Indeed. Machine code is simpler than .NET </sarcasm> I was making fun of his statement that binary code is easier than "the examples posted here". Count to 10 - Eos - 2011-05-23 Ah, OK. Internet. Lack of tone. Programming discussion. Bad chin. |