aboutsummaryrefslogtreecommitdiff
path: root/challenge-084/roger-bell-west/python/ch-2.py
blob: 27e091f6b0ce141c6ecfff88ddc6ad85c4f98fa5 (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
#! /usr/bin/python3

import unittest

def fs(s):
    t=0
    maxx=len(s)-1
    maxy=len(s[0])-1
    for x in range(0,maxx):
        for y in range(0,maxy):
            if (s[x][y] == 1):
                for d in range(1,min(maxx-x,maxy-y)+1):
                    if (s[x+d][y] == 1 and
                        s[x][y+d] == 1 and
                        s[x+d][y+d] == 1):
                            t += 1
    return t

class TestFs(unittest.TestCase):

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

    def test_ex2(self):
        self.assertEqual(fs((
            [1,1,0,1],
            [1,1,0,0],
            [0,1,1,1],
            [1,0,1,1])),
                         4,'example 2')

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

unittest.main()