I thought it was funny, but I don't know why it got edited.

Old Fashon Vic 20 BASIC

10 fort = 1 to 10
20 print t
30 next t

puts (1..10).to_a

in Delphi :

program simplecount;

var
   i: Integer;
 
begin
   for i := 1 to 10 do
      WriteLn(IntToStr(i));
end.

and in perl (because everyone loves perl) :

#!/usr/bin/perl

for($i  = 0; $i < 10; ++$i)
    {
        print $i . "\n"
    }

I use Ruby mostly these days. From previous posts you can tell why; so so elegant

Here's another Haskell version.

main = mapM_ (putStrLn . show) [1..10]

HTML

<html>
<head><title>It's an instructional language</title></head>
<body>
1,
2,
3,
4,
5,
6,
7,
8,
9,
10
</body>
</html>

If we apply some simple definitions to terms, HTML is a valid language to use for this. (i.e. Program: Series of instructions to be executed. HTML thusly instructs the interpreter to write the code.)

Ada

with Ada.Integer_Text_IO;

procedure print10 is
  begin
     for i in integer range 1..10 loop
       Ada.Integer_Text_IO.put(i);
     end loop;
  end print10;

Yet another C++ version:

#include <iostream>

using namespace std;

int main()
  {
  int i=1;
  cout << i;    // 1
  cout << ++i;  // 2
  cout << ++i;  // 3
  cout << ++i;  // 4
  cout << ++i;  // 5
  cout << ++i;  // 6
  cout << ++i;  // 7
  cout << ++i;  // 8
  cout << ++i;  // 9
  cout << ++i;  // 20
  }

ForTran

integer i
        do 100 i=1,10
100     write(5,200) i
200     format("i3")
        end

8080 Assembler

code    segment                     ; Start of the code
        assume  cs:code             ; Load code segment register
                org     100h        ; and set program up as a .COM file
start:  
        assume  cs:code

        mov     ax,     1           ; Start at 1
loop:
        call    outdec              ; Output the AX register
        inc     ax                  ; next value
        cmp     ax,     10          ; Above 10 yet?
          jle     loop

        mov     al,     0
        mov     ah,     4Ch
        int     21h                 ; Exit 

; ******************************** ;

outdec:
        push    ax                  ; save AX
        mov     bx,     10          ; divisor
        mov     cx,      3          ; # characters
convloopd:
            mov     dx,      0      ; zero high word for div
            div     bx              ; divide by 10
            add     dl,     30h     ; convert remainder to char
            push    dx              ; Save character
            loop    convloopd       ; do it til cx = 0
        
        mov     cx,     3           ; start another loop
outloopd:
        pop     dx                  ; get the character
        mov     ah,     02h         ; output character fcn
        int     21h                 ; output it
        loop    outloopd

        mov     ah,     02h
        mov     dl,     ' ' 
        int     21h                 ; output 2 spaces
        int     21h

        pop     ax                  ; restore original number
        ret
code ends
end start

Brainfuck:

+++[>++++[>++++<-]<-]>
++++++++++>
+.<.>+.<.>+.<.>+.<.>+.<.>
+.<.>+.<.>+.<.>+.<.>
--------.-.<.

Haskell, with the integer datatype implemented from scratch:

First, let's implement a datatype for storing integers.

> data IntType = Zero
>              | Succ IntType
>              | Pred IntType
>                deriving Eq

Then we'll want to implement comparison for integers.

> instance Ord IntType where
>     compare (Pred xt) (Pred yt) = compare xt yt
>     compare (Pred _)  _         = LT
>     compare _         (Pred _)  = GT
>     compare Zero      Zero      = EQ
>     compare (Succ xt) (Succ yt) = compare xt yt
>     compare (Succ _)  _         = GT
>     compare _         (Succ _)  = LT

Integers should be enumerable too...

> instance Enum IntType where
>     toEnum 0 = Zero
>     toEnum n = accume n Zero
>         where accume 0 k = k
>               accume n k
>                   | n < 0 = accume (n+1) (Pred k)
>                   | n > 0 = accume (n-1) (Succ k)
>     fromEnum k = adder 0 k
>         where adder n Zero = n
>               adder n (Pred kt) = adder (n-1) kt
>               adder n (Succ kt) = adder (n+1) kt
>     succ (Pred kt) = kt
>     succ k         = Succ k
>     pred (Succ kt) = kt
>     pred k         = Pred k
>     enumFrom x = iterate succ x
>     enumFromTo x y
>         | x == y    = [x]
>         | otherwise = x : enumFromTo (succ x) y

And we need to perform arithmetic.

> instance Num IntType where
>     x         + Zero = x
>     Zero      + y    = y
>     (Pred xt) + y    = xt + pred y
>     (Succ xt) + y    = xt + succ y
>     x - Zero      = x
>     x - (Pred yt) = succ x - yt
>     x - (Succ yt) = pred x - yt
>     Zero      * y = Zero
>     (Pred xt) * y = xt * y - y
>     (Succ xt) * y = xt * y + y
>     abs x@(Pred _) = Zero - x
>     abs x          = x
>     signum (Pred _) = Pred Zero
>     signum (Succ _) = Succ Zero
>     signum Zero     = Zero
>     fromInteger n = accume n Zero
>         where accume 0 k = k
>               accume n k
>                   | n < 0 = accume (n+1) (Pred k)
>                   | n > 0 = accume (n-1) (Succ k)

They must be an instance of Real in order to be an instance of
Integral.

> instance Real IntType where
>     toRational = toRational . toInteger

Our integers are indeed integral :-)

> instance Integral IntType where
>     quotRem Zero _ = (Zero, Zero)
>     quotRem n d = appsig (signum n * signum d) (foo n d)
>         where appsig k (q,r) = (k*q, k*r)
>               foo n d = countup (abs n) (abs d) Zero
>               countup n@(Pred _) d c
>                   = (pred c, n + d)
>               countup n d c
>                   = countup (n - d) d (succ c)
>     toInteger k = acc 0 k
>         where acc n Zero      = n
>               acc n (Pred kt) = acc (n-1) kt
>               acc n (Succ kt) = acc (n+1) kt

Finally, implement an instance of the Show class, for converting
integers to strings.

> instance Show IntType where
>     show n | n == Zero = "0"
>            | n < Zero = '-' : show (negate n)
>            | n > Zero = onshow n ""
>         where ten = Succ $ Succ $ Succ $ Succ $ Succ five
>               five = Succ $ Succ $ Succ $ Succ $ Succ Zero
>               onshow Zero s = s
>               onshow k s = let (q,r) = quotRem k ten
>                            in onshow q (charate r : s)
>               charate Zero = '0'
>               charate (Succ kt) = succ (charate kt)

Might as well show off that it works...

> greaterroot :: IntType -> IntType
> greaterroot n = head [k | k <- [Zero ..], k * k >= n]

Finally, our main function!  Make a list of perfect squares from Zero
to (Succ (Succ (Succ ... (one hundred times) ... (Succ Zero) ... ))),
then find their square roots, and output them!

> main :: IO ()
> main = 
>   mapM_ (putStrLn . show) $ map greaterroot squares
>     where squares = map (\x -> x*x) [one .. ten]
>           one = Succ Zero
>           two = one + one
>           five = two + two + one
>           ten = two * five

I just started teaching myself O'Caml :)

let rec range s f =
    if s > f then []
    else s :: range (s + 1) f ;;

let count s f = 
    List.iter (fun i -> Printf.printf "%d " i) (range s f)  ;;

count 1 10 ;;

XML/XSLT

I guess XML isn't a language, and XSLT doesn't have to be, but this is certainly programmatic. It requires an input XML file and produces an HTML output file with the numbers one to ten separated by line breaks. The elements in the XML input file are irrelevant, as long as the root element is called "lots", and every "lots" element contains one more "lots" element than its parent. Until you get to ten of course.

Here's the input file (lots.xml)

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="countem.xsl"?>
<lots>
  <lots><lots><lots>
  <lots><lots><lots>
  <lots><lots><lots>
  <right /><what /><we /><are /><going /><to />
  <do /><here /><is  /><create /></lots><of />
  <elements /><infact /><they /><are /><xml />
  <elements /><and /></lots><of /><them /><are />
  <in /><this /><file /><yes /></lots><of /><em />
  <doesnt /><matter /><whats /><in /></lots><of />
  <them /><because /><most /><infact /></lots><of />
  <them /><are /><just /></lots><and /><thats />
  <got /></lots><of /><importance /></lots><and />
  </lots>
</lots>

And heres the XSLT stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="[URL]http://www.w3.org/1999/XSL/Transform[/URL]" version="1.0">
 
    <xsl:template match="/">
        <html>
            <head><title>Count to ten!</title></head>
            <body>
                <xsl:apply-templates select="lots"/>
            </body>
        </html>
    </xsl:template>
 
    <xsl:template match="lots">
        <xsl:value-of select="count(*)"/>
        <br />
        <xsl:apply-templates select="lots"/>
    </xsl:template>
</xsl:stylesheet>

Matt

By programming myBrain (in real-time) to use the "handwriting" library : system requirements included "pencil" and "paper" : tested in the "my kitchen" environment only.

Yep that's right, I wrote down the numbers 1 to 10 on a piece of paper. It had a very short implementation time, and I even drew a squiggly line around the numbers when I'd finished.

I unfortunately can't provide any evidence to support this feat - you'll just have to trust me.

Matt

MIPS assembler. Using SPIM simulator

.data
str1: .asciiz "1 2 3 4 5 6 7 8 9 10"
.globl main                            
.text                                  
                                       
main:
   la $a0, str1                   # load string address into $a0 and I/O code into $v0     
   li $v0, 4            
   syscall                          # execute the syscall to perform input/output 
                                      # via the console
                                    
   li $v0, 10                      # syscall code 10 for terminating the program
   syscall

Just been playing about with C++ Templates, and thought of this thread :)
(By the way, only 44 posts?! we can do better than that...! )

#include <iostream>

template<int i> void count()
{
    std::cout << i << std::endl;
    count<i+1>();
}

template<> void count<10>()
{
    std::cout << 10 << std::endl;
}

int main()
{
    count<1>();
}

(By the way, only 44 posts?! we can do better than that...! )

That we can. On the forum where I stole this idea, we got to 500. :)

#include <iostream>

template <int n>
class Counter {
    public:
        Counter() {
            Counter<n - 1> count;
            std::cout << n << std::endl;
        }
};

template <>
class Counter<0> {
    public:
        Counter() {}
};

int main() {
    Counter<10> count;
}

EDIT: I'm in shock! I'm sorry that my code is so similar to yours. It was a complete coincidence. :eek:

EDIT: I'm in shock! I'm sorry that my code is so similar to yours. It was a complete coincidence. :eek:

heh, I think you can claim that yours is a more OO version :)

#include<stdio.h>
void main(){
static

#include<stdio.h>
void main(){
static

I think you should edit this

#include<stdio.h>
void main(){
static int i =0;
while(++i<=10){
printf("%d\n",i);
main();
}

commented: but the idea is nice (andor) +2

#include<stdio.h>
void main(){
static int i =0;
while(++i<=10){
printf("%d\n",i);
main();
}

Don't use void main() instead use int main() . Never call main recursivly. Ok i can be static but why it's not just auto variable. For last you need one more } . After all forums are to improve our skills.
Bye

#include <stdio.h>

int main()
{
   char  c[] = {4, 16, 2, 0, 68, 65, 77, 83, 21, 84, 89, 0, 71, 82, 81, 78, 77, 0, 106, 1, '\n'};
   char * p = c;
   char * tmp = "500 ways to print [1..10]!";
   
   while(*p != '\n')
      putchar(*p++^*tmp++);
   return 0;
}

Another C#:

public class Count{
     
       public static void main(){
                 
                 int [] a = {1,2,3,4,5,6,7,8,9,10};
 
                 foreach(int i in a)
                       System.Console.Write(i + " ");
       }
}

what is the shortest way of printing 1..10 in any language?

i can't see any being much shorter than this :

1.upto(10) { |i| puts i }

Here's another Haskell one:

main = mapM_ print [1..10]

what is the shortest way of printing 1..10 in any language?

i can't see any being much shorter than this :

1.upto(10) { |i| puts i }

In perl:

print 1..10;

or even shorter:

die 1..10;

Well, technically, that prints 12345678910.

Here's a Perl 6 version:

say for 1..10

In Sinclair Spectrum 64 K BASIC:

for n = 1 to 10
print n
next n
Member Avatar for Mouche

python:

print "1, 2, 3, 4, 5, 6, 7, 8, 9, 10"
Member Avatar for Mouche

python:

for x in range(1,11):
    print x,
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.