User:Yeti: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎Bourne Again SHell: updated mandelbrot example to use less multiplications and more bashisms)
(Blanked the page)
 
(24 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...

----

=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)/23))
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
1111111111122222222233333333333333333333344444456296554444333333222222222
1111111111222222333333333333333333333444444445556805008644444433333322222
1111111122222333333333333333333334444444445555671070308755544444333333322
1111111222333333333333333333334444444445566667807000006976655554443333333
1111112233333333333333333334444444555620129900125000054200077779954433333
1111122333333333333333344445555555666793000000000000000000005009875443333
1111123333333333333445555555555666670403000000000000000000000061876544333
1111233333344444455569288780387778893200000000000000000000000000049544433
1111334444444455555678939080080941140000000000000000000000000000007544443
1113444444455555678891900000000000900000000000000000000000000000686544443
1114556677776777003000000000000000000000000000000000000000000005765544443
1114556678776788003700000000000000000000000000000000000000000003765544443
1113444444455555679991000000000000000000000000000000000000000000086544443
1111334444444455555678930000000941140000000000000000000000000000707544443
1111233333344444455569288781387778806400000000000000000000000000049544433
1111123333333333334445555555555666676661000000000000000000000061876544333
1111122333333333333333344445555555666793000000000000000000015007275443333
1111112233333333333333333334444444555620129908136000034201087779954433333
1111111222333333333333333333334444444445566667808000005976655554443333333
1111111122222333333333333333333334444444445555681070008755544444333333322
1111111111222222333333333333333333333444444445556896008644444433333322222
1111111111122222222233333333333333333333344444456096554444333333222222222
1111111111111222222222222333333333333333333333333333333333222222222222222
</pre>

----

==Spin==
{{works with|BSTC}}
{{works with|FastSpin}}
{{works with|OpenSpin}}
Famous last words: It should work with all Spin compilers for P8X32A... ;-)
<lang spin>con
_clkmode = xtal1+pll16x
_clkfreq = 80_000_000

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=25

obj
ser : "FullDuplexSerial"

pub main | c,cx,cy,dx,dy,x,y,x2,y2,iter

ser.start(31, 30, 0, 115200)

dx:=(xmax-xmin)/79
dy:=(ymax-ymin)/24

cy:=ymin
repeat while cy=<ymax
cx:=xmin
repeat while cx=<xmax
x:=0
y:=0
x2:=0
y2:=0
iter:=0
repeat while iter=<maxiter and x2+y2=<16384
y:=((x*y)~>11)+cy
x:=x2-y2+cx
iter+=1
x2:=(x*x)~>12
y2:=(y*y)~>12
cx+=dx
ser.tx(iter+32)
cy+=dy
ser.str(string(13,10))

waitcnt(_clkfreq+cnt)
ser.stop</lang>

{{out}}
<pre>
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'+)%%%$$$$$#####"""""""""""
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(+,)++&%$$$$$$######""""""
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*5:/+('&%%$$$$$$#######"""
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),:::::::,'&%%%%%$$$$########
!!!!!!!"""####################$$$$$$$$%%%&'())((())*,::::::/+))('&&&&)'%$$######
!!!!!!""###################$$$$$%%%%%%&&&'+.:::/::::::::::::::::/++:..93%%$#####
!!!!!"################$$$%%%%%%%%%%&&&&'),+2:::::::::::::::::::::::::1(&&%$$####
!!!!"##########$$$$$%%&(-(''''''''''''(*,5::::::::::::::::::::::::::::+)-&%$$###
!!!!####$$$$$$$$%%%%%&'(*-:1.+.:-4+))**:::::::::::::::::::::::::::::::4-(&%$$$##
!!!!#$$$$$$$$$%%%%%%'''++.6:::::::::8/0::::::::::::::::::::::::::::::::3(%%$$$$#
!!!#$$$$$$$%&&&&''()/-5.5::::::::::::::::::::::::::::::::::::::::::::::'&%%$$$$#
!!!(**+/+:523/80/46::::::::::::::::::::::::::::::::::::::::::::::::4+)'&&%%$$$$#
!!!#$$$$$$$%&&&&''().-2.:::::::::::::::::::::::::::::::::::::::::::::::'&%%$$$$#
!!!!#$$$$$$$$$%%%%%&'''/,.7::::::::::/0::::::::::::::::::::::::::::::::0'%%$$$$#
!!!!####$$$$$$$$%%%%%&'(*-:2.,/:-5+))**:::::::::::::::::::::::::::::::4+(&%$$$##
!!!!"##########$$$$$%%&(-(''''(''''''((*,4:::::::::::::::::::::::::::4+).&%$$###
!!!!!"################$$$%%%%%%%%%%&&&&'):,4:::::::::::::::::::::::::/('&%%$####
!!!!!!""##################$$$$$$%%%%%%&&&'*.:::0::::::::::::::::1,,://9)%%$#####
!!!!!!!"""####################$$$$$$$$%%%&(())((()**-::::::/+)))'&&&')'%$$######
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''(,:::::::+'&&%%%%%$$$########
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*7:0+('&%%%$$$$$#######"""
!!!!!!!!!!!"""""""######################$$$$$$$$$%%%&&(+-).*&%$$$$$$######""""""
!!!!!!!!!!!!!"""""""""#######################$$$$$$%%'3(%%%$$$$$######""""""""""
!!!!!!!!!!!!!!!""""""""""""#####################################""""""""""""""""
</pre>

----

=Primes=
==Python==
{{works with|Python|2.x}}
<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>

{{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|}}
{{mylangend}}

Latest revision as of 09:25, 7 June 2021