diff --git a/5/IfYouGiveASeedAFertilizer.ipynb b/5/IfYouGiveASeedAFertilizer.ipynb index 6793f93..de36bc6 100644 --- a/5/IfYouGiveASeedAFertilizer.ipynb +++ b/5/IfYouGiveASeedAFertilizer.ipynb @@ -111,31 +111,37 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 62, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[['50', '98', '2'], ['52', '50', '48']]\n", + "[[52, 50, 48], [50, 98, 2]]\n", "seed-to-soil map\n", "\n", - "[['0', '15', '37'], ['37', '52', '2'], ['39', '0', '15']]\n", + "[[39, 0, 15], [0, 15, 37], [37, 52, 2]]\n", "soil-to-fertilizer map\n", "\n", - "[['49', '53', '8'], ['0', '11', '42'], ['42', '0', '7'], ['57', '7', '4']]\n", + "[[42, 0, 7], [57, 7, 4], [0, 11, 42], [49, 53, 8]]\n", "fertilizer-to-water map\n", "\n", - "[['88', '18', '7'], ['18', '25', '70']]\n", + "[[88, 18, 7], [18, 25, 70]]\n", "water-to-light map\n", "\n", - "[['45', '77', '23'], ['81', '45', '19'], ['68', '64', '13']]\n", + "[[81, 45, 19], [68, 64, 13], [45, 77, 23]]\n", "light-to-temperature map\n", "\n", - "[['0', '69', '1'], ['1', '0', '69']]\n", + "[[1, 0, 69], [0, 69, 1]]\n", "temperature-to-humidity map\n", - "\n" + "\n", + "14\n", + "14\n", + "53\n", + "53\n", + "53\n", + "89\n" ] } ], @@ -147,14 +153,38 @@ " def __init__(self, name, map):\n", " self.name = name\n", " self.map = map\n", + " self.selforganise()\n", + "\n", + " def selforganise(self):\n", + " for i in range(len(self.map)):\n", + " for j in range(i, len(self.map)):\n", + " if self.map[i][1]> self.map[j][1]:\n", + " temp = self.map[i]\n", + " self.map[i] = self.map[j]\n", + " self.map[j] = temp\n", + "\n", + "\n", + "def convert(obj, num):\n", + " index = 0\n", + "\n", + " for i in obj.map:\n", + " if i[1] <= num:\n", + " #print(\"IIIII: \", )\n", + " break\n", + " index += 1\n", + " else:\n", + " index -= 1\n", + " if obj.map[index][1] + obj.map[index][2] > num:\n", + " return num\n", " \n", - " def getconvert(self, numbre):\n", - " for i in self.map:\n", - "\n", - " pass\n", - "\n", "\n", + " #print(obj.map[index][1], \" \", obj.map[index][2], \" \", num)\n", + " space = num - obj.map[index][1]\n", + " if space > obj.map[index][2]:\n", + " return num\n", "\n", + " return obj.map[index][0] + space\n", + " \n", "\n", "with open(\"almanac.txt\", 'r') as reader:\n", " seedlist = reader.readline()\n", @@ -166,12 +196,18 @@ " elif i != '\\n':\n", " maper.append(list(i.split()))\n", " elif len(maper) > 0 and name != \"\":\n", - " almanac.append(map(name, maper))\n", + " almanac.append(map(name, [[eval(j) for j in i] for i in maper]))\n", " maper = []\n", "\n", "for i in almanac:\n", " print(i.map)\n", - " print(i.name)" + " print(i.name)\n", + "\n", + "location = 14\n", + "\n", + "for i in almanac:\n", + " print(location)\n", + " location = convert(i, location)" ] } ],