How to write offline real time I tried to solve the problem of F02 with Python

Problem: Number of squares contained in 2 rectangles 2017.2.22 Problem Implementation links: Offline real-time writing F02 problem-Qiita

Only for 10x10 for the time being.

def solve(data):
    area = lambda x1, y1, x2, y2: lambda x, y: x1 <= x <= x2 and y1 <= y <= y2
    areas = [area(*map(int, a.replace('-', ',').split(','))) for a in data.split('/')]
    return str(sum(sum(area(x, y) for area in areas) == 2 for x in range(10) for y in range(10)))

def test(data, correct):
    answer = solve(data)
    print ("NG","OK")[answer == correct], data, correct, '->', answer

test( "5,1-7,9/3,2-8,6/0,5-9,5", "15" )
test( "0,0-9,9/0,0-9,9/0,0-9,9", "0" )
test( "0,0-9,9/0,0-0,9/1,0-9,9", "100" )
test( "2,5-7,6/0,5-7,7/2,0-8,6", "0" )
test( "1,9-4,9/4,9-7,9/0,3-7,4", "1" )
test( "6,1-6,9/5,0-7,4/5,1-7,2", "6" )
test( "4,0-9,8/5,1-6,8/0,2-9,7", "28" )
test( "2,8-8,9/7,9-8,9/8,3-8,9", "2" )
test( "3,3-9,4/0,1-8,4/1,2-8,9", "12" )
test( "2,1-8,3/0,1-3,7/8,3-8,4", "7" )
test( "5,4-6,9/0,0-6,0/5,3-9,8", "10" )
test( "1,1-9,7/1,1-3,8/3,8-7,9", "22" )
test( "2,4-6,7/3,2-7,8/1,0-9,4", "24" )
test( "0,2-1,5/8,1-8,3/1,8-6,8", "0" )
test( "5,2-9,5/9,1-9,2/8,0-8,6", "5" )
test( "5,0-6,4/2,1-6,4/3,8-3,9", "8" )
test( "0,4-6,9/4,1-6,9/7,6-9,7", "18" )
test( "0,0-5,5/0,1-2,8/5,3-9,4", "17" )
test( "0,2-5,6/5,6-8,7/0,1-2,6", "16" )
test( "7,2-8,4/1,0-6,8/1,3-7,6", "26" )
test( "4,3-9,3/0,0-6,5/0,0-4,8", "31" )
test( "3,4-4,6/2,2-4,8/2,0-8,4", "11" )
test( "1,2-6,5/0,5-4,7/2,8-2,9", "4" )
test( "4,1-7,5/2,1-9,9/1,7-2,9", "23" )
test( "1,6-5,6/0,3-5,7/0,2-2,6", "13" )
test( "1,3-3,4/1,4-3,4/9,2-9,9", "3" )
test( "6,3-7,6/2,2-2,3/1,3-9,8", "9" )
test( "2,2-9,7/1,8-9,8/2,2-8,9", "49" )
test( "1,2-6,9/7,6-9,9/4,3-9,9", "33" )
test( "6,0-7,5/0,4-3,8/1,4-5,8", "15" )
test( "2,0-9,7/0,5-3,8/5,1-7,7", "27" )
test( "1,2-8,7/3,1-4,3/2,3-5,8", "20" )
test( "1,0-7,7/0,1-5,4/0,0-2,3", "19" )
test( "2,0-3,7/1,1-3,7/5,3-5,9", "14" )
test( "7,2-9,8/1,0-6,8/0,2-9,9", "63" )
test( "1,1-5,3/0,3-8,7/2,3-8,7", "32" )
test( "3,4-6,6/1,0-9,1/4,0-9,9", "21" )
test( "0,0-4,7/0,5-5,9/0,2-4,5", "25" )
test( "1,1-9,9/2,2-7,4/2,4-7,7", "30" )
test( "3,2-9,9/2,0-6,6/0,5-8,9", "36" )
test( "0,1-8,8/0,5-9,8/2,3-2,4", "38" )
test( "0,0-8,6/4,3-9,9/7,1-9,9", "29" )
test( "0,0-8,8/2,4-9,8/0,1-9,2", "53" )

Execution result


OK 5,1-7,9/3,2-8,6/0,5-9,5 15 -> 15
OK 0,0-9,9/0,0-9,9/0,0-9,9 0 -> 0
OK 0,0-9,9/0,0-0,9/1,0-9,9 100 -> 100
OK 2,5-7,6/0,5-7,7/2,0-8,6 0 -> 0
OK 1,9-4,9/4,9-7,9/0,3-7,4 1 -> 1
OK 6,1-6,9/5,0-7,4/5,1-7,2 6 -> 6
OK 4,0-9,8/5,1-6,8/0,2-9,7 28 -> 28
OK 2,8-8,9/7,9-8,9/8,3-8,9 2 -> 2
OK 3,3-9,4/0,1-8,4/1,2-8,9 12 -> 12
OK 2,1-8,3/0,1-3,7/8,3-8,4 7 -> 7
OK 5,4-6,9/0,0-6,0/5,3-9,8 10 -> 10
OK 1,1-9,7/1,1-3,8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-9,9 29 -> 29
OK 0,0-8,8/2,4-9,8/0,1-9,2 53 -> 53

Recommended Posts

How to write offline real time I tried to solve the problem of F02 with Python
The 15th offline real-time I tried to solve the problem of how to write with python
How to write offline real time I tried to solve E11 with python
How to write offline real time I tried to solve E12 with python
How to write offline real time Solve F01 problems with Python
Part 1 I wrote the answer to the reference problem of how to write offline in real time in Python
The 16th offline real-time how to write reference problem to solve with Python
Part 1 I wrote an example of the answer to the reference problem of how to write offline in real time in Python
I tried to solve the problem with Python Vol.1
The 19th offline real-time how to write reference problem to solve with Python
How to write offline real time Solve E04 problems in Python
The 15th offline real-time how to write problem was solved with python
I tried to solve the soma cube with python
I tried to find the entropy of the image with python
I tried to simulate how the infection spreads with Python
I tried to describe the traffic in real time with WebSocket
I tried to solve the ant book beginner's edition with python
The 15th offline real-time how to write reference problem in Python
Offline real-time how to write Python implementation example of E15 problem
I wanted to solve the ABC164 A ~ D problem with Python
The 14th offline real-time how to write reference problem in python
I tried to improve the efficiency of daily work with Python
The 18th offline real-time how to write reference problem in Python
Answer to "Offline real-time how to write F02 problem"
Answer to "Offline Real-time How to Write F01 Problem"
The 17th offline real-time how to write reference problem implemented in Python
I tried to get the authentication code of Qiita API with Python.
I tried to streamline the standard role of new employees with Python
I tried to get the movie information of TMDb API with Python
I tried to solve the first question of the University of Tokyo 2019 math entrance exam with python sympy
I tried to summarize how to use matplotlib of python
Try to solve the internship assignment problem with Python
I tried to touch the CSV file with Python
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried to summarize the string operations of Python
I tried to solve AOJ's number theory with Python
I tried to find out how to streamline the work flow with Excel x Python ②
I tried to find out how to streamline the work flow with Excel x Python ④
I tried to find out how to streamline the work flow with Excel x Python ⑤
I tried to put out the frequent word ranking of LINE talk with Python
I tried to solve the virtual machine placement optimization problem (simple version) with blueqat
I tried to automate the article update of Livedoor blog with Python and selenium.
I tried to find out how to streamline the work flow with Excel x Python ①
I tried to find out how to streamline the work flow with Excel x Python ③
I tried to compare the processing speed with dplyr of R and pandas of Python
I wanted to solve the Panasonic Programming Contest 2020 with Python
I tried to find the average of the sequence with TensorFlow
Offline real-time how to write Python implementation example of E14
I tried to solve a combination optimization problem with Qiskit
[Python] I tried to visualize the follow relationship of Twitter
I tried to divide the file into folders with Python
How to write offline real-time Solving E05 problems with Python
I tried to automatically post to ChatWork at the time of deployment with fabric and ChatWork Api
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
I tried scraping the ranking of Qiita Advent Calendar with Python
I tried to automate the watering of the planter with Raspberry Pi
The 17th Offline Real-time How to Solve Writing Problems in Python
I tried to make a regular expression of "time" using Python
Try to solve the N Queens problem with SA of PyQUBO