Skip to content

Instantly share code, notes, and snippets.

@Superbil
Last active December 13, 2015 23:28
Show Gist options
  • Save Superbil/4991554 to your computer and use it in GitHub Desktop.
Save Superbil/4991554 to your computer and use it in GitHub Desktop.
find ship by Navy Fleet
#!/usr/bin/env ipython
# author: superbil
# define values
map_size = 7
small_limit = 3
middle_limit = 2
bigger_limit = 1
# create map
import numpy as np
map = np.zeros((map_size, map_size), int)
# define ship
small_ship = 1
middle_ship = 2
bigger_ship = 4
# set default places(sea or ships)
# set prompt value for vertical
# get input from raw_input()
vertical = [4,0,0,1,1,1,3] # example
#vertical = raw_input("vertical numbers:").split(' ')
# set prompt value for horizontal
horizontal = [0,4,1,1,2,1,1] # example
#horizontal = raw_input("horizontal numbers:").split(' ')
# print "v:%s, h:%s" % (vertical, horizontal) # debug use
# get input from raw_input()
# find ships
# find ship
# find a place to put ship on vertical
for i in range(len(vertical)):
for j in range(len(horizontal)):
# check v can put ship
v = vertical[i]
h = horizontal[j]
if v > 0:
print map[:v, j]
print map
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment