500 ways to print [1..10]!

Reply

Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

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

 
0
  #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 Quick reply to this message  
Join Date: Apr 2006
Posts: 34
Reputation: CaliVagabond is an unknown quantity at this point 
Solved Threads: 0
CaliVagabond CaliVagabond is offline Offline
Light Poster

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

 
0
  #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 Quick reply to this message  
Join Date: Jun 2005
Posts: 2,081
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: 142
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
2
  #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 }
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: 8,313
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: 825
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

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

 
0
  #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.
In case you were wondering, yes, I do hate you.
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
  #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 Quick reply to this message  
Join Date: Jun 2005
Posts: 2,081
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: 142
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
2
  #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))
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 2,108
Reputation: server_crash is on a distinguished road 
Solved Threads: 18
server_crash server_crash is offline Offline
Postaholic

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

 
0
  #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 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
  #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 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
  #19
May 9th, 2006
Python

for x in range(10):
    print x + 1
--Jessehk
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,321
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 384
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

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

 
0
  #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 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


Views: 16544 | Replies: 81
Thread Tools Search this Thread



Tag cloud for IT Professionals' Lounge
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC