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 401,713 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 4,126 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.
Views: 12311 | Replies: 81
Reply
Join Date: Dec 2004
Posts: 1,590
Reputation: tgreer is an unknown quantity at this point 
Rep Power: 7
Solved Threads: 34
Colleague
tgreer tgreer is offline Offline
Made Her Cry

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

  #11  
May 9th, 2006
Well, since the goal is to PRINT 1 - 10, I give you:

PostScript
%!PS

% position constants and procs
/x 72 def 
/yPos 700 def
/y {yPos lnHeight sub dup /yPos exch def} bind def

% font constants
/fontName /Courier def
/ptSize 12 def
/lnHeight ptSize 1.2 mul def

% set the font
fontName ptSize selectfont

% for loop to paint numbers
1 1 10 { 5 string cvs x y moveto show} for

% commit page image to currentpage
showpage
Reply With Quote  
Join Date: Apr 2006
Location: San Luis Obispo, CA
Posts: 34
Reputation: CaliVagabond is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
CaliVagabond CaliVagabond is offline Offline
Light Poster

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

  #12  
May 9th, 2006
In C

#include <stdio.h>

#define MIN_RANGE 1
#define MAX_RANGE 10

int main (void)
{
       int i;

       for (i = MIN_RANGE; i <= MAX_RANGE; i++)
              printf("%i\n", i);

       return 0;
}
Reply With Quote  
Join Date: Jun 2005
Location: Troy
Posts: 1,277
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]!

  #13  
May 9th, 2006
I would've done one in Tama, but it's not Turing complete so doesn't deserve it.

Ruby:
(1..10).each { |x| puts x }
Reply With Quote  
Join Date: Sep 2004
Posts: 6,059
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: 419
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

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

  #14  
May 9th, 2006
My Tama, or some other language I haven't heard of? If you're talking about mine, yea, it's pretty lame. I never got around to really improving it.
I'm a programmer. My attitude starts with arrogance, holds steady at condescension, and ends with hostility. Get used to it.
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]!

  #15  
May 9th, 2006
Jess, was this thread inspire by the one on PFO .

Of course not.

Bah, I wanted to be the first to use Ruby. Anyways...

Ruby
puts *(1..10)
--Jessehk
Reply With Quote  
Join Date: Jun 2005
Location: Troy
Posts: 1,277
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]!

  #16  
May 9th, 2006
Here's um, another Scheme version:
(let loop ((i 1))
  (cond ((<= i 10)
         (display i)
         (loop (+ i 1))))
And another...
(define (range n m)
  (if (> n m)
      '()
      (cons n (range (+ n 1) m))))
(for-each display (range 1 10))
Reply With Quote  
Join Date: Jun 2004
Location: H4x0rville
Posts: 2,105
Reputation: server_crash is on a distinguished road 
Rep Power: 9
Solved Threads: 18
server_crash's Avatar
server_crash server_crash is offline Offline
Postaholic

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

  #17  
May 9th, 2006
Ohhh yeahh. Predicates with internal state.

#include <iostream>
#include <list>
#include <algorithm>
using namespace std;

template <class T>
inline void PRINT_ELEMENTS(const T& coll, const char* optc="")
{
    std::cout << optc;
    typename T::const_iterator pos;
    for (pos=coll.begin(); pos != coll.end(); ++pos)
    {
      std::cout << *pos << " ";
    }
}


class IntSequence
{
  public:
    //constructor
    IntSequence(int initialValue)
    : value(initialValue) { }

    //function call
    int operator() ()
    {
      return value++;
    }

  private:
    int value;
};

int main()
{
  list<int> coll;

  //insert values from 1 to 9
  generate_n(back_inserter(coll), //start
             10,                   //number of elements
             IntSequence(1));     //generates values

  PRINT_ELEMENTS(coll);
  cout << endl;
}
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]!

  #18  
May 9th, 2006
C

#include <stdio.h>

void count(int start, int end);

int main(void) {
    count(1, 10);

    return 0;
}

void count(int start, int end) {
    int x;

    for(x = start; x <= end; x++)
        printf("%d\n", x);
}
--Jessehk
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]!

  #19  
May 9th, 2006
Python

for x in range(10):
    print x + 1
--Jessehk
Reply With Quote  
Join Date: Aug 2005
Posts: 4,709
Reputation: iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light iamthwee is a glorious beacon of light 
Rep Power: 17
Solved Threads: 309
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

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

  #20  
May 10th, 2006
Java

class Pedantic
{
   public static void main(String[] args)
  {
      for(int i=1; i <=10; i++)
     {
       System.out.println(i);
      }
   }
}
Reply With Quote  
Reply

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

DaniWeb Software Developers' Lounge Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Software Developers' Lounge Forum

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