User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Software Developers' Lounge section within the Software Development category of DaniWeb, a massive community of 391,709 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,394 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Software Developers' Lounge advertiser:
Views: 12235 | Replies: 81
Reply
Join Date: May 2006
Location: Ontario, Canada
Posts: 18
Reputation: Jessehk is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Jessehk's Avatar
Jessehk Jessehk is offline Offline
Newbie Poster

500 ways to print [1..10]!

  #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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jul 2005
Location: FL.
Posts: 1,536
Reputation: tayspen is on a distinguished road 
Rep Power: 7
Solved Threads: 98
Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

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

  #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  
Join Date: May 2006
Location: Ontario, Canada
Posts: 18
Reputation: Jessehk is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Jessehk's Avatar
Jessehk Jessehk is offline Offline
Newbie Poster

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

  #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  
Join Date: Jul 2005
Location: FL.
Posts: 1,536
Reputation: tayspen is on a distinguished road 
Rep Power: 7
Solved Threads: 98
Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

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

  #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  
Join Date: May 2006
Location: Ontario, Canada
Posts: 18
Reputation: Jessehk is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
Jessehk's Avatar
Jessehk Jessehk is offline Offline
Newbie Poster

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

  #5  
May 8th, 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  
Join Date: Dec 2003
Location: Nashville, TN
Posts: 2,333
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Rep Power: 11
Solved Threads: 101
Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

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

  #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  
Join Date: Jul 2005
Location: FL.
Posts: 1,536
Reputation: tayspen is on a distinguished road 
Rep Power: 7
Solved Threads: 98
Colleague
tayspen's Avatar
tayspen tayspen is offline Offline
<Insert title here>

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

  #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  
Join Date: Jun 2005
Location: Troy
Posts: 1,276
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 36
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

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

  #8  
May 9th, 2006
Perl:
print "$_\n" for 1..10
Reply With Quote  
Join Date: Sep 2004
Posts: 6,017
Reputation: Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of Narue has much to be proud of 
Rep Power: 26
Solved Threads: 414
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

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

  #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'
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Jun 2005
Location: Troy
Posts: 1,276
Reputation: Rashakil Fol has a spectacular aura about Rashakil Fol has a spectacular aura about 
Rep Power: 7
Solved Threads: 36
Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Salamander Man

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

  #10  
May 9th, 2006
Haskell:
main = mapM (putStr . (++ "\n") . show) [1..10]
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb Software Developers' Lounge Marketplace
Thread Tools Display Modes

Other Threads in the Software Developers' Lounge Forum

All times are GMT -4. The time now is 3:06 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC