You are on page 1of 16
Practical No: 6B im s- Design an application 4o_simulede number puzzle problem fom _simpleat.search innpost astar, Seasch Problem Iprint(” Goal & Stale _{s i”) ~ paiot CGeAL) INTTIAL =“ 4-4-2 yee-3 76-6" pvt C" Initial State is >”) L print ( TNETTAL) def list to.stving (mytist)* sretura “\n”. * join (C= join (rows foe sro io_enylist ) def tiag to li + (mysbving): aelusa [rowsplit ('— for rw in myelaiing esplitC\o'] del Gad. locatfan (vows detent. to. find): fox iv, row ip enumerate (wows): j for ie, element in enumerate (20) if element = = element—to-fiad : eehusn iv, ic | FOR EDUCATIONAL USE geal_positie os = $y nows.goal = sting - to- list C@cAl) fox_number in ‘1 2345638e" goal = posites [oumte z= Rad. location Gous_ geal number) pat Cg a Class GghtPuzrle Problem (SearchPsvblenn) : def actions (self, state) mows = string -Jo- list Cstate ) we, ce = find location (wows, te’) e roy action =C J if ve>o: ctfor .ayp| Crows [ve~ij [ce] if vec@: myaction append Crows [ret] fceD — if coro: myaction - append Crows [ve} Cce-15) if ceca: my action - cig pend. (see [ve] Ccettjy) - e A achoo = def result (self, stede, achon): mows = string jo—lisk stated - xe, (e= finde location (rows. e’) am cn > Bad_ location Crows , achen) rows Ere) [ce} , wwsbrnI Len]= sows [rr eal wuwslrel ie] sceluxa_list-to ~ string (vows) FOR EDUCATIONAL USE, def is-goal Cself, state): wth state==G0A) def cost (self, state, action, stajer): retum 4 def heiivish’c (self, state) : news = String to-list (state 7 wv distance =o for number jg '1234S69R¢? + +000 = Find. Jocetfon (rows _ number ) sgeal_, cgoal = goa) positions Chun ber] distance t= abi (ro=r0c! ) tak Cen-oud Treburon distin Besult = astar CEtzhtPueale Problem CINITLAL)) punt (resale for action, state in vesult.pecth(): pyint (' prove number’ , action) prin’ Lctade) Output FOR EDUCATIONAL USE Initial state is + — ye-4-2 #-e -3 g-s-6 F'47:00,0) , (27s C0,4), 137: (0,2), QW? : (1,0), (9:41) [6 stt2) P20) 820, fe? 32,2) Node move number None 4-2-2 ¥-e-3 | @-S-6 | move number & 4-1-2 4-5-3 g-e-€ move number F 4-1-2 4-5-3 e-8-6 | Move number F y-4-2 FOR EDUCATIONAL USE, Samed ove number 2 -2-e -S-3 ~8-6 ove number -2-3 -S-e -3-6 ove Numbers -2-3 ~S-6 -8-e FOR EDUCATIONAL USE = Practical No: A Aim: wite a Pregram to shuffle deck of card import random = card-faces = CJ sults = [" Heaxts”," Diamonds” “Spades”, ‘Clubs ‘J soyalsel YS" "Q%, Mer en] decle =C J 4 Add +he content jn tne deck for _i in range (2,41); Card faces.append (ste) Hor & in wange C4): card Faces. append beoyals Ck) print Ccard faces) lov iin range C4) ¢ for jin vange (13): cord = cardfaces Cj] +!= "+ suitsCiJ cle ck append (card) pyink ("~~ original deck o cards ~~ ” for i ia range (52)! ponb(deckCi J) fom shuffle (deck) ent (“~~ Shuffled deck of cardo--”) for i in vange (52): print (deck Ci) FOR EDUCATIONAL USE #t Output Pio? Bi ty? 84619 gg! Yo eT gee? al ea Original deck of Cardo -- 2- Hearts 3 ~ Hearts 4 ~ Hecrts S= Hearts & —Heagsts ~ Hearts @ = Hearts 9 = Heaxts 10 = Hearts : I - Heasts : Q— Heaxts . K - Heasts ; ,_ |2 ~ Diamonds 7 3 - Diamonds : 4 = Diamonds z |S _~ Diamonds - 6 — Diamond - _ ~ 4 = Djamonds = : & - Diamonds 7 ~ 4_= Diarnonds * 10 = Diamonds _ ~ T_~ Diamonds : 8 = pfamords K = Djammorels ~ Diaronds FOR EDUCATIONAL USF Geass | A - diam L — 2- Spacles 3 - Spades 4 = Spades S = Spades ——l6 = soad ae Spacles ———8 = Spades 19 ~ Spades TC fo ~ Spades 3 = Spades aa Q - Spades a K ~Spades ‘— A =Spades = 2 - Clubs = 3 = Clubs ae 4 = Cubs — 5 -Clubs = 6 ~ Club —= |? - Clubs a g -Clubs q -clubs lo _—élubs T -Clubs -Clubs K -Clubs 1 A_~Clubs . ~~ Shuffled becle of Cards ~~ 5 - Diamonds 4 - Hearts FOR EDUCATIONAL USE Gandara) a 6 - Club J - Heasts 3 - Hearts [5 _- Spaces Nk - Spades [4 - clubs 2 -Spades Q- Heasts [2 - Spadet [lo -Spades 4-Spades LO -Heaxts S -Clubs 3 - Heasts A -Cubs (0 -Clubs Q- Spades _ %- Hearts £- Heawts 2 -Clubs 3- Spades 6 -Hearts 4- Digmonde 4- Clubs S - Spades A = Spacl és 3 - Diamonds 2+ Diamonds @- Spades A ~ Hearts Seas FOR EDUCATIONAL USE S -Clab gq - Hearts &- Diamonds 3 - Spades k- Clubs 1=S pad és 2- Hearts ke - Diamonds 5 - Heasts G_-Diarnonds - Diamonds Jo -Diamonds Q@ -Clubs Q- Diamonds &- Cubs - 5 = Clubs 7 - Clubs D - Diamonds 4 - Diamon 3 -_ Diamonds FOR EDUCATIONAL USE Practical No oom Aim + Solve Jravelling alesman pwblem cwwsing AT 2 5 Aechnigue from _ikertools import permutations Ve4 def ISP Cqvuph, $): — verbo = et J for ifn serge (vy): if jjes: verter -append Ci) Marxclist = |o00 if Mi. path = Maxelist next_per mutation = permutations (vertex) punt Clist ( pesmudectiens/vextex))) : for i_jo_next-permutation: a _ current dist =O ver=C] _ kes — saler) ov jin ie prot ) urxenb-dist= cuventdist + qraph ChIC) vera) ke} cunvent-dists Current dist + graph CkJs) pot Ccurrent dist) T FOR EDUCATIONAL USE Gandara) currentedist) moin—path = min Cmin_path print (min- path) wink (ver) erefusn _mnio. path # main logic graph = Cco 10, 15, 20) Cio, 0, 3S, 25] CIS, 35,0, 303 (20, 25,30, 0 Isso ” TSPC graph, 5)) pin’ C“ The minimum distance is é # Output (C423) .C41,3,2) 62,43), 02,3,4), 84,2), (3)2,4) (4,23) i 2 3 95 qs (2,2... (4.3.2) FOR EDUCATIONAL USE © fo fe ° Bo Ct, 3,23 C223) 2 a 3 qs So C24, 35 (23,2) 2 3 a Bo go IC2,3,13 (34,29 3 i 2 95 go 34/25 FOR EDUCATIONAL USE (3,2, 4) 3 2 1 45 go C3,2,41) ‘The minimum distance TStece 6iOur emia FOR EDUCATIONAL USE Prackcal No? 9A Aico Devive the expyessions based om Associative law a= int (input CY Enter the value for a: ")) = jot (input (“ Enter the value ox b:”)) = jot Goput (4 Enter the value for ci") od = (at) "te pak C°vesult js_i” +1) = at (bt) ok Co After Assoc ative law: ”) paint C! Resuttt amd _[eesult2_ ave same”) #Oudpub Enter the value for Gaber the value for 0 loo 3 i6 Enter the value for 5 result is _< 1& After Associative law: Resultt and Rewlt2 ore same. FOR EDUCATIONAL USE, Ferackical No: 9B Aicn i Derive he expression based an _Distsi butive. law - a2 int Cinp ut (* Enter the value for q 3") be tnt Ciny ut _(" Enter the value for b i")) cz int Cinpuct CY Enter the value forc :")) paint! given Expressing : a * Cbtc)") oy wi: a * (bt+0) : paat C8 vesujt ti vi) . point CY distibuive e pression: (ab) + Ca¥c) ") _ v2 = CaXb) + Ca*o) pont (vesult 23 v2.) __[#outoue Enter the value pe ato - Enter the value for bi4 Enter the value for cS given expression ia Chto) wesult 4: 18 distxi butive expres jon i Ca ¥b) + Ca¥o) sresult 2: 38 Saas FOR EDUCATIONAL USE

You might also like