How to write offline real time I tried to solve E12 with python

Problem: http://mtsmfm.github.io/2017/03/04/doukaku-e12.html Answer links: http://qiita.com/mtsmfm/items/d307c7b884cd86621262

It has become the same logic as other people.

import re

shapes = { 'I': ((0,), (4,)),
           'L': ((0, 0), (3, 1)),
           'O': ((0, 0), (2, 2)),
           'S': ((0, 0, 1), (1, 2, 2)),
           'T': ((1, 0, 1), (2, 2, 2)) }

def solve(data):
    board = {}
    for shift, tetromino in re.findall('(\d+)(.)', data):
        bottom_gaps, heights = shapes[tetromino]
        y = max(board.get(x, 0) - gap
                for x, gap in enumerate(bottom_gaps, int(shift)))
        for x, height in enumerate(heights, int(shift)):
            board[x] = y + height
    return str(max(board.values()))

def test(data, correct):
    answer = solve(data)
    print("%s %s : %s %s" % (("NG", "OK")[answer == correct], answer, correct, data))

test("1O3L0I0T", "5")
test("0I", "4")
test("0I0I", "8")
test("0I1I2I3I4I", "4")
test("0S0I", "5")
test("0I0S", "6")
test("2S0T2O3I", "8")
test("4O4T1T0S4L1L3L", "10")
test("0S2S4S6S8S10S12S14S", "16")
test("14S12S10S8S6S4S2S0S", "2")
test("5I2O10I0O4L10T9T11L8I2I10I12O7L12T12T12S11T9O10O13I12O10O7I9I7O0S1O2S0L1L", "23")
test("9T14L10L8T4I1T3S5I8T12O3S7L9O7L14T2I7O3S6S2L0L13T10O4I9T7L8S0I12O9S11L11T14T", "27")
test("9S9S7O11O16I2T9O12L10T9O0O13I9O1I2T14S7O9S11T5L7I14T13O0T12I3S10L10O7I15I6S2L12S8I16I3L", "23")
test("11T13I16S15T7O10L12S1I5I8S5I13I15O8S9I1T12I1S5S0L14I12L16T2S2S8L2S14L16O4I13L15L13S11S9T13S9S3L6O", "22")
test("12L10S7I5L14T12S9L1T14I0I5L1T2O18T9L0I15I16L10S1O15I0L17O5L18T4I18L7L7I13I3I12I2S3T5T3S16L14S14O11O15T14S", "17")
test("0S18S2S19I14T7L14L2L6I9I0L4I5L13L15I8S8T2I5I7O18T3S1T7I2L8O0S20T9I14T5L5I1T4L9O8T19T5S12O16T19L4O10O10T14L", "24")
test("7T5L6S4S8T6S10I19O20L14I18L21S7I11S11O1L13T20O9I7L2T8L2S20L3O14L9T17I8L8S14I6T2O11T21O18O6T15T1S3L6O19S18O20S19O16T6S14T", "26")
test("18S2I4S16L13S17I21O8I17T8I14O12T20I20S19S16S13T12T20I22I15O2I2I8I2S18I9I9T6O13O13L17I2L20L2L4I9I19O11T3S10O2S18T12I5O11S19O21S6I17T17S", "26")
test("11L5S0T22S18O13T2O22S15I12I21T16I3I1I22L11L11L22O13S24S15L13T15S19L10O15T7S24T19L0T13O11I12T13S4I24L15O3S19O10L19O0S20L7O11L21I22S18T19T23O8I22S24L0S", "21")
test("7L7I11T7S18O17L8S15L9I3O24S3O1O5O14L9T13S2O25S22T10T8L24S18S13T1O1L6I10I4S13O3S7L10T1T4L17S20I18O15S25S23S21I19T6O24S9L2O2O15L12L8L8O18I18L0T5O", "31")
test("999I999I999I999I999I999I999I999I999I999I999I", "44")

Recommended Posts

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 I tried to solve the problem of F02 with Python
How to write offline real time Solve E04 problems in Python
How to write offline real time Solve F01 problems 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 Solving E05 problems with Python
The 16th offline real-time how to write reference problem to solve with Python
I tried to solve the soma cube with python
I tried to solve the problem with Python Vol.1
Part 1 I wrote the answer to the reference problem of how to write offline in real time in Python
I tried to solve AOJ's number theory with Python
I tried to simulate how the infection spreads with Python
Offline real-time how to write Python implementation example of E14
Part 1 I wrote an example of the answer to the reference problem of how to write offline in real time in Python
I wanted to solve ABC160 with Python
I tried to solve TSP with QAOA
I wanted to solve ABC172 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
Offline real-time how to write E11 ruby and python implementation example
Offline real-time how to write Python implementation example of E15 problem
The 16th offline real-time how to write problem was solved with Python
I wanted to solve NOMURA Contest 2020 with Python
I tried to get CloudWatch data with Python
I tried to output LLVM IR with Python
How to measure execution time with Python Part 1
I tried to automate sushi making with python
I want to solve APG4b with Python (Chapter 2)
The 15th offline real-time how to write problem was solved with python
Answer to "Offline Real-time How to Write E13 Problem"
I want to write to a file with Python
How to measure execution time with Python Part 2
Python / PEP8> E128 I tried to solve continuation line under-indented for visual indent
20th Offline Real-time How to Write Problems in Python
I tried to summarize how to use matplotlib of python
I tried to implement Minesweeper on terminal with python
I tried to get started with blender python script_Part 01
I tried to touch the CSV file with Python
I tried to draw a route map with Python
How to measure mp3 file playback time with python
I tried to get started with blender python script_Part 02
I tried to implement an artificial perceptron with python
I tried to automatically generate a password with Python3
I tried to summarize how to use pandas in python
I tried to analyze J League data with Python
I tried fp-growth with python
I tried scraping with Python
Write to csv with Python
I tried gRPC with Python
I tried scraping 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 ⑤
[For beginners in competition professionals] I tried to solve 40 AOJ "ITP I" questions with python
I tried to find out how to streamline the work flow with Excel x Python ①
I tried to aggregate & compare unit price data by language with Real Gachi by Python
I tried to find out how to streamline the work flow with Excel x Python ③
I tried to find the entropy of the image with python
I tried various methods to send Japanese mail with Python
I made a package to filter time series with python
I tried to solve a combination optimization problem with Qiskit