User:Yeti: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎Bourne Again SHell: mandelbrot example: less plutimications, more bashisms)
Line 60: Line 60:
1111111111112222222233333333333333333333344444456205554444333333222222222
1111111111112222222233333333333333333333344444456205554444333333222222222
1111111111111222222222222333333333333333333333333333333333222222222222222
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>
</pre>



Revision as of 05:19, 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

Bourne Again SHell

Works with: BASH version 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>

Output:
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

Primes

Python

Works with: Python version 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>
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 ---