Showing posts with label Tiny weeny programs. Show all posts
Showing posts with label Tiny weeny programs. Show all posts

Tuesday, September 17, 2013

PASCAL TRIANGLE

# I got this one from the BBC basic in Rosetta Code site
font "arial",10,100
graphsize 700,350
nrows = 16
FOR row = 1 TO nrows
acc = 1
FOR element = 1 TO row
text element*40+350-row*20,row*20, acc+" "
acc = acc * (row - element) / element
NEXT element
PRINT
NEXT row

Wednesday, November 28, 2012

Doppler efect

#Doppler efect
fastgraphics
x=0
loop:
for b = 1 to 10
color white
rect 0,0,300,300
x=x+1
a=.5
for n = 1 to 255 step 5
a=a*-1+.5
color rgb(255-a*n,255-a*n,255-a*n)
circle x + (n-b)*.5-255,150,255-(n-b)
next n
refresh
clg
next b
goto loop

Friday, June 29, 2012

Collatz conjecture


Rem  http://en.wikipedia.org/wiki/Collatz_conjecture#Methods_of_proof
graphsize 1000,400
for x = 1 to 1000
a=x
n=0
do
b=a
if a/2 = int(a/2) then
a = a/2
else
a=a*3+1
end if
n=n+8
line n-8,400-b/30,n,400-a/30
until a = 1
print "Initial number "+x+ " Iterations "+n/8
next x

Wednesday, June 6, 2012

Cellular Automation


# This program was malfunctioning for a long time because I did not update the code to the New Basic 256 . It is very interesting to see how 2 very simple rules generate two very different patterns . One is a fractal and the other is chaotic
# You can change the rule by activating or deactivating the plotting instruction . See also http://mathworld.wolfram.com/ElementaryCellularAutomaton.html


fastgraphics
graphsize 800,400
For n = 1 to 2
plot (400,1)
For y = 1 to 400
For x = 1 to 800
a=0
if pixel(x-1,y)=black then a=a+1
if pixel(x,y)=black then a=a+10
if pixel(x+1,y)=black then a=a+100
if n=1 then gosub chaotic
if n=2 then gosub fractal
next x
refresh
next y
pause 1
clg
refresh
next n
chaotic:
if a=001 or a=110 or a =010 or a=100 then plot (x,y+1)
return
fractal:
if a=001 or a=010 or a=100 then plot (x,y+1)
return

Tuesday, September 27, 2011

Static Wave


Rem the purple wave is made out of two simple sinusoidal waves. Change the frequencies and amplitudes and see what happens .
fastgraphics
Amplitude1=30
Frequency1=2
Amplitude2=30
Frequency2=8
for t = 1 to 1000 step .1
clg
for n = 1 to 31.4 step 0.1
r=Amplitude1*sin(t )*Sin(n/(10/Frequency1))
b=Amplitude2*sin(t )*Sin(n/(10/Frequency2))
p= r+b
color red
circle 10*n,r+250,3
color blue
circle 10*n,b+200,3
color purple
circle 10*n,p+100,3
next n
refresh
next t

Tuesday, July 12, 2011

Complex wave


Rem the purple wave is made out of two simple sinosoidal waves
fastgraphics
for t = 1 to 1000 step 0.1
clg
for n = 1 to 30  step 0.1
r=30*sin(t+n*0.2)
b=10*sin(t+n*0.8)
p= r+b
color red
circle 10*n,r+250,3
color blue
circle 10*n,b+200,3
color purple
circle 10*n,p+100,3
next n
refresh
next t

Tuesday, January 25, 2011

Character frequency

dim a(123)
for n = 97 to 122
a[n]= count("The frequency of letters in text has often been studied for use in cryptography, and frequency analysis in particular. No exact letter frequency distribution underlies a given language, since all writers write slightly differently. Linotype machines sorted the letters' frequencies as etaoin shrdlu cmfwyp vbgkqj xz based on the experience and custom of manual compositors. Likewise, Modern International Morse code encodes the most frequent letters with the shortest symbols; arranging the Morse alphabet into groups of letters that require equal amounts of time to transmit, and then sorting these groups in increasing order, yields e it san hurdm wgvlfbk opjxcz yq. Similar ideas are used in modern data-compression techniques such as Huffman coding.", chr(n),true)
next n
for n = 97 to 122
print chr(n)+" "+a[n]
next n

Monday, January 10, 2011

Line pattern

Graphsize 600,600
fastgraphics
clg
for pic = 1 to 30
a=122 : b=rand^2 : c=rand^2: d=rand^2
for x= 1 to 600
for y= 1 to 600
color a+a*sin(b*x),a+a*sin(c*x),a+a*sin(d*x)
plot x,y
next y
refresh
next x
next pic

Saturday, January 1, 2011

Color plots

Graphsize 600,600
fastgraphics
clg
for pic = 1 to 2
for x= 1 to 600
for y= 1 to 600
# try different formulae for color using coordenates x and y
if pic = 1 then color ((x-300)^2+(y-300)^2)*3
if pic = 2 then color 300*abs((x-300)/(y-300))
plot x,y
next y
refresh
next x
next pic

Friday, December 31, 2010

Caesar's cipher decryption

ciphr$="ňŭğŢűŸůųŮŦűŠůŧŸīğŠğłŠŤŲŠűğŢŨůŧŤűīğŠūŲŮğŪŭŮŶŭğŠŲğŠğłŠŤŲŠűĦŲğŢŨůŧŤűīğųŧŤğŲŧŨťųğŢŨůŧŤűīğłŠŤŲŠűĦŲğŢŮţŤğŮűğłŠŤŲŠűğŲŧŨťųīğŨŲğŮŭŤğŮťğųŧŤğŲŨŬůūŤŲųğŠŭţğŬŮŲųğŶŨţŤūŸğŪŭŮŶŭğŤŭŢűŸůųŨŮŭğųŤŢŧŭŨŰŴŤŲħŖŨŪŨůŤţŨŠĨ"

text$=""
shift=255
for n = 1 to length(ciphr$)
letter$= mid(ciphr$, n, 1)
m = asc(letter$)
text$=text$+chr(m-shift)
next n
print text$

Thursday, December 30, 2010

Caesar's cipher encryption

text$="In cryptography, a Caesar cipher, also known as a Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques(Wikipedia)"
shift=255
ciphr$=""
for n = 1 to length(text$)
letter$= mid(text$, n, 1)
m = asc(letter$)
ciphr$=ciphr$+chr(m+shift)
next n
print ciphr$

Sphere

clg
For n = 1 to 150
color rgb(50+n,50+n,50+n)
circle rgb(150,150,150-n)
next n

Smarties

clg
ns=int(rand*500)
For n = 1 to ns
color int(rand*2)*255,int(rand*2)*255,int(rand*2)*255
circle rand*290+5,rand*290+5,5
next n
input "How many smarties?",wait
print ns

Tuesday, October 12, 2010

HCF

a=420
b=360
c= int ((a+b)/2)
loop:
if a/c = int (a/c) and b/c = int (b/c) then
print "The highest common factor to a and b is "+ c
end
end if
c=c-1
goto loop

Sunday, October 10, 2010

Compound interest

clg
color red
value=10
f=150/value
intrest=2
for y = 1 to 40
value=value*(1+intrest/100)
print y+" "+value
rect y*5 ,300-value*f,4,value*f
next y

Friday, October 8, 2010

Abundant numbers

Rem Abundant numbers are smaller than the sum of their factors
for n = 5 to 100000
sum = 0
for factor = 1 to int(n/2)
if n/factor = int(n/factor) then sum = sum + factor
next factor
if sum > n then print n
next n

Wednesday, October 6, 2010

Pythagorian triple distribution





t=-1
clg
for c=3 to 3000
for b=2 to c-1
asquared=c^2-b^2
a=(asquared)^.5
if a=int(a)then
t=t*(-1)
if t=-1 then print a+chr(178)+"+"+b+chr(178)+"="+c+chr(178)
if a<3000 and b<3000 then plot a/10,b/10
end if
next b

next c

Monday, October 4, 2010

Nth term

a= int(rand*10)
b= int(rand*10)
for n = 1 to 4
  print a*n + b
next n
input "What is the nth term?", x$
Print a+"n+"+b

Equation ax + b = cx +d

x= int (rand*10+2)
a= int (rand*10+2)
b= int (rand*10+2)
c= int (rand*10+2)
d=a*x+b-c*x
print a+"x+"+b+"="+c+"x"+d
input "What is x",s$
print x

Guess the distance

clg
color yellow
rect 0,0,300,300
x1=rand*300
y1=rand*300
x2=rand*300
y2=rand*300
color red
circle x1,y1,4
color blue
circle x2,y2,4
Print "What is the distance between the points? "
input " " , s$
print ((x2-x1)^2 + (y2-y1)^2)^0.5