User:Yeti: Difference between revisions
m (removing header templates that make this page appear among task categories) |
(→Spin: mandelbrot example updated to variant with 2 multiplications less per loop) |
||
Line 89: | Line 89: | ||
ser : "FullDuplexSerial" |
ser : "FullDuplexSerial" |
||
pub main | c,cx,cy,dx,dy,x,y, |
pub main | c,cx,cy,dx,dy,x,y,x2,y2,iter |
||
ser.start(31, 30, 0, 115200) |
ser.start(31, 30, 0, 115200) |
||
Line 102: | Line 102: | ||
x:=0 |
x:=0 |
||
y:=0 |
y:=0 |
||
x2:=0 |
|||
⚫ | |||
iter:=0 |
iter:=0 |
||
repeat while iter=<maxiter and |
repeat while iter=<maxiter and x2+y2=<16384 |
||
y:=((x*y)~>11)+cy |
|||
x:=x2-y2+cx |
|||
⚫ | |||
⚫ | |||
⚫ | |||
iter+=1 |
iter+=1 |
||
⚫ | |||
⚫ | |||
cx+=dx |
cx+=dx |
||
ser.tx(iter+32) |
ser.tx(iter+32) |
||
cy+=dy |
cy+=dy |
||
ser. |
ser.str(string(13,10)) |
||
waitcnt(_clkfreq+cnt) |
waitcnt(_clkfreq+cnt) |
||
Line 124: | Line 124: | ||
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'+)%%%$$$$$#####""""""""""" |
!!!!!!!!!!!!!"""""""""#######################$$$$$$$%'+)%%%$$$$$#####""""""""""" |
||
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(+,)++&%$$$$$$######"""""" |
!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(+,)++&%$$$$$$######"""""" |
||
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')* |
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*5:/+('&%%$$$$$$#######""" |
||
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),:::::::,'&%%%%%$$$$######## |
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),:::::::,'&%%%%%$$$$######## |
||
!!!!!!!"""####################$$$$$$$$%%%&'())((())*,::::::/+))('&&&&)'%$$###### |
!!!!!!!"""####################$$$$$$$$%%%&'())((())*,::::::/+))('&&&&)'%$$###### |
||
!!!!!!""###################$$$$$%%%%%%&&&'+.:::/::::::::::::::::/++:.. |
!!!!!!""###################$$$$$%%%%%%&&&'+.:::/::::::::::::::::/++:..93%%$##### |
||
!!!!!"################$$$%%%%%%%%%%&&&&'),+ |
!!!!!"################$$$%%%%%%%%%%&&&&'),+2:::::::::::::::::::::::::1(&&%$$#### |
||
!!!!"##########$$$$$%%&(-(''''''''''''(*,5::::::::::::::::::::::::::::+)-&%$$### |
!!!!"##########$$$$$%%&(-(''''''''''''(*,5::::::::::::::::::::::::::::+)-&%$$### |
||
!!!!####$$$$$$$$%%%%%&'(*-:1.+.:-4+))**:::::::::::::::::::::::::::::::4-(&%$$$## |
!!!!####$$$$$$$$%%%%%&'(*-:1.+.:-4+))**:::::::::::::::::::::::::::::::4-(&%$$$## |
||
!!!!#$$$$$$$$$%%%%%%'''++.6:::::::::8/0::::::::::::::::::::::::::::::::3(%%$$$$# |
!!!!#$$$$$$$$$%%%%%%'''++.6:::::::::8/0::::::::::::::::::::::::::::::::3(%%$$$$# |
||
!!!#$$$$$$$%&&&&''()/- |
!!!#$$$$$$$%&&&&''()/-5.5::::::::::::::::::::::::::::::::::::::::::::::'&%%$$$$# |
||
!!!(**+/+:523/ |
!!!(**+/+:523/80/46::::::::::::::::::::::::::::::::::::::::::::::::4+)'&&%%$$$$# |
||
!!!#$$$$$$$%&&&&''().-2.:::::::::::::::::::::::::::::::::::::::::::::::'&%%$$$$# |
!!!#$$$$$$$%&&&&''().-2.:::::::::::::::::::::::::::::::::::::::::::::::'&%%$$$$# |
||
!!!!#$$$$$$$$$%%%%%&'''/,.7::::::::::/0::::::::::::::::::::::::::::::::0'%%$$$$# |
!!!!#$$$$$$$$$%%%%%&'''/,.7::::::::::/0::::::::::::::::::::::::::::::::0'%%$$$$# |
||
!!!!####$$$$$$$$%%%%%&'(*-:2.,/:-5+))**:::::::::::::::::::::::::::::::4+(&%$$$## |
!!!!####$$$$$$$$%%%%%&'(*-:2.,/:-5+))**:::::::::::::::::::::::::::::::4+(&%$$$## |
||
!!!!"##########$$$$$%%&( |
!!!!"##########$$$$$%%&(-(''''(''''''((*,4:::::::::::::::::::::::::::4+).&%$$### |
||
!!!!!"################$$$%%%%%%%%%%&&&&'):,4:::::::::::::::::::::::::/('&%%$#### |
!!!!!"################$$$%%%%%%%%%%&&&&'):,4:::::::::::::::::::::::::/('&%%$#### |
||
!!!!!!""##################$$$$$$%%%%%%&&&'*.:::0::::::::::::::::1,,:// |
!!!!!!""##################$$$$$$%%%%%%&&&'*.:::0::::::::::::::::1,,://9)%%$##### |
||
!!!!!!!"""####################$$$$$$$$%%%&(())((()**-::::::/+)))'&&&')'%$$###### |
!!!!!!!"""####################$$$$$$$$%%%&(())((()**-::::::/+)))'&&&')'%$$###### |
||
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''(,:::::::+'&&%%%%%$$$######## |
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''(,:::::::+'&&%%%%%$$$######## |
||
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*7:0+('&%%%$$$$$#######""" |
!!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*7:0+('&%%%$$$$$#######""" |
||
!!!!!!!!!!!"""""""######################$$$$$$$$$%%%&&(+-).*&%$$$$$$######"""""" |
!!!!!!!!!!!"""""""######################$$$$$$$$$%%%&&(+-).*&%$$$$$$######"""""" |
||
!!!!!!!!!!!!!"""""""""#######################$$$$$$%%' |
!!!!!!!!!!!!!"""""""""#######################$$$$$$%%'3(%%%$$$$$######"""""""""" |
||
!!!!!!!!!!!!!!!""""""""""""#####################################"""""""""""""""" |
!!!!!!!!!!!!!!!""""""""""""#####################################"""""""""""""""" |
||
</pre> |
</pre> |
Revision as of 05:34, 1 December 2018
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
<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)) ((rsq=0)) for((iter=0;iter<maxiter && rsq<=16384;iter++)) ; do ((xn=((x*x-y*y)>>12)+cx)) ((yn=((x*y)>>11)+cy)) ((x=xn)) ((y=yn)) ((rsq=(x*x+y*y)>>12)) done ((c=iter%lC)) echo -n ${C:$c:1} done echo done</lang>
- Output:
1111111111111222222222222333333333333333333333333333333333222222222222222 1111111111122222222233333333333333333333344444456296554444333333222222222 1111111111222222333333333333333333333444444445556805008644444433333322222 1111111122222333333333333333333334444444445555671070508755544444333333322 1111111222333333333333333333334444444445566667807000006976655554443333333 1111112233333333333333333334444444555630129900135000064200077779954433333 1111122333333333333333344445555555666793000000000000000000005009075443333 1111123333333333333445555555555666670303000000000000000000000061876544333 1111233333344444455569288780387778893200000000000000000000000000049544433 1111334444444455555678938080080941140000000000000000000000000000007544443 1113444444455555678891900000000000900000000000000000000000000000696544443 1114556677776777003000000000000000000000000000000000000000000004765544443 1114556678776788003800000000000000000000000000000000000000000003765544443 1113444444455555679991100000000000000000000000000000000000000000086544443 1111334444444455555678930000000941140000000000000000000000000000707544443 1111233333344444455569288781387778806400000000000000000000000000049544433 1111123333333333334445555555555666673661000000000000000000000061876544333 1111122333333333333333344445555555666793000000000000000000015007275443333 1111112233333333333333333334444444555620129909136000034201087779954433333 1111111222333333333333333333334444444445566667808000005976655554443333333 1111111122222333333333333333333334444444445555682070008755544444333333322 1111111111222222333333333333333333333444444445556895008644444433333322222 1111111111122222222233333333333333333333344444456096554444333333222222222 1111111111111222222222222333333333333333333333333333333333222222222222222
Spin
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>
- Output:
!!!!!!!!!!!!!!!"""""""""""""####################################"""""""""""""""" !!!!!!!!!!!!!"""""""""#######################$$$$$$$%'+)%%%$$$$$#####""""""""""" !!!!!!!!!!!"""""""#######################$$$$$$$$%%%&&(+,)++&%$$$$$$######"""""" !!!!!!!!!"""""#######################$$$$$$$$$$%%%%&')*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(%%%$$$$$######"""""""""" !!!!!!!!!!!!!!!""""""""""""#####################################""""""""""""""""
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 | --- |