500 ways to print [1..10]!

Reply

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
  #31
May 15th, 2006
I thought it was funny, but I don't know why it got edited.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 3
Reputation: nightowl512 is an unknown quantity at this point 
Solved Threads: 0
nightowl512's Avatar
nightowl512 nightowl512 is offline Offline
Newbie Poster

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

 
0
  #32
May 16th, 2006
Old Fashon Vic 20 BASIC

10 fort = 1 to 10
20 print t
30 next t
NightOwl512
nightowl512@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 10
Reputation: julesjacobs is an unknown quantity at this point 
Solved Threads: 0
julesjacobs julesjacobs is offline Offline
Newbie Poster

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

 
0
  #33
Jun 18th, 2006
puts (1..10).to_a
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 523
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

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

 
0
  #34
Jun 21st, 2006
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
Last edited by pty; Jun 21st, 2006 at 6:24 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
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: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
3
  #35
Jun 21st, 2006
Here's another Haskell version.
main = mapM_ (putStrLn . show) [1..10]
Last edited by Rashakil Fol; Jun 21st, 2006 at 8:08 pm.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 494
Reputation: Puckdropper is an unknown quantity at this point 
Solved Threads: 21
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

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

 
1
  #36
Jul 29th, 2006
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
  }
Last edited by Puckdropper; Jul 29th, 2006 at 11:51 pm.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

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

 
0
  #37
Aug 4th, 2006
ForTran
        integer i
        do 100 i=1,10
100     write(5,200) i
200     format("i3")
        end
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

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

 
0
  #38
Aug 4th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
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: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
1
  #39
Aug 4th, 2006
Brain****:
+++[>++++[>++++<-]<-]>
++++++++++>
+.<.>+.<.>+.<.>+.<.>+.<.>
+.<.>+.<.>+.<.>+.<.>
--------.-.<.
All my posts may be redistributed under the GNU Free Documentation License.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,052
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: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

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

 
2
  #40
Aug 4th, 2006
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
All my posts may be redistributed under the GNU Free Documentation License.
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
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC