Showing posts with label Mental Maths. Show all posts
Showing posts with label Mental Maths. Show all posts

Saturday, October 20, 2012

Krypto - make the target number


# This program uses the new functions and subroutines from version 0.9.9.1










cls
clg
dim n(4)
dim op$(4)
target = int (rand*60)
n[0]=int (rand*10)+1
n[1]=int (rand*10)+1
n[2]=int (rand*10)+1
n[3]=int (rand*10)+1
graphsize 600,200
font "arial",40,100
text 0,20, "Target number is : "+ target
text 0,100, "Use only: "+ n[0]+", "+n[1]+", "+n[2]+", "+n[3]
counter=0
op$[0]="+"
op$[1]="-"
op$[2]="*"
op$[3]="/"
for turn = 1 to 2
For t1 = 0 to 3
For t2 = 0 to 3
For t3 = 0 to 3
For t4 = 0 to 3
For t5 = 0 to 3
For t6 = 0 to 3
For t7 = 0 to 3
if t1<>t3 and t3<>t5 and t5<>t7 and t1<>t5 and t3<>t7 and t1<>t7 then
a=eval(op$[t2],n[t1],n[t3])
c=eval(op$[t6],n[t5],n[t7])
ac=eval(op$[t4],a,c)
if ac = target and turn =2 then Print "("+ n[t1]+op$[t2]+n[t3]+")"+op$[t4]+"("+ n[t5]+op$[t6]+n[t7]+")="+ac
if ac = target and turn =1 then counter = counter +1
b=eval(op$[t4],n[t3],n[t5])
ba=eval(op$[t2],n[t1],b)
bac=eval(op$[t6],ba,n[t7])
if bac= target and turn =2 then Print "(("+ n[t1]+op$[t2]+"("+n[t3]+op$[t4]+n[t5]+"))"+op$[t6]+n[t7]+"="+bac
if bac = target and turn =1 then counter = counter +1
bc=eval(op$[t6],b,n[t7])
bca=eval(op$[t2],n[t1],bc)
if bca= target and turn =2 then Print n[t1]+op$[t2]+"(("+n[t3]+op$[t4]+n[t5]+")"+op$[t6]+n[t7]+")="+bca
if bca = target and turn =1 then counter = counter +1
ab=eval(op$[t4],a,n[t5])
abc=eval(op$[t6],ab,n[t7])
if abc= target and turn =2 then Print "(("+ n[t1]+op$[t2]+n[t3]+")"+op$[t4]+n[t5]+")"+op$[t6]+n[t7]+"="+abc
if abc = target and turn =1 then counter = counter +1
cb=eval(op$[t4],n[t3],c)
cba=eval(op$[t2],n[t1],cb)
if cba = target and turn =2 then Print n[t1]+op$[t2]+"("+n[t3]+op$[t4]+"("+n[t5]+op$[t6]+n[t7]+"))="+cba
if cba = target and turn =1 then counter = counter +1
end if
next t7
next t6
next t5
next t4
next t3
next t2
next t1
print "Number of solutions "+counter
input "press any key to get solutions",a
next turn
function eval(e$,x,y)
if e$="*" then eval = x*y
if e$="/" and y<>0 then eval = x/y
if e$="/" and y=0 then eval = 10000000
if e$="-" then eval = x-y
if e$="+" then eval = x+y
end function

Thursday, December 30, 2010

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 5, 2010

What is the angle?

dim arrow(8)
arrow = {0,0,0,0,0,70,0,0}
r=int(rand*2*pi)+.1
clg
fastgraphics
for i = 0 to r step .005
stamp 150,150,2,i,arrow
refresh
next i
input "What is the angle?",r$
print r*180/pi

Hidden dots - Sample , Averages,

clg
a=int(rand*1000)
for n = 1 to a
color rand*150,rand*150,rand*150
circle int(rand*300),int(rand*300),2
next n
pause 1
color red
for x = 0 to 9 : for y = 0 to 9
if int(rand*10)<>5 then rect x*30,y*30,30,30
next y : next x
input "How many dots are there?",r$
print a

Monday, October 4, 2010

Estimate the area

clg
color yellow
rect 0,0,300,300
color red
rect 0,0,20,20
h=int(rand*5)+1: l=int(rand*5)+1
rect 40,40,40+20*l,40+20*h
input "The small square is 1 cm^2 what is the area of the rectangle?",q$
color yellow : rect 40,40,40+20*l,40+20*h
color red
a=0
for s = 0 to h+1 : for n = 0 to l+1
  rect 40+20*n,40+20*s,19,19
  a=a+1
  print a
next n : next s

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