User:Yeti: Difference between revisions

From Rosetta Code
Content added Content deleted
m (meh)
(Blanked the page)
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
=My Sandbox=
I need to get used to this flavour of markup first. That'll take some time. Meanwhile I collect my examples here. If you think, some example is worth being moved to the "right" place, feel free to do so and leave me a note...

----

=DC/Questions/DROP=
TODO Drop top of stack without side effects
<pre>
# assume there is a value in x[1337], e.g. "gold"
[gold] 1337 :x

# "trash" on the stack:
[trash]

# push x[1337] to x-stack
1337;x Sx
# deposit TOS in x[1337]
1337:
# top of x-stack to x[1337]
Lx 1337:

1337 ;x

[Stack: ]PAP f
</pre>
{{out}}
<pre>
Stack:
gold
</pre>
Sigh!

Is there really no simpler way to drop the top of stack that works for strings and numbers and in all versions of Dc?

=Python/Primes/FSOE=
{{works with|Python|2.x}}
This is a sequentialised variant of the well known sieve method (ab)using a dictionary as sparse array.
<lang python>L = {}
n = 2

while 1:

if n in L:
P = L[n]
del L[n] # optional - saves some memory.
else:
print n
P = [n]

for p in P:
npp = n+p
if npp in L:
L[npp].add(p)
else:
L[npp] = set([p])

n += 1</lang>

{{out}}
<pre>
2
3
5
7
11
13
17
19
23
29
</pre>
...the program has to be terminated by the user e.g. by typing ctrl-c.

----

{{mylangbegin}}
{{mylang|AWK|}}
{{mylang|C|}}
{{mylang|Dc|}}
{{mylang|Spin|}}
{{mylangend}}

Latest revision as of 09:25, 7 June 2021