aboutsummaryrefslogtreecommitdiff
path: root/challenge-087/roger-bell-west/python/ch-2.py
blob: 5bd1ec72a9599b550a121c8746981dec5271e042 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /usr/bin/python3

def lr(s):
    maxx=len(s)-1
    maxy=len(s[0])-1
    maxa=0
    c=list()
    for x in range(0,maxx):
        for y in range(0,maxy):
            if (s[x][y]==1):
                for tx in range (x+1,maxx+1):
                    for ty in range (y+1,maxy+1):
                        valid=1
                        for sx in range(x,tx+1):
                            for sy in range(y,ty+1):
                                if (s[sx][sy]!=1):
                                    valid=0
                                    break
                            if (valid==0):
                                break
                        if (valid):
                            l=[tx-x+1,ty-y+1]
                            a=l[0]*l[1]
                            if (a > maxa):
                                maxa=a
                                c=l
    if (len(c)):
        o=list()
        for i in range(0,c[0]):
            o.append([1] * c[1])
        return o
    else:
        return 0
   
import unittest;

class TestLcs(unittest.TestCase):

    def test_ex1(self):
        self.assertEqual(lr((
            (0,0,0,1,0,0),
            (1,1,1,0,0,0),
            (0,0,1,0,0,1),
            (1,1,1,1,1,0),
            (1,1,1,1,1,0),
        )),
                         [
                             [1,1,1,1,1],
                             [1,1,1,1,1],
                         ],
                         'example 1')

    def test_ex2(self):
        self.assertEqual(lr((
            (1,0,1,0,1,0),
            (0,1,0,1,0,1),
            (1,0,1,0,1,0),
            (0,1,0,1,0,1),
        )),
                         0,
                         'example 2')

    def test_ex3(self):
        self.assertEqual(lr((
            (0,0,0,1,1,1),
            (1,1,1,1,1,1),
            (0,0,1,0,0,1),
            (0,0,1,1,1,1),
            (0,0,1,1,1,1),
        )),
                         [
                             [1,1,1,1],
                             [1,1,1,1],
                         ],
                         'example 3')

unittest.main()