943,867 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
May 9th, 2006
0

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

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
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
May 9th, 2006
0

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

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;
}
Reputation Points: 10
Solved Threads: 0
Light Poster
CaliVagabond is offline Offline
34 posts
since Apr 2006
May 9th, 2006
2

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

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 }
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
May 9th, 2006
0

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

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.
Administrator
Reputation Points: 6442
Solved Threads: 1393
Bad Cop
Narue is offline Offline
11,807 posts
since Sep 2004
May 9th, 2006
0

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

Quote ...
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)
Reputation Points: 33
Solved Threads: 2
Newbie Poster
Jessehk is offline Offline
19 posts
since May 2006
May 9th, 2006
2

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

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))
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
May 9th, 2006
0

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

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;
}
Reputation Points: 113
Solved Threads: 19
Postaholic
server_crash is offline Offline
2,108 posts
since Jun 2004
May 9th, 2006
0

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

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);
}
Reputation Points: 33
Solved Threads: 2
Newbie Poster
Jessehk is offline Offline
19 posts
since May 2006
May 10th, 2006
0

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

Python

for x in range(10):
    print x + 1
Reputation Points: 33
Solved Threads: 2
Newbie Poster
Jessehk is offline Offline
19 posts
since May 2006
May 10th, 2006
0

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

Java

class Pedantic
{
   public static void main(String[] args)
  {
      for(int i=1; i <=10; i++)
     {
       System.out.println(i);
      }
   }
}
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in IT Professionals' Lounge Forum Timeline: Merrrrryyyyy Christmas!
Next Thread in IT Professionals' Lounge Forum Timeline: creating skins





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC