Skip to content

Commit 7139081

Browse files
added chicks_n_rabs question (ancient chinese puzzle), and bonestructure for clean_bot.
1 parent ab21546 commit 7139081

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

bots/clean_bot.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from matplotlib import pyplot as plt
2+
import random
3+
4+
# generate the canvas..
5+
def gen_grid(size):
6+
canvas = [[True for i in range(size)] for i in range(size)]
7+
return canvas
8+
9+
# randomly put dirty tiles in the canvas..
10+
def get_dirty(canvas):
11+
for i,row in enumerate(canvas):
12+
for j,_ in enumerate(row):
13+
canvas[i][j]=bool(random.getrandbits(1))
14+
# TODO - func to find nearest dirty tile from our robots current position..
15+
find_nn_dirty(canvas,point):
16+
x,y = point
17+
18+
# TODO - func to generate next move of our robot towards the dirt,
19+
# if on dirt: clean it.
20+
def move(curr,next_dirt):
21+
pass
22+
23+
if __name__=='__main__':
24+
canvas = gen_grid(100)
25+
get_dirty(canvas)
26+
print(canvas)

chicks_n_rabs.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'''Author Anurag Kumar(mailto:anuragkumarak95@gmail.com)
2+
3+
Module to solve a classic ancient Chinese puzzle:
4+
We count 35 heads and 94 legs among the chickens and rabbits in a farm.
5+
How many rabbits and how many chickens do we have?
6+
7+
8+
'''
9+
def solve(numheads,numlegs):
10+
ns='No solutions!'
11+
for i in range(numheads+1):
12+
j=numheads-i
13+
if 2*i+4*j==numlegs:
14+
return i,j
15+
return ns,ns
16+
17+
if __name__=="__main__":
18+
numheads=35
19+
numlegs=94
20+
21+
solutions=solve(numheads,numlegs)
22+
print(solutions)

0 commit comments

Comments
 (0)