-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e38c06e
commit 1474a9a
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
#Problem: QueensReach, made by SiddharthChaberia | ||
# This code takes the size of the n*n board and the initial position of a chess queen as inputs, and returns how many boxes can it cover from the current positions, given that their is just that queen on the whole board | ||
# This code is funny as it wont really help in any real life problem because u cant play with just a single queen with no opponents obstructing XD | ||
# Hopefully my contribution also gets accepted and becomes a part of Hacktober 2022 fest ✨ | ||
|
||
def queensreach(n,pos): | ||
up=n-pos[0] # considering the blocks above the queen | ||
down=pos[0]-1 # considering the blocks below the queen | ||
left=pos[1]-1 # considering the block on left side of the queen | ||
right=n-pos[1] # considering the blocks on right side of the queen | ||
upleft=min(up,left) # considering the blocks on upper left diagonal of the queen | ||
upright=min(up,right) # considering the blocks on upper right diagonal of the queen | ||
downright=min(down,right) # considering the blocks on lower right diagonal of the queen | ||
downleft=min(down,left) # considering the blocks on lower left diagonal of the queen | ||
scope=up+down+left+right+upleft+upright+downright+downleft | ||
return scope | ||
|
||
n=int(input("Enter the length/breadth of the chessboard: ")) | ||
position=[int(i) for i in input("Enter the x and y position of the queen (1-indexed base): ").split()] | ||
output=queensreach(n,position) | ||
print("The queen could cover:",output,"blocks") |