Thursday, March 14, 2019

codingdirectional: Count the number of audiences around you in the theater

Hello and welcome back. In this chapter, we are going to create the python method which will count the number of audiences around you in the theater based on the column and the row you are sitting on as well as the total rows and the total columns of the seat in the cinema. Here is the full question from CodeWars.

Your friend advised you to see a new performance in the most popular theater in the city. He knows a lot about art and his advice is usually good, but not this time: the performance turned out to be awfully dull. It’s so bad you want to sneak out, which is quite simple, especially since the exit is located right behind your row to the left. All you need to do is climb over your seat and make your way to the exit.

The main problem is your shyness: you’re afraid that you’ll end up blocking the view (even if only for a couple of seconds) of all the people who sit behind you and in your column or the columns to your left. To gain some courage, you decide to calculate the number of such people and see if you can possibly make it to the exit without disturbing too many people.

Given the total number of rows and columns in the theater (nRows and nCols, respectively), and the row and column you’re sitting in, return the number of people who sit strictly behind you and in your column or to the left, assuming all seats are occupied.

Example : For nCols = 16, nRows = 11, col = 5 and row = 3, the output should be

Here is the solution to the above question.

def seats_in_theater(tot_cols, tot_rows, col, row):

    a1 = tot_cols - col
    b1 = tot_rows - row
    total1 = a1 * b1
    return b1 + (total1)

Very simple, all you need is just to think a little bit. Help me to retweet this tweet so we can share this solution with more people.



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...