Posts

8-puzzle solving

 Game Trees Snigle Player Path Finding Problems 1.Rubik Cube 2.Sliding Puzzle 3.Travellig sales man Problem Two Player games 1.Chess 2.Checkers 3.Othello Constraint Satisfaction Problem 1.Eight Queens 2.Sudoku Solutions for 8-puzzle solving in python is  from source, github 8-puzzle Explanation from  Goeduhub More https://www.linkedin.com/pulse/solving-8-puzzle-using-algorithm-python-ajinkya-sonawane

Find how many iterations taken to get 6 on a 6-face die

  #rolling a 6-face dice #calculate how many iterations needed to get 6 import random n=1 iterations=0 while n>0:     n=random.randint(1,6)     if n==6:         print("Total iterations# ",iterations)         break#exit loop     iterations+=1

Find length of list using while loop without len() in python

  #Python 3.7.5 L=[10,10,2] i=0 while L[i:]:    i+=1 print("Length is ",i) #Likewise length of string  S="NAME" i=0 while S[i:]:     i+=1 print("len is ",i)

Maths vs Stats computations

 If total time taken to calculate perfect numbers from 1 to 10000 is 12 seconds(on i5 2nd gen 12gb ram) then find out total time taken for perfect numbers from 1 to 20000? sol: 24 seconds is wrong  Because as the number becoming large, computation calculation increases there by delay in time So time is 54 seconds(in my system) #Find  all perfect number 1 -100 import time as t start=t.time() z=1 while z<=20000:     n=z     i=1     sum=0     while i<n:         if n%i==0:             sum=sum+i         i=i+1     if sum==n:         print(n, end="\t")     z=z+1 end=t.time() print("Total time #",end-start, " seconds")

Python sudoku shortest code ever

def r(a):i=a.find('0');~i or exit(a);[m in[(i-j)%9*(i/9^j/9)*(i/27^j/27|i%9/3^j%9/3)or a[j]for j in range(81)]or r(a[:i]+m+a[i+1:])for m in'%d'%5**18] from sys import*;r(argv[1])   Src: http://www.scottkirkwood.com/2006/07/shortest-sudoku-solver-in-python.html Original Source:   Mark Byer's site has some more  Sudoku solvers     (can be found on web archive as web site is down) Expalanation https://jakevdp.github.io/blog/2013/04/15/code-golf-in-python-sudoku/ NOTE "A=0 #False B=20#True print(A or B) #B A=1 #True B=0#False print(A or B) #A you might expect the result to be either True or False. Instead, Python does something a bit clever. If the result is False, it returns A (which, naturally, evaluates to False).  If the result is True, it returns A if A evaluates to True, and B otherwise.  We can use this fact to remove the if statement completely from the set comprehension