User:Yeti: Difference between revisions
Content added Content deleted
(→Spin) |
|||
Line 5: | Line 5: | ||
=Mandelbrot Set= |
=Mandelbrot Set= |
||
==Bourne Again SHell== |
|||
{{works with|BASH|4}} |
|||
<lang bash>((xmin=-8601)) # int(-2.1*4096) |
|||
((xmax=2867)) # int( 0.7*4096) |
|||
((ymin=-4915)) # int(-1.2*4096) |
|||
((ymax=4915)) # int( 1.2*4096) |
|||
((maxiter=30)) |
|||
((dx=(xmax-xmin)/72)) |
|||
((dy=(ymax-ymin)/24)) |
|||
C='0123456789' |
|||
((lC=${#C})) |
|||
for((cy=ymax;cy>=ymin;cy-=dy)) ; do |
|||
for((cx=xmin;cx<=xmax;cx+=dx)) ; do |
|||
((x=0,y=0,x2=0,y2=0)) |
|||
for((iter=0;iter<maxiter && x2+y2<=16384;iter++)) ; do |
|||
((y=((x*y)>>11)+cy,x=x2-y2+cx,x2=(x*x)>>12,y2=(y*y)>>12)) |
|||
done |
|||
((c=iter%lC)) |
|||
echo -n ${C:$c:1} |
|||
done |
|||
echo |
|||
done</lang> |
|||
{{out}} |
|||
<pre> |
|||
1111111111111222222222222333333333333333333333333333333333222222222222222 |
|||
1111111111112222222233333333333333333333344444456015554444333332222222222 |
|||
1111111111222222333333333333333333333444444445556704912544444433333222222 |
|||
1111111112222333333333333333333333444444444555678970508655544444333333222 |
|||
1111111222233333333333333333333444444444556667807000002076555544443333333 |
|||
1111112223333333333333333333444444455577898889016000003099766662644333333 |
|||
1111122333333333333333334444455555566793000800000000000000931045875443333 |
|||
1111123333333333333344455555555566668014000000000000000000000009865544333 |
|||
1111233333333344445568277777777777880600000000000000000000000009099544433 |
|||
1111333344444445555678041513450199023000000000000000000000000000807544433 |
|||
1112344444445555556771179000000000410000000000000000000000000000036544443 |
|||
1114444444566667782404400000000000000000000000000000000000000000775544443 |
|||
1119912160975272040000000000000000000000000000000000000000000219765544443 |
|||
1114444444566667792405800000000000000000000000000000000000000000075544443 |
|||
1113344444445555556773270000000000500000000000000000000000000000676544443 |
|||
1111333344444445555678045623255199020000000000000000000000000000707544433 |
|||
1111233333333444445568177777877777881500000000000000000000000009190544433 |
|||
1111123333333333333344455555555566668126000000000000000000000009865544333 |
|||
1111122333333333333333334444455555566793000100000000000000941355975443333 |
|||
1111112223333333333333333334444444455588908889016000003099876670654433333 |
|||
1111111222233333333333333333334444444445556667800000002976555554443333333 |
|||
1111111112222333333333333333333333444444444555679060608655544444333333222 |
|||
1111111111222222333333333333333333333444444445556702049544444433333222222 |
|||
1111111111112222222233333333333333333333344444456205554444333333222222222 |
|||
1111111111111222222222222333333333333333333333333333333333222222222222222 |
|||
</pre> |
|||
---- |
|||
=Primes= |
=Primes= |
||
==Python== |
==Python== |
Revision as of 05:25, 3 January 2019
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...
Mandelbrot Set
Primes
Python
<lang python>L = {} n = 2
while 1:
if n in L: P = L[n] del L[n] # optional - just 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>
- Output:
2 3 5 7 11 13 17 19 23 29
...the program has to be terminated by the user e.g. by typing ctrl-c.
My Favorite Languages | |
Language | Proficiency |
AWK | --- |
C | --- |
Dc | --- |