| | |
500 ways to print [1..10]!
![]() |
in Delphi :
and in perl (because everyone loves perl) :
I use Ruby mostly these days. From previous posts you can tell why; so so elegant
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.
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.
•
•
Join Date: Jul 2004
Posts: 494
Reputation:
Solved Threads: 21
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
Yet another C++ version:
<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.
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.
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 Brain****:
+++[>++++[>++++<-]<-]> ++++++++++> +.<.>+.<.>+.<.>+.<.>+.<.> +.<.>+.<.>+.<.>+.<.> --------.-.<.
All my posts may be redistributed under the GNU Free Documentation License.
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.
![]() |
Other Threads in the IT Professionals' Lounge Forum
- Previous Thread: Merrrrryyyyy Christmas!
- Next Thread: creating skins
| Thread Tools | Search this Thread |
1gbit advertising advice amazon answers archive british broadband business businessprocesses career carrier censorship cern china cio collectiveintelligence connectivity consumer consumers corporateearnings datatransfer debtcollectors dictionary digg digital ebay ecommerce email employment environment facebook food government grid high-definition hottub infodelivery infotech intel internet interview ipod isp japan kindle lhc library malware marketing mit moonfruit news onlineshopping piracy piratebay pope porn program questions r&d religion remoteworking research retail security sex shopping simple skype smallbusiness smb sms socialmedia socialnetworking software softwareengineer spam speed spending startrek statistics stocks study stumbleupon survey tabletpc technology touch-screen touchscreen twitter uk videoinprint voips web webdeveloper windows words






