コード例 #1
0
    def test_outputCount(self):
        from main import parseInput, countUnique

        signalPatterns, outputValues = parseInput(sample1)
        result = countUnique(outputValues[0])
        self.assertEqual(result, 0)

        result = countUnique(signalPatterns[0])
        self.assertEqual(result, 4)

        signalPatterns, outputValues = parseInput(sample2)
        total = 0
        for output in outputValues:
            total += countUnique(output)
        self.assertEqual(total, 26)
コード例 #2
0
    def test_input(self):
        from main import parseInput
        commands = parseInput(["forward 4"])
        self.assertEqual(commands, [{"command": "forward", "distance": 4}])

        commands = parseInput(["up 3"])
        self.assertEqual(commands, [{"command": "up", "distance": 3}])

        commands = parseInput(["down 12"])
        self.assertEqual(commands, [{"command": "down", "distance": 12}])

        commands = parseInput(["down 12"])
        self.assertEqual(commands, [{"command": "down", "distance": 12}])

        commands = parseInput(["up -7"])
        self.assertEqual(commands, [{"command": "up", "distance": -7}])
コード例 #3
0
 def test_decoding(self):
     from main import parseInput, determineValue
     signalPatterns, outputValues = parseInput(sample1)
     result = determineValue(signalPatterns[0])
     self.assertEqual(result, [
         'cagedb', 'ab', 'gcdfa', 'fbcad', 'eafb', 'cdfbe', 'cdfgeb', 'dab',
         'acedgfb', 'cefabd'
     ])
コード例 #4
0
def parse():
    '''
    Don't want to have to repeat this...
    '''
    from main import parseInput
    fileText = sample1.replace("\n\n", "\n")
    inputStrings = fileText.split('\n')
    return parseInput(inputStrings, 5)
コード例 #5
0
    def test_v1_part1(self):
        from main import step, parseInput

        fish = parseInput(sample1)
        for i in range(0, 80):
            fish = step(fish)

        self.assertEqual(len(fish), 5934)
コード例 #6
0
    def test_part2(self):
        from main import parseInput, findLowPoints, getBasins
        grid = parseInput(sample2)
        lowPoints = findLowPoints(grid)

        basins = getBasins(lowPoints, grid)

        self.assertEqual(basins, [3, 9, 9, 14])

        value = basins[-1] * basins[-2] * basins[-3]
        self.assertEqual(value, 1134)
コード例 #7
0
    def test_v2(self):
        from main import parseInput, Grid
        biggest, coordinates = parseInput(sample1)
        testGrid = Grid(biggest)

        for line in coordinates:
            testGrid.placeLine(line)

        result = testGrid.findOverlaps()
        print("Map for V2")
        pp.pprint(testGrid.map)
        self.assertEqual(result, 12)
コード例 #8
0
    def test_markGrid(self):
        from main import parseInput, Grid, filterOutDiagonals
        biggest, coordinates = parseInput(sample0)
        coords = filterOutDiagonals(coordinates)
        testGrid = Grid(biggest)

        for line in coords:
            testGrid.placeLine(line)

        self.assertEqual(
            testGrid.map,
            [[0, 0, 0, 0], [0, 0, 0, 1], [0, 0, 0, 1], [1, 1, 1, 1]])
コード例 #9
0
    def test_v1(self):
        from main import parseInput, Grid, filterOutDiagonals
        biggest, coordinates = parseInput(sample1)
        coords = filterOutDiagonals(coordinates)
        testGrid = Grid(biggest)

        for line in coords:
            testGrid.placeLine(line)

        result = testGrid.findOverlaps()
        print("Map for V1")
        pp.pprint(testGrid.map)
        self.assertEqual(result, 5)
コード例 #10
0
    def test_v2_part2(self):
        from main import stepV2, parseInput

        fish = parseInput(sample1)
        fishTrack = np.array([
            len(fish[fish == 0]),
            len(fish[fish == 1]),
            len(fish[fish == 2]),
            len(fish[fish == 3]),
            len(fish[fish == 4]),
            len(fish[fish == 5]),
            len(fish[fish == 6]),
            len(fish[fish == 7]),
            len(fish[fish == 8])
        ],
                             dtype=np.int64)
        for i in range(0, 256):
            fishTrack = stepV2(fishTrack)

        self.assertEqual(np.sum(fishTrack), 26984457539)
コード例 #11
0
    def test_filterDiagonals(self):
        from main import parseInput, filterOutDiagonals
        biggest, coordinates = parseInput(sample0)
        result = filterOutDiagonals(coordinates)

        self.assertEqual(result, [[[1, 3], [3, 3]], [[3, 0], [3, 2]]])
コード例 #12
0
    def test_inputParsing(self):
        from main import parseInput
        biggest, coordinates = parseInput(sample1)
        self.assertEqual(biggest, 9)

        self.assertEqual(coordinates[0], [[0, 9], [5, 9]])
コード例 #13
0
    def test_parse(self):
        from main import parseInput

        signalPatterns, outputValues = parseInput(sample1)

        self.assertEqual(outputValues, [["cdfeb", "fcadb", "cdfeb", "cdbaf"]])
コード例 #14
0
ファイル: dispatcher.py プロジェクト: designer52/HPS2013
    distances = list(((self.getDistance(person, ambulance),) + person)
                          for person in sorted(persons))
    return distances

  def getDistance(self, person, ambulance):
    personCoordinates = (person[1], person[2])
    ambulanceCoordinates = (ambulance[1], ambulance[2])
    distance = self.__cityMap.getDistance(personCoordinates, ambulanceCoordinates)
    return distance

  def anyPersonsLeftToRescue(self):
    personsToRescue = self.__cityMap.get911Calls()
    if personsToRescue == set():
      return False
    else:
      return True

  def anyAmbulancesFree(self):
    ambulances = self.__cityMap.callAmbulances()
    if ambulances == set():
      return False
    else:
      return True

if __name__ == '__main__':
  import main
  cityMap = main.parseInput('input')
  cityMap.placeHospitals()
  dispatcher = Dispatcher(cityMap)
  dispatcher.route()
コード例 #15
0
 def test_parse(self):
     from main import parseInput, findLowPoints, calculateScore
     grid = parseInput(sample2)
     lowPoints = findLowPoints(grid)
     result = calculateScore(lowPoints)
     self.assertEqual(result, 15)
コード例 #16
0
 def test_V2(self):
     from main import parseInput, traceDirectionsV2
     position = {"horizontal": 0, "depth": 0, "aim": 0}
     commands = parseInput(sample1)
     position = traceDirectionsV2(commands, position)
     self.assertEqual(position["horizontal"] * position["depth"], 900)