500 ways to print [1..10]!

Reply

Join Date: May 2006
Posts: 19
Reputation: Jessehk is an unknown quantity at this point 
Solved Threads: 2
Jessehk's Avatar
Jessehk Jessehk is offline Offline
Newbie Poster

500 ways to print [1..10]!

 
0
  #1
May 8th, 2006
*Hopefull this hasn't been done already*

Write a program that when run, will print out the numbers 1 through 10. The program can be in any language, and can be as complicated or simple as you want.

Lets see how creative people are, and get up to 500 unique ways!

I'll start out with something simple:

C++
#include <iostream>

int main() {
    int x = 1, y = 10;

    while(y--)
        std::cout << x++ << std::endl;
}

EDIT: I guess we'll let the post count determine the number of different ways that have been produced.
--Jessehk
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: 500 ways to print [1..10]!

 
0
  #2
May 8th, 2006
C#

using System;

class onetoten
{
	public static void Main ()
	{
		for (int x = 0; x < 11; x++)
		{
			Console.Write(x);
		}
	}
}
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 19
Reputation: Jessehk is an unknown quantity at this point 
Solved Threads: 2
Jessehk's Avatar
Jessehk Jessehk is offline Offline
Newbie Poster

Re: 500 ways to print [1..10]!

 
0
  #3
May 8th, 2006
Scheme

(define range
  (lambda (s e)
    (cond ((< s e) (cons s
                         (range (+ s 1) e)))
          ((= s e) (list s))
          (else "Invalid function call"))))

(range 1 10) ;=> (1 2 3 4 5 6 7 8 9 10)
--Jessehk
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: 500 ways to print [1..10]!

 
0
  #4
May 8th, 2006
3.) VB Script

MsgBox "1, 2, 3, 4, 5, 6, 7, 8, 9, 10", vbOKOnly, "Count!"

Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 19
Reputation: Jessehk is an unknown quantity at this point 
Solved Threads: 2
Jessehk's Avatar
Jessehk Jessehk is offline Offline
Newbie Poster

Re: 500 ways to print [1..10]!

 
0
  #5
May 9th, 2006
C++
#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>

int main() {
    std::vector<int> numbs(0);

    for(int x = 1; x <= 10; x++)
        numbs.push_back(x);

    std::copy(numbs.begin(), numbs.end(), std::ostream_iterator<int>(std::cout, "\n"));
}
--Jessehk
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: 500 ways to print [1..10]!

 
0
  #6
May 9th, 2006
Originally Posted by tayspen
C#

using System;

class onetoten
{
	public static void Main ()
	{
		for (int x = 0; x < 11; x++)
		{
			Console.Write(x);
		}
	}
}
Blah... you have to show off the features of object orientation:

using System;
using System.Collections.Generic;
using System.Text;

namespace counting
{
    public class Counter
    {
        private int count = 1;

        public int Count
        {
            get
            {
                return count;
            }
            set
            {
                count = value;
            }
        }
    }

    class Program
    {
        public static void Main()
        {
            Counter number = new Counter();
            do
            {
                Console.WriteLine(number.Count.ToString());
                number.Count++;
            } while (number.Count <= 10);

        }
    }
}

Looks like a lot more code... Well, it is, but now I've created a reusable object that does all of the work, and I could change it later on so to have a different starting number, or even determine the number some other way.
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,542
Reputation: tayspen is on a distinguished road 
Solved Threads: 98
Team Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

Re: 500 ways to print [1..10]!

 
0
  #7
May 9th, 2006
That is indeed a better way you did it though. But alot more code


Another one; Doesnt really 'count" but it prints .

C#

MessageBox.Show("1, 2, 3, 4, 5, 6, 7, 8, 9, 10");

Yea, it's beginner, yet it gets the job done. Now off to create a complicated one.

Jess, was this thread inspire by the one on PFO .
Firefox
Ewido
Tune up windows
Get detailed system information
My Fixes

Member - Alliance of Security Analysis Professionals - Since 2006
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: 500 ways to print [1..10]!

 
0
  #8
May 9th, 2006
Perl:
print "$_\n" for 1..10
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,566
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 705
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: 500 ways to print [1..10]!

 
0
  #9
May 9th, 2006
FASM Assembly:
format PE console
entry start

include 'C:\fasmw\include\win32a.inc'

;======================================
section '.data' data readable writeable
;======================================

num_fmt db '%d',10,0

;=======================================
section '.code' code readable executable
;=======================================

start:
	mov	ebx,10
    .again:
	lea	eax,[ebx-11]
	neg	eax
	ccall	[printf],num_fmt,eax
	dec	ebx
	jnz	.again
	stdcall	[ExitProcess],0

;=====================================
section '.import' import data readable
;=====================================

library kernel,'kernel32.dll',\
	msvcrt,'msvcrt.dll'

import kernel,\
       ExitProcess,'ExitProcess'

import msvcrt,\
       printf,'printf'
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: 500 ways to print [1..10]!

 
0
  #10
May 9th, 2006
Haskell:
main = mapM (putStr . (++ "\n") . show) [1..10]
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the IT Professionals' Lounge Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC