Examples
Print primes number :
echo '2p3ps#s@s&ds.x'|dcAs an example of a relatively simple program in dc, this command (in 1 line):
dc -e 'psj]shsz PnP10Pdx]dx'will convert distances from metres to feet and inches; the bulk of it is concerned with prompting for input, printing output in a suitable format and looping round to convert another number.
As an example, here is an implementation of the Euclidean algorithm to find the GCD:
dc -e '??dsax+p' # shortest dc -e 'P?P?dsax+Pp' # easier-to-read versionComputing the factorial of an input value,
dc -e '?sQdsFxp'A more complex example performs Diffie-Hellman key exchange. This was popular as a signature block among cypherpunks during the ITAR debates:
#!/usr/bin/perl -- -export-a-crypto-system-sig Diffie-Hellman-2-lines ($g,$e,$m)=@ARGV,$m||die"$0 gen exp mod\n";print`echo "16dio1[d2%Sa2/d0Read more about this topic: Dc (computer Program)
Famous quotes containing the word examples:
“In the examples that I here bring in of what I have [read], heard, done or said, I have refrained from daring to alter even the smallest and most indifferent circumstances. My conscience falsifies not an iota; for my knowledge I cannot answer.”
—Michel de Montaigne (15331592)
“Histories are more full of examples of the fidelity of dogs than of friends.”
—Alexander Pope (16881744)
“No rules exist, and examples are simply life-savers answering the appeals of rules making vain attempts to exist.”
—André Breton (18961966)