The 19th offline real-time writing problem in Python

Click here for the problem http://nabetani.sakura.ne.jp/hena/ord19nebasec/

Click here for other sample answers http://qiita.com/Nabetani/items/9810b301648099028bf0

from math import floor

def solve(data):
    bad = map(int, data.split(','))
    hdd = [[0]*n for n in (0, 8, 16, 24, 32)]
    def mark(t,s): hdd[t%len(hdd)][s%len(hdd[t])] += 1
    def side(t,s): return int(floor((s - 0.5) / track * t + 0.5))
    for track, sector in ((b/100, b%100) for b in bad):
        mark(track, sector-1)
        mark(track, sector+1)
        if track > 1:
            for s in range(side(track-1, sector), side(track-1, sector+1)+1):
                mark(track-1, s)
        if track < 4:
            for s in range(side(track+1, sector), side(track+1, sector+1)+1):
                mark(track+1, s)
    return ','.join(map(str, (t*100+s for t in (1,2,3,4) for s in range(8*t)
                              if hdd[t][s]>1 and t*100+s not in bad))) or "none"

def test(data, correct):
    answer = solve(data)
    print 'xo'[answer == correct], data, correct, answer

0, test( "400,401,302", "300,301,402" );
1, test( "105,100,306,414", "none" );
2, test( "100", "none" );
3, test( "211", "none" );
4, test( "317", "none" );
5, test( "414", "none" );
6, test( "100,106", "107" );
7, test( "205,203", "102,204" );
8, test( "303,305", "304" );
9, test( "407,409", "306,408" );
10, test( "104,103", "207" );
11, test( "204,203", "102,305" );
12, test( "313,314", "209,418" );
13, test( "419,418", "314" );
14, test( "100,102,101", "201,203" );
15, test( "103,206,309", "205,207,308,310" );
16, test( "414,310,309", "206,311,413" );
17, test( "104,102,206,307,102,202", "101,103,203,204,205,207,308" );
18, test( "104,206,308,409,407", "103,205,207,306,307,309,408,410" );
19, test( "313,406,213,301,409,422,412,102,428", "none" );
20, test( "101,300,210,308,423,321,403,408,415", "none" );
21, test( "304,316,307,207,427,402,107,431,412,418,424", "none" );
22, test( "205,408,210,215,425,302,311,400,428,412", "none" );
23, test( "200,311,306,412,403,318,427,105,420", "none" );
24, test( "105,305,407,408,309,208,427", "104,209,306,406" );
25, test( "311,304,322,404,429,305,316", "203,303,321,405,406,430" );
26, test( "210,401,316,425,101", "211,315" );
27, test( "414,403,404,416,428,421", "303,415" );
28, test( "207,300,103,211,428", "104,206" );
29, test( "322,314,310", "none" );
30, test( "427,200,215", "100,323" );
31, test( "311,402,424,307,318,430,323,305,201", "200,204,301,302,306,322,423,425,431" );
32, test( "425,430,408", "none" );
33, test( "202,320,209,426", "319,427" );
34, test( "430,209,302,310,304,431,320", "202,303,323" );
35, test( "208,206,406,424,213,312", "207,311,313" );
36, test( "420,302,313,413,317,402", "301,403" );
37, test( "319,306,309,418,204,411", "305,307,308,412" );
38, test( "400,308,105,430,203,428,209", "104,210,429,431" );
39, test( "200,305,214", "215" );
40, test( "214,408,410,407,317,422", "306,316,409,423" );

Recommended Posts

The 19th offline real-time writing problem in Python
The 14th offline real-time writing reference problem with Python
The 15th offline real-time how to write reference problem in Python
The 17th Offline Real-time How to Solve Writing Problems in Python
The 10th offline real-time writing reference problem. Implementation example by Python.
The 11th offline real-time writing reference problem. Implementation example by python.
The 18th offline real-time how to write reference problem in Python
The 17th offline real-time how to write reference problem implemented in Python
13th Offline Real-time How to Solve Writing Problems in Python
The twelfth offline real-time writing reference problem. Implementation by python
The 16th offline real-time how to write problem was solved with Python
The 16th offline real-time how to write reference problem to solve with Python
The 15th offline real-time how to write problem was solved with python
20th Offline Real-time How to Write Problems in Python
The 15th offline real-time I tried to solve the problem of how to write with python
Answer to "Offline real-time writing F05 problem"
Answer to "Offline Real-Time Writing E12 Problem"
Solve the maximum subarray problem in Python
The first step in the constraint satisfaction problem in Python
Install the python package in an offline environment
Basic information Write the 2018 fall algorithm problem in Python
Solve the one-stroke writing (backtrack without recursion in Python)
Download the file in Python
Find the difference in Python
Getting the arXiv API in Python
[Note] Project Euler in Python (Problem 1-22)
Python in the browser: Brython's recommendation
Hit the Sesami API in Python
Get the desktop path in Python
ABC166 in Python A ~ C problem
Get the script path in Python
In the python command python points to python3.8
Implement the Singleton pattern in Python
Hit the web API in Python
I wrote the queue in Python
Calculate the previous month in Python
Examine the object's class in python
Get the desktop path in Python
Get the host name in Python
Access the Twitter API in Python
The first step in Python Matplotlib
When writing a program in Python
I wrote the stack in Python
Master the weakref module in Python
Offline real-time how to write Python implementation example of E15 problem
Try running the basic information Python sample problem only in the browser
Solve the subset sum problem with a full search in Python
Trial of writing the configuration file in Python instead of .ini etc.
Part 1 I wrote the answer to the reference problem of how to write offline in real time in Python
Learn the design pattern "Prototype" in Python
Load the remote Python SDK in IntelliJ
Ant book in python: page 42 coin problem
Try using the Wunderlist API in Python
Learn the design pattern "Flyweight" in Python
Try using the Kraken API in Python
Learn the design pattern "Memento" in Python
Learn the design pattern "Proxy" in Python
Write the test in a python docstring
Learn the design pattern "Command" in Python
OR the List in Python (zip function)
Display Python 3 in the browser with MAMP