Jump to content

Fun code!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
20 replies to this topic

#1
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Yes typing serious and productive code is ALWAYS fun and interesting. But what about typing fun code, isn't that fun and interesting :D

This all started when me and Chili5 were talking about competition, they have to type code that will run in under 2.5 seconds!! On a quad-core processor :D Then he mentioned counting to a million on a Python script, it took forever! I did it and it was fairly quick, it was fun :D

Which then leads me to this thread.

Share your FUN CODE!! I want something new and fun to see hehe. Here is how to count to a million in Python.


count = 0

while count <= 1000000:

    print count

    count = count + 1


I think most fun code could be written as while loops, but use whatever you wish! Something that isn't as fun, but interesting. Is 100 ^ 1000000 in Python :D Took about 10 - 20 minutes and still get to see the full answer! Too many zeros hehe.

Here's how.

print 100 ** 1000000


Now let's see your fun and interesting code.
NOTE: Any language, anything you wish!
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Fun code for me is recursion. Here is one that prints a string until it doesn't exist any longer.

<?php

/**
 * Recursively  print a string
 *
 * @param mixed $someString
 */
function RecursivePrint(&$strString) {
    if (strlen($strString) > 0) {
        echo "$strString" . PHP_EOL;
        $strString = substr($strString,0,-1);
        RecursivePrint($strString);
    }
}

// Create a string
$myString = "CodeCall Fun Code Thread!";

// Execute the function
RecursivePrint($myString);

?>
Which will output:

CodeCall Fun Code Thread!
CodeCall Fun Code Thread
CodeCall Fun Code Threa
CodeCall Fun Code Thre
CodeCall Fun Code Thr
CodeCall Fun Code Th
CodeCall Fun Code T
CodeCall Fun Code 
CodeCall Fun Code
CodeCall Fun Cod
CodeCall Fun Co
CodeCall Fun C
CodeCall Fun 
CodeCall Fun
CodeCall Fu
CodeCall F
CodeCall 
CodeCall
CodeCal
CodeCa
CodeC
Code
Cod
Co
C


#3
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Wow! That looks so cool! That is why I did one of the next code I will show you.

Try this, put this in Python again :)
x = 1
y = 1

while x <= 10000000:
    while y <= 100:
        print x ** y
        x = x + 1
        y = y + 1

jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#4
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
Lol nice thread
ill go digging in my codes

#5
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Can't wait amrosama! Show us some of your skills :D
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#6
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts
I adore infinite loops cuz they make the computer look stupid

while(true) cout<<"<<<<<>";

when the console starts maximize it's window and stare into it, now move your eyes slowly from the top to the bottom of the window, you will see a very beautiful waterfall :)

#7
Dren

Dren

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 448 posts

Brandon W said:

Wow! That looks so cool! That is why I did one of the next code I will show you.

Try this, put this in Python again :)

x = 1

y = 1


while x <= 10000000:

    while y <= 100:

        print x ** y

        x = x + 1

        y = y + 1


Brandon I haven't tried that in Python but looks awesome in C++:p

The C++ version:

#include <iostream>


using namespace std;


int main(int)

{

  

  int x = 1;

  int y = 1;

  

  do

  {

    do

    {

        cout << x * y;

        x++;

        y++;

    }

    while(y <= 100);  

  }

  while(x <= 10000000);

  

  system("PAUSE");	

  return 0;

}


#8
Egz0N

Egz0N

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,034 posts

Jordan said:

Which will output:


CodeCall Fun Code Thread!

CodeCall Fun Code Thread

CodeCall Fun Code Threa

CodeCall Fun Code Thre

CodeCall Fun Code Thr

CodeCall Fun Code Th

CodeCall Fun Code T

CodeCall Fun Code 

CodeCall Fun Code

CodeCall Fun Cod

CodeCall Fun Co

CodeCall Fun C

CodeCall Fun 

CodeCall Fun

CodeCall Fu

CodeCall F

CodeCall 

CodeCall

CodeCal

CodeCa

CodeC

Code

Cod

Co

C


Wow ..Cool One Jordan ..:p

#9
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts

amrosama said:

I adore infinite loops cuz they make the computer look stupid

while(true) cout<<"<<<<<>";

when the console starts maximize it's window and stare into it, now move your eyes slowly from the top to the bottom of the window, you will see a very beautiful waterfall :)

That language is that?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#10
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
C++
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#11
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
OK thanks Winged, I will need to put it in my compiler. But I don't know it, so anyone got the complete code with the includes?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#12
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,674 posts

#include<iostream>

using namespace std;


int main()

{

while(true) cout<<">>>>><";

return 0;

}

sorry i didnt post it before