Die Seite wurde neu angelegt: [http://en.wikipedia.org/wiki/Dc_%28Unix%29 dc] ist eine Programmiersprache, die auf fast jedem Unix-Rechner installiert ist. dc ist sehr minimalistisch und gerade daru...

This commit is contained in:
Toidinamai 2007-05-25 09:51:46 +00:00
parent 647a04f71b
commit e30be59794
1 changed files with 76 additions and 0 deletions

76
Dc.mw Normal file
View File

@ -0,0 +1,76 @@
[http://en.wikipedia.org/wiki/Dc_%28Unix%29 dc] ist eine Programmiersprache, die auf fast jedem Unix-Rechner installiert ist.
dc ist sehr minimalistisch und gerade darum macht es Spaß, darin zu programmieren. Bitte tragt eure
eigenen dc-Programme hier ein:
==Range==
Zum Warmwerden. Das folgende Programm gibt einfach aufeinanderfolgende Zahlen innerhalb der vorgegebenen Schranken aus:
<pre>
#!/usr/bin/env dc
[Starting from? ]n?sa
[Up to? ]n?sb
# a is the lower bound
# b is the upper bound
[
# load lower bound
la
# print lower bound
p
# increment
1+
# store upper bound
dsa
# copy lower bound
lbdsb
# compare and recurse
>f
]sf
# call f
lfdsfx
</pre>
Besonders schön sieht das dann als Einzeiler ohne Kommentare aus:
[Starting from? ]n?sa[Up to? ]n?sb[lap1+dsalbdsb>f]sflfdsfx
==Fibonacci==
Ein Klassiker. Die [http://de.wikipedia.org/wiki/Fibonacci-Folge Fibonacci-Zahlen] sind rekursiv definiert:
die ersten beiden Zahlen sind 0 und 1, jede weitere ist die Summe ihrer beiden vorhergehenden.
<pre>
#!/usr/bin/env dc
[How many fibonacci numbers should be computed? ]n?sa
# start values
0p 1p
# counter
1sb
[
# save second summand
dsc
# add numbers on stack
+
# restore second summand as new first
lcr
# print
p
# check counter and recurse
lb1+dsbladsa>f
]sf
# call f
lfdsfx
</pre>
==Sieb des Eratosthenes==
TBD