Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

ExP NO:

- PuzzLE PROBUEM
CUA BES)

AiM
To rite a Python prog 1am to implemank

Breadth Jiat search.


-Panle problem ung
*Algorm Paeudloczde
Problem.Ihed-State
ouctu Brea oljh-Fiist- tluté
=

a tu- tost
d

Hhan rctan
olitun: (rode)
PrvbleM, GtOAL-TEST (mode.STATE)
FIFo /ueu with
wode f h e ony element
ontter<a
eplored*an empty Bet
oop do return ure
Emr7y ? (Jronter) Hhen
6
mode Pop Chonter)
add mode. state xplared
o
poblem. Ac haio ode. STATE)do
r ch aeton n
Cld-CHILD- NoDE Cprsblew,
mde, aCta)

oill 8ATE in plored t) fontr hem


nt
TegE-Leiol.STATE)
Pha uturn
Prolem 1OAL- COLUToN cld)

rovter s e t Cehil n e
*Sample Tnpat7 Output

date

TITAL SsTAE L12, o3, 4, 5 6 , , ]


G10AL &TATE FOUND ) Lo,2,3, 4,5, 47,
O 2

5
6 7

Total umber ove Naleol 2

dfep-wse Se uncCe glates hrevn Clart ho

2 O
3HS
618

O2
3 45
678

012

67 8 goal
Proc edure

Sates
lotaher t a e
A. state dtotpleon fuien the
y he zht l e and he

bla in hu he wne quares


Tn4al iate: Any ate tau be dukadd
a e nihal fod.Nlote that any i e
oaltau be athed Jren trasHhy hal
he pess1BEmhl sati.

Achens he kmplest orlaturn depin tte

a moyennunts e he blauk epnte


1 atou

ohere
dependig
hoss arc pbe
the ank ë .

Criwen slate and actu,


Trastto model a

s turmie dete
seulhia a pt. 7
tue
t 4tate the
has the
SCno
the lau
Cnd he blauk
ltitate

htothuon
Hhe . Alate
wethun
noal tut- Th thetke
tatyuratmi

mothes h e geal
(oit
ath
.fath: ath stepe ost1, ein hte
e peth;
uwbe4 4tep
the
Resls t ktat
the Pytihonf r a
TAus éfs nettuted
etu rd,
-Punyyle problem i e
8- Pagle Prblen

Sampe /o
8
Enter norom
Evdes roo rom Enter te mbnyt
te tthe numbor :
nte He 2 Mber
huwber 8 nter the 3mb:2
nte Hhe
2

e r the
humber: 2
enley the umben 0
: 0
*umbr
Futer tht ken : 4
ter te
nwmbe : y nfe tue 6uwwb3
5
nter the
ummbu: 3 Bn ter t e hube7
hder me
he number +
the hu !
buter enter
6
ter he & nwbe (Eu ter te wwbe
Dsiabmter e humbu S
unlue
h e Purle sovable
The PuYJe u
Reptada h on
enurateol pota elk uun3 )
Explohy Nd
Move :one2

fe,ult:
Hab'feu6 3

Aodeuwbu:D

Move r a t

Peault

elie
elueliea
hode umb 3
3 gtcha
7L 6
Move P

Resulk
de wwbn 1
WATER JUUI PRoBLE M

AIM
To wrte Pathow pngrdu fo mplemant
Acareh.
iut
Water- dug toblem iing epta

AlDtl Pmudlode

2pty i t
Stack dutflows
as ept iFo

For qnt (node, tlouw)


n fnpuls:
Dehinesdp
Add: Node to P *low
Mradu
b e Minslouo-
TkT (ncde, louo, P mn Flo«)
-
Dekone

tohule s has eleuanb


Pat, nunfloua)
Pop TukU> (node, Jouo,
nede has cildrem
ho
(Ncde, 8low)
Detme: Outpot o
Add uttlow

nadeCohilol, e d )
For Cld u
Pefine uldjlouo- uegtHoo
mn tlow and culd, nottn pata:
dtd louw >=

Add eld to pat


chuld, cildjlou, Pata, winloo)
o
Add: Tadkl
Add: TokC euld):

duflocoa byurde
Colleet Sn outpa Chole, loco) t
Saple Inpuoulput
Iput 6, 6,
Staoting wore

Pseing
Co e,4)
Cs, o,
Ce,A
3,8, 1
C1, O,)
Cn,i,o)
C6,
C6,4,
Sample 7/0:-

olulurn gor wat j bem


tr Capehy s
Cagcl 3
re, r Volume 3
PPT Foumd
Co, Co, 43, [S,4]3)
Po ceodure
a -qallou taud auol
G1íve a puP,
maY ken,
with no meauriug
a 3-9allon tanle
taxk wth naetly dgellers.
aelly galory
the -alovw
1l
wate
water

.(2,)>(a-3-3), 9
t)23
and 2>
into the
water roun the hgalle
jag
Pour i
iau
i l the
3
gallrm jug
-gallenjg

(a1)4 4 and >o


ink
Pou all he boater rem 3- allo ug
ne -3allow 1

C7y) (o,2r})

Pour Qll the watesrom the A-9ellon

u t the 3 allou )

lo,2)> (2,)
Pour e gallons hrom te 3-7allon
tie -9allor lg
a in
C2,2) (o,2)
e 40und
mply tueA- 9allonjug

Reut Thus the Pmthuo Pmgram to inpleuuewt

water g problen V Derth Jiat


Aplemeutod md sutput
up
Mach
obtauned
CxnO3

TMPLEMENTATIONl OF
A ALORITH.

AM
To ne the hortest Patt vng A
goton í Kython
ALORITHM: Node
lontamung onhy tae startirg
onake an 0penlst
empty
Closcd duot
make
ode hoa not b e
am
dytnaluo»
owle (he ea nnd )
the owest
owesl
the ooll
Connelen s6
Store tn the pen
node u our dotuauoin, node)
Cthus
we are
tnusked

ot node a
the clased
the elose
current n eh jhkour guoour
Put heand all
a ll 'u
leok a t
t
umt ode)
hukborthe
gorCah loven 2
valut thon
than
neghbor han elosed t
closed ut));
:
n e
awe
Currat hew,
utAe
t h i hughbor
eplace Current node
vaul
oue
ouwe,
ow
eh bor's
h e ntughbas paron paremt

rrent value
As owe ang
2lse
us the Open Jot ):
h neahbou
he'ghbor
oifh then e ,
#he
plate ower vaue

Agbors paromt
ho our

change the
Gaurront nod

tus muhbor hot h bott lob:


lse st
o am
t a no
s
do the
open
adol l
t
rocedure '

Pekine a t optn ntall, CFN uu


ode, h e ata,b hode s.
alely a
ingha
wtemply, uturrouure amd e i t .
d. he 4mallst valus
nw th he
node n
.Reuove move t o tee
OPEN md
C n ) trem a pal slde,
clomd. ode n
t
tun uccem e

.Epand mode n oal heole,


ueole,
MllWor to n us toal the
5. aty Aoluton
oluiov
b teu
the
amoA
ueten
Aturn ndl do S
do S oftinwise
Otuinw ise
oa
he
the pah Zrom
Pavh

to step-06
netir S to the node
evalualon
the st
6 Arr'y not been n u
node hao
he
adol fo DPEM

b Stp-02.
7Unobark

Reult Thusthe yhon PTOgram


do implemt
inmple wnteol am
A Algorith
he
0utpat ob4ahed
LNO:4

AO ALCORITHM

AIM
To impletut Ao alejorhm Python to 3d
un amol vised oxt

ALLoRITHM
to alartnode
Ttialise theJraph
the Curremt
Jollowing
Travese 4ie grapk hal
tha have
haue
modu
P at
Pat actumulat ng olved
expamclol
4olved
bun
quot 4et
naok amol expamol it
3 Pck auyfhere ctestors ealu ths
has n o
amo

FuLILITY othnwae lulate nly f'z«


valu
LAen ot the ucleAora

mark
the
the node
a
a SoL VED.
SoLVED.

o theu
o

f or ha neuoy
5 chauge valu
the
BuCteso
Ceateol nod to leet
back pAgakn
mort promu'ainy
Wheavon poetble Vse the marked as
a s
node
outes no mack the parent node as
node a i
thtm
SoLven

SoLvED
Value greater
gr eater
node oLVED lo) Value
7 sdadin ebe peat shp.
FULILITY, 4op,
ham
RoUE DURE
Cost Functuon FCn) - u(n) 4 H (n).

2 Plate hke Harting node ínto OPEN

3 Compute the wst promig Aouboin ree


sa TO
oole thot A both on OPE and
A Seleut a n

Remove it om OPE Cmd


a member TO
plate t In

5: close
nade thn lueleo
6 n ai the feminal gaal
naw sdved amal levelec all the antes hor
sfarttug mode marke
au olved . the
and 'erit
olveol h e n
Auetes
as
mark n
mot a kolvable mocle, hen
n ub node us marked ay
as unodvable. 4 t4rhig
amo t
amd eet
then Aturn 9oilure
unolva ble,
all i
sutestore
amd nd
Expowmonind
8 them into BFe.
value, push
+heir hCn)

&tep2
9 Rehun
X No5,

SIIGHLE 1LNER UIAME

AIM
"implemmt 6ngle playen Anake hame usfng
tteunush umtluon n Python
* AL1ORITHM

Start
Create a
game
piholouw ne 720 1eo
2 4nake to (loo, ) pixe l
pasttu of
3- Sek inital
'n the awndow
Co-ordinalien

A.ohlesnake nadt deod t nput jrom

t
nake
direeiov altordung
6 ehamgg -the
VA input

gotSnake suut iner.enoe


e by ome.

6
Repea p 4
8 Shop.
RoCEDURE

Uhrare
Firsy we are impordfng nee may
te
to itHaliye
Ubrar'es 1oe teol
impovtng
metud.
P19ame inst C)
geme

anahe poviho Omd u ie.


Tnikialine
Create a umcio t auplay the sore
the AtorG
S
he
Plag feat wrll
Ove uncti
A No Create a game
the Mtore
ate Chake s ht h
reprent
a wall G) tse-
l be
albe
hat a
ralidatrng
the keys
we will be
the Ahake,
movemmd
Asponn'ble jor tue
wl be creatihg aspe uel
londtem
hen
then e
be allow e ed
nake shoad ot
that he
to move n he Ppostte diretuo inofamtaneous
wll
i t otu'de
we

6 Atee that, A snake amo


ne
utt
increamunina
he ktore
b n
be
panneel
oilbe

we are
the shake
Shake
thetkrng that u dhake
Alter ha, wall eo t
a htta
th a
w
w l e a l lqame overumcuar.
wal we

the nake h telh,the 9ame vve

unuan illhe lalled.


wo PlAvER AME :

AIM
Tre Ta Toe
To ímplemeut he fwo pla
Gome
N Virg Heihe Juntuo n Python
ALGTORITHM:-
is
Mrnmarnade, derth, marimiirg player )
deph onode aHermínal node then
=o

Modle
turn Stortfe evaluatuo

Marmiyingflayen
themartva - in t t
do
or each childl Rodle
eya miwmax (child, depth- I, falbe )
Max eva > mar Cmax Eva, eva)
u r n Maxeva

dse
neva+ intn
Mode do
eack cild
o true)
va
min'ma Ciilad, deyth-1,
munva min Cminta eva)
nturn muintva.
rodeolure:
the lom mand
We wtll be plasying Te-Hae-oe n
tWe
e kave to dlo
ne, thefore, -the Ziat tting
koe
s Create a dewg for otur He dae-
Cruual
inssamt tfme, Ve heeol two
At amy

nor maden
hawe a odada
the grid -

ne mut
8taktus o slate, thet ,
tach tells
strutture hat tore

whetin t ocCupjeol G) Vacamt


bomehos hawe fhe
A.taek playeis move e
and pra
Caeh playud past
knouoledge am
move, tat ú , the posiBos decupieol b
D' whieh
has eme kinol ame opP,
5 tver ame, or the ame emda
bKIT sonne playu p í n
nun teratign
t e - fac- oe
each oop
In ,

fna drauo playu makea


Move

Ae to a
kng
mwot tnput
tnpu
ierdtuoin a playen must
6 ver
n every me
w move

payt npuk,
we neeol do uplt a

Acuordi t the playu m u t hane


uust hawe
dea, that caek playu
qevnous
o teh Ma rk
mark
choosa
o
opporunily
6wap the valus n Cur-playe date
o dp4o
dp4o, we
he Smootth wnetin
e nformati 9or
fhe gome

we hawe to check wheth


81Afen eaeh move,
ha
the a m e hau
game
won fthe gama
omy pla wom
wfnu, then the
beon
beo drauon amy playo uT
u r rre
en t
Atturs h e
C) nctuo
irgle- game
he ove. In Case,
the Ja
the me
7ame
Lho made
plaup,
playe,
0
D
back
semt back
drawn,

ome at a me,
Since .each plaeye 0nly mov
1 we
we
tack Aucceul uov
theu hore ofter
hawe do swap the
urrent
pay
The tntornuatuin hke the Qurrent playo the
ktojeboard nteol
amd he
ckpiee e Playeos
the Carremt playon u
h Aorec By defeult,
he
enteud
nane frat
rat
the playerwho
pop or Mamaqina
we need
amothe 9ame
. eauh modch
madches t e - t a c - doe
ultple mark
a r k x'or
('x'or 'o')
ehooses his
he Current play
must be dwplayeol
The menu or choosng
ame
terafo
in eyery
the doda ka
douda ben
haz been
the players luotte,
|Aceordira
aAceordirg
Ta mpos tonot Ante after taeh
Sroren
tore ull ells shich plagu
game inishen,
13 Aler4brig
Aler all he mecesmasy 'normalio, if
Madeh Omd
independlsmt
tfme to eeeoute am

&fore te onning mask

fdeas, 4hot ach playen muut


t a qeneuous wwuith ma rh
mark
ehoase
one tue portunily to fhe
Swap fhe value
vaue
&war
To cdo , we
4hey womt
Tey
in dx plap

You might also like