コード例 #1
0
def minimumLevel(numbers):
    # print("numbers=" + numbers)
    localOptimal = []
    for idx in range(0, len(numbers) + 1):
        localOptimal.append(0)

    localOptimal[0] = 0
    localOptimal[1] = INF
    localOptimal[2] = INF
    localOptimal[3] = integratedLevel(numbers[:3], 3)

    # vs integratedLevel(numbers[:4], 3) + localOptimal[4-3]
    localOptimal[4] = integratedLevel(numbers[:4], 4) + localOptimal[4 - 4]
    # vs integratedLevel(numbers[:4], 5) + localOptimal[4-5]

    # vs integratedLevel(numbers[:5], 3) + localOptimal[5-3]
    # vs integratedLevel(numbers[:5], 4) + localOptimal[5-4]
    localOptimal[5] = integratedLevel(numbers[:5], 5)

    for idx in range(6, len(numbers) + 1):
        minimum = INF
        for sublength in [3, 4, 5]:
            candidate = integratedLevel(numbers[:idx], sublength) \
                        + localOptimal[idx - sublength]
            if minimum > candidate:
                minimum = candidate

        localOptimal[idx] = minimum
        # print("localOptimal= " + str(minimum))

    return localOptimal[-1]
コード例 #2
0
 def test_2(self):
     self.assertEqual(integratedLevel('123', 3), 2)
コード例 #3
0
 def test_length5_5(self):
     self.assertEqual(integratedLevel('13901', 5), 10)
コード例 #4
0
 def test_1(self):
     self.assertEqual(integratedLevel('000', 3), 1)
コード例 #5
0
 def test_length5_3(self):
     self.assertEqual(integratedLevel('23232', 5), 4)
コード例 #6
0
 def test_length5_4(self):
     self.assertEqual(integratedLevel('13579', 5), 5)
コード例 #7
0
 def test_length5_1(self):
     self.assertEqual(integratedLevel('00000', 5), 1)
コード例 #8
0
 def test_length5_2(self):
     self.assertEqual(integratedLevel('12345', 5), 2)
コード例 #9
0
 def test_length4_4(self):
     self.assertEqual(integratedLevel('1357', 4), 5)
コード例 #10
0
 def test_length4_5(self):
     self.assertEqual(integratedLevel('1390', 4), 10)
コード例 #11
0
 def test_length4_3(self):
     self.assertEqual(integratedLevel('2323', 4), 4)
コード例 #12
0
 def test_length4_2(self):
     self.assertEqual(integratedLevel('1234', 4), 2)
コード例 #13
0
 def test_5(self):
     self.assertEqual(integratedLevel('139', 3), 10)
コード例 #14
0
 def test_4(self):
     self.assertEqual(integratedLevel('147', 3), 5)
コード例 #15
0
 def test_3(self):
     self.assertEqual(integratedLevel('232', 3), 4)