| | |
500 ways to print [1..10]!
![]() |
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
Well, since the goal is to PRINT 1 - 10, I give you:
PostScript
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•
•
Join Date: Apr 2006
Posts: 34
Reputation:
Solved Threads: 0
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;
} I would've done one in Tama, but it's not Turing complete so doesn't deserve it.
Ruby:
Ruby:
(1..10).each { |x| puts x } All my posts may be redistributed under the GNU Free Documentation License.
•
•
•
•
Jess, was this thread inspire by the one on PFO.

Bah, I wanted to be the first to use Ruby. Anyways...
Ruby
puts *(1..10)
--Jessehk
Here's um, another Scheme version:
And another...
(let loop ((i 1))
(cond ((<= i 10)
(display i)
(loop (+ i 1))))(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.
•
•
Join Date: Jun 2004
Posts: 2,108
Reputation:
Solved Threads: 18
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;
} 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
![]() |
Other Threads in the IT Professionals' Lounge Forum
- Previous Thread: Merrrrryyyyy Christmas!
- Next Thread: creating skins
Views: 16544 | Replies: 81
| Thread Tools | Search this Thread |
Tag cloud for IT Professionals' Lounge
advice answers budget buy career carrier css degrees education game gaming gpu infodelivery infotech interview kindle microsystems multiple-os networking news pc php program projects questions r&d saas schools security simple sms spoof ssl sun tabletpc touch-screen touchscreen training vbulletin videoinprint vulnerability webdesign windows







I never got around to really improving it.