Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.62 KB | None | 0 0
  1. """Exam3."""
  2. from typing import List, Tuple, Optional
  3. import re
  4.  
  5.  
  6. def sum_nums(num1: int, num2: int) -> List:
  7. """
  8. Sum two numbers as an integer and as a string.
  9.  
  10. #01
  11.  
  12. sum_nums(1, 2) -> [3, '12']
  13. sum_nums(12, 34) -> [46, '1234']
  14. sum_nums(33, 44) -> [77, '3344']
  15. sum_nums(0, 0) -> [0, '00']
  16.  
  17. :param num1: Given non-negative integer
  18. :param num2: Given non-negative integer
  19. :return: Sums of num1, num2; list with one integer and one string.
  20. """
  21. return [num1 + num2, str(num1) + str(num2)]
  22.  
  23.  
  24. def numbers_in_list(number1: int, number2: int, numbers: List[int]) -> int:
  25. """
  26. Given two integers and a list, return the required result.
  27.  
  28. #02
  29.  
  30. Return sum of the two numbers if both numbers are in the given list.
  31. If only one of these numbers is in the list, return that number minus the other number.
  32. If both of them are not in the list, return product of their multiplication, unless they differ from 0 equally,
  33. then return 0.
  34.  
  35. numbers_in_list(3, 5, [5, 6, 3, 1]) -> 8
  36. numbers_in_list(0, 2, [3, 2, 9]) -> 2
  37. numbers_in_list(0, 2, [3, 0, 9]) -> -2
  38. numbers_in_list(3, 6, [5, 9, 8]) -> 18
  39. numbers_in_list(9, 9, [0, 6, 32]) -> 0
  40.  
  41. :param number1: First given number
  42. :param number2: Second given number
  43. :param numbers: Given list
  44. :return: Required result.
  45. """
  46. if number1 in numbers and number2 in numbers:
  47. return number1 + number2
  48. elif number1 in numbers and number2 not in numbers:
  49. return number1 - number2
  50. elif number2 in numbers and number1 not in numbers:
  51. return number2 - number1
  52. elif number1 not in numbers and number2 not in numbers and abs(number1) != abs(number2):
  53. return number1 * number2
  54. elif number1 not in numbers and number2 not in numbers and abs(number1) == abs(number2):
  55. return 0
  56.  
  57.  
  58. def multiply_after_digit(s: str) -> str:
  59. """
  60. Given a string where the number before letter stands for its quantity, return the result string.
  61.  
  62. #03
  63.  
  64. You get 80% (40 points out of 50) if the function works with one digit. To get 100%, is should also work with more digits.
  65.  
  66. multiply_after_digit('a5b4c') -> 'abbbbbcccc'
  67. multiply_after_digit('2 0nhe2lo world3!') -> ' hello world!!!'
  68. multiply_after_digit('thi10s end3s wit3h 31') -> 'thissssssssss endsss withhh ' (to get 100%)
  69.  
  70. :param s: Given input string
  71. :return: Result string.
  72. """
  73. string = ""
  74. pattern = r"\d+\s|\s|\d+[^\d]|[^\d]"
  75. mps = [n for n in re.findall(pattern, s)]
  76. print(mps)
  77. for i in mps:
  78. if len(i) == 1:
  79. try:
  80. if int(i) and i != " ":
  81. return string
  82. except ValueError:
  83. string += i
  84. elif len(i) > 1:
  85. if i[-1] == " ":
  86. string += i[-1] * int(i[:-1])
  87. try:
  88. if int(i) and i[-1] != " ":
  89. return string
  90. except ValueError:
  91. string += i[-1] * int(i[:-1])
  92. return string
  93.  
  94.  
  95. def mastermind_guess(solution: List[int], guess: List[int]) -> List[int]:
  96. """
  97. Return the result of the guess in Mastermind game.
  98.  
  99. #04
  100.  
  101. Mastermind is a game where the player tries to guess the correct order of numbers.
  102. The function has a parameter solution, which indicates the correct order of elements.
  103. All the elements are positive numbers, there are no duplicate elements in the solution.
  104. The parameter guess indicates a guess by the player.
  105. The length of the solution and guess is always the same.
  106.  
  107. The function should return the outcome of the guess,
  108. where for every element in guess there is a number in the result:
  109. - 2 if the given element in guess was in the correct position (in solution)
  110. - 1 if the given element in guess is in solution, but not in the correct position,
  111. - 0 if the given element is not in the solution.
  112.  
  113. The length of the solution (and guess) is at least 1.
  114.  
  115. Examples:
  116.  
  117. mastermind_guess([1, 2, 3], [1, 2, 3]) => [2, 2, 2]
  118. mastermind_guess([1, 2, 3], [3, 1, 2]) => [1, 1, 1]
  119. mastermind_guess([1, 2, 3], [3, 3, 3]) => [1, 1, 2]
  120. mastermind_guess([1, 2], [7, 3]) => [0, 0]
  121.  
  122. :param solution: Non-empty list of positive integers.
  123. :param guess: Non-empty list of positive integers.
  124. :return: Result for the guess.
  125. """
  126. answer = []
  127. for n in range(0, len(solution)):
  128. if solution[n] == guess[n]:
  129. answer.append(2)
  130. elif guess[n] in solution:
  131. answer.append(1)
  132. else:
  133. answer.append(0)
  134. return answer
  135.  
  136.  
  137. def reformat_money(data: dict) -> dict:
  138. """
  139. Reformat data in dictionary.
  140.  
  141. #05
  142.  
  143. Dictionary represents money (integers) as keys and people's names (strings) as values.
  144. You should switch key-value pairs in dictionary, to know, how much money each person has.
  145. There can be different money entries with same names, you have to sum the money for each person.
  146. If a persons name contains the words james or bond (non-case sensitive), double the money to be added.
  147.  
  148. The order of the dict is not important.
  149.  
  150. reformat_money({10: 'A', 20: 'B', 30: 'a', 40: 'A', 50: 'James'}) => {'A': 50, 'B': 20, 'a': 30, 'James': 100}
  151.  
  152. :param data: Dictionary with data
  153. :return: Dictionary with reformatted data.
  154. """
  155. new_dict = {}
  156. keys = [i for i in data.keys()]
  157. values = [i for i in data.values()]
  158. for i in range(len(keys)):
  159. if values[i].lower() == "james" or values[i].lower() == "bond" and values[i] not in new_dict:
  160. new_dict[values[i]] = keys[i] * 2
  161. elif values[i].lower() == "james" or values[i].lower() == "bond":
  162. new_dict[values[i]] += keys[i] * 2
  163. elif values[i] not in new_dict:
  164. new_dict[values[i]] = keys[i]
  165. else:
  166. new_dict[values[i]] += keys[i]
  167. return new_dict
  168.  
  169.  
  170. def collatz_conjecture(num: int, i=0, max_term=0) -> Optional[Tuple[int, int]]:
  171. """
  172. Given integer, return the number of steps Collatz sequence needed to reach 1 and the biggest term on the way.
  173.  
  174. #06
  175.  
  176. The solution has to be recursive!
  177.  
  178. The Collatz conjecture is a conjecture that concerns a sequence that started with any positive integer n.
  179. If the previous term is even, the next term is previous term / 2.
  180. If the previous term is odd, the next term is 3 * previous term + 1.
  181. The conjecture states that no matter what value of n, the sequence will always reach 1.
  182.  
  183. collatz_conjecture(12) -> 9, 16 (sequence is [12, 6, 3, 10, 5, 16, 8, 4, 2, 1], steps - 9, biggest term - 16)
  184. collatz_conjecture(1) -> 0, 1 (sequence is [1], steps - 0, biggest term - 1)
  185. collatz_conjecture(27) -> 111, 9232
  186. collatz_conjecture(670617279) -> 949, 966616035460 (close to the border of RecursionError, but should still work)
  187. collatz_conjecture(0) -> None
  188.  
  189. :param num: Given integer
  190. :return: Tuple with length of sequence and biggest term or None if input is not valid.
  191. """
  192. if num <= 0:
  193. return None
  194. if num > max_term:
  195. max_term = num
  196. if num == 1:
  197. return i, max_term
  198. elif num > 1:
  199. i += 1
  200. if num % 2 == 0:
  201. num = num // 2
  202. return collatz_conjecture(num, i, max_term)
  203. else:
  204. num = 3 * num + 1
  205. return collatz_conjecture(num, i, max_term)
  206.  
  207.  
  208. def plot_the_tangerines(integers: List[int]) -> str:
  209. """
  210. Given list of non-negative integers create a bar graph.
  211.  
  212. #07
  213.  
  214. Recently you have noticed that your consumption of tangerines is too high.
  215. You want to monitor the situation so you try to make a bar graph of tangerines consumption in Excel.
  216. But Excel won't work, because you have just started using Linux.
  217. Oh well, it seems that you have to make your own program to plot graphs and do fancy calculations.
  218.  
  219. Graph consists of scale (left) and stack of '#'s that represent integer in the list (consumed tangerines in a day).
  220. 0 means stack of 0 '#', 1 means stack of 1 '#', 2 means stack of 2 '#' and so on.
  221.  
  222. Graph max height should be the maximum value from the list, max is always at least 1.
  223. There is always at least one element in the list.
  224. Graph needs to be in a frame consisting of '|', '-' and '+' characters as shown in examples.
  225. There should be no newlines before or after the graph.
  226.  
  227.  
  228. plot_the_tangerines([1, 0, 2, 3, 4, 5, 4, 3, 2, 1, 0, 3, 2, 1]) =>
  229. +--------------+
  230. 5| # |
  231. 4| ### |
  232. 3| ##### # |
  233. 2| ####### ## |
  234. 1|# ######## ###|
  235. 0+--------------+
  236.  
  237. plot_the_tangerines([0]) =>
  238. +-+
  239. 1+ +
  240. 0+-+
  241.  
  242. plot_the_tangerines([0, 0, 0, 0, 0, 0])) =>
  243. +------+
  244. 1| |
  245. 0+------+
  246.  
  247. plot_the_tangerines([1, 4, 5, 3, 1]) =>
  248. +-----+
  249. 5| # |
  250. 4| ## |
  251. 3| ### |
  252. 2| ### |
  253. 1|#####|
  254. 0+-----+
  255.  
  256. In case the maximum value is is more than 9, the left side should be wider, aligned to right:
  257.  
  258. +-----
  259. 100|
  260. 99|
  261. ....
  262. 9|#
  263. 8|#
  264. ...
  265. 0+-----
  266. all.
  267. """
  268. nr_len = len(str(max(integers)))
  269. upper = f"{' ' * nr_len}+{'-' * len(integers)}+"
  270. lower = f"{' ' * (nr_len - 1)}0+{'-' * len(integers)}+"
  271. fill = [f"{' ' * (nr_len - 1)}{i}|{' ' * len(integers)}|" if i <= 9 else f"{' ' * (nr_len - 2)}{i}|{' ' * len(integers)}|" for i in range(1, max(integers) + 1)]
  272. fill.reverse()
  273. # upper = f" +{'-' * len(integers)}+"
  274. # lower = f"0+{'-' * len(integers)}+"
  275. # fill = [f"{i}|{' ' * len(integers)}|" for i in range(1, max(integers) + 1)]
  276. # fill.reverse()
  277. lines = ""
  278. if not fill:
  279. lines = f"1|{' ' * len(integers)}|" + "\n"
  280. for n in range(len(integers)):
  281. for l in range(len(fill)):
  282. if help_func2(fill[l]) <= integers[n]:
  283. length = len(str(help_func2(fill[l])))
  284. fill[l] = fill[l][:n + 1 + length] + "#" + fill[l][n + 2 + length:]
  285. # line[n + 2].replace("#", line[n + 2])
  286. for line in fill:
  287. lines += line + "\n"
  288. table = upper + "\n" + lines + lower
  289. return table
  290. # upper = f" +{'-' * len(integers)}+"
  291. # lower = f"0+{'-' * len(integers)}+"
  292. # fill = [f"{i}|{' ' * len(integers)}|" for i in range(1, max(integers) + 1)]
  293. # fill.reverse()
  294. # lines = ""
  295. # if not fill:
  296. # lines = f"1|{' ' * len(integers)}|" + "\n"
  297. # for n in range(len(integers)):
  298. # for l in range(len(fill)):
  299. # if int(fill[l][0]) <= integers[n]:
  300. # fill[l] = fill[l][:n + 2] + "#" + fill[l][n + 3:]
  301. # # line[n + 2].replace("#", line[n + 2])
  302. # for line in fill:
  303. # lines += line + "\n"
  304. # table = upper + "\n" + lines + lower
  305. # return table
  306.  
  307.  
  308. def help_func2(line):
  309. """Help."""
  310. return int([n for n in re.findall(r"\d+", line)][0])
  311.  
  312. # 08 - OOP1 - transport
  313.  
  314.  
  315. class Passenger:
  316. """Class that defines passenger object."""
  317.  
  318. def __init__(self, first_name: str, age: int):
  319. """
  320. Initialize passenger.
  321.  
  322. self.is_validated - when passenger arrives to the vehicle, they should validate themselves.
  323. If the passenger doesn't do that and inspector arrives, the passenger will be kicked out from the vehicle.
  324. self.vehicle - describes vehicle, where passenger is at the moment.
  325.  
  326. One passenger can't be on multiple vehicles at the same time.
  327.  
  328. :param first_name: Passenger's first name.
  329. :param age: Passenger's age.
  330.  
  331. """
  332. self.first_name = first_name
  333. self.age = age
  334. self.is_validated = False
  335. self.vehicle = None
  336.  
  337. def validate(self):
  338. """Validate passenger."""
  339. self.is_validated = True
  340.  
  341.  
  342. class PublicTransportVehicle:
  343. """Class that defines public transport vehicle object."""
  344.  
  345. def __init__(self, seats: int):
  346. """
  347. Initialize vehicle.
  348.  
  349. :param seats: Amount of seats in the public transport vehicle. If the amount of seats is smaller than 0, then it should be determined that there is 1 seat in the vehicle.
  350. Vehicle driver does not need a seat.
  351. """
  352. self.seats = seats
  353. self.passengers = []
  354. if self.seats <= 0:
  355. self.seats = 1
  356.  
  357. def get_amount_of_people(self) -> int:
  358. """
  359. Return amount of people in the bus including the vehicle driver.
  360.  
  361. Assume that driver is always in the vehicle.
  362.  
  363. :return: Amount of people as integer.
  364. """
  365. return len(self.passengers) + 1
  366.  
  367. def get_all_passengers(self) -> List:
  368. """
  369. Return the list of passengers.
  370.  
  371. :return: Passengers as list.
  372. """
  373. return self.passengers
  374.  
  375. def add_new_passenger(self, passenger: Passenger) -> bool:
  376. """
  377. Register new passenger if there is a seat for him/her.
  378.  
  379. :return: True if passenger can be added, otherwise (if not enough seats or passenger is already there) False.
  380. """
  381. if len(self.passengers) < self.seats and passenger not in self.passengers:
  382. self.passengers.append(passenger)
  383. return True
  384. return False
  385.  
  386. def release_passenger(self, passenger: Passenger):
  387. """Release passenger (passenger leaves the vehicle)."""
  388. self.passengers.remove(passenger) if passenger in self.passengers else None
  389.  
  390. def inspector_arrival(self):
  391. """All passengers, who are not validated, will be kicked out from vehicle."""
  392. self.passengers = [p for p in self.passengers if p.is_validated]
  393.  
  394.  
  395. # 09 - OOP2 - village
  396.  
  397.  
  398. class Building:
  399. """Represents one building."""
  400.  
  401. def __init__(self, name: str, resources: dict):
  402. """Initialize building."""
  403. self.name = name
  404. self.resources = resources
  405. self.level = 1
  406.  
  407. def upgrade(self):
  408. """Upgrade building."""
  409. self.level += 1
  410.  
  411. def downgrade(self):
  412. """Downgrade building."""
  413. self.level -= 1
  414.  
  415. def get_name(self):
  416. """Return building name."""
  417. return self.name
  418.  
  419. def get_level(self):
  420. """Return building level."""
  421. return self.level
  422.  
  423. def __repr__(self):
  424. """Representation of Building."""
  425. return f"{self.name} ({self.level})"
  426.  
  427.  
  428. class Village:
  429. """Represents village."""
  430.  
  431. def __init__(self, name: str, resources: dict):
  432. """Constructor."""
  433. self.name = name
  434. self.resources = resources
  435. self.buildings = [Building("Main building", {"Wood": 200, "Clay": 200, "Iron": 200, "Wheat": 200})]
  436.  
  437. def can_build(self, resources_needed: dict):
  438. """True if can build building, else False."""
  439. if self.resources["Wood"] - resources_needed["Wood"] >= 0 and self.resources["Clay"] - \
  440. resources_needed["Clay"] >= 0 and self.resources["Iron"] - \
  441. resources_needed["Iron"] >= 0 and self.resources["Wheat"] - resources_needed["Wheat"] >= 0:
  442. return True
  443. return False
  444.  
  445. def build_building(self, resources_needed: dict, name: str) -> bool:
  446. """
  447. Build building.
  448.  
  449. You can build a building if there is room for a new building in the village and you have enough resources.
  450. There can't be multiple buildings with the same name and name can't be empty.
  451.  
  452. If you can build the building, build it and add it the buildings list.
  453.  
  454. Return True if building was successful, else False.
  455.  
  456. :param resources_needed: Resources needed for building the building.
  457. :param name: Name of the building to be built.
  458. :return: True if building was successful, else False.
  459. """
  460. if len(self.buildings) <= 20 and self.can_build(resources_needed):
  461. self.buildings.append(Building(name, resources_needed))
  462. self.resources["Wood"] -= resources_needed["Wood"]
  463. self.resources["Clay"] -= resources_needed["Clay"]
  464. self.resources["Iron"] -= resources_needed["Iron"]
  465. self.resources["Wheat"] -= resources_needed["Wheat"]
  466. return True
  467. return False
  468.  
  469. def downgrade_building(self, building_name: str) -> bool:
  470. """
  471. Downgrade building.
  472.  
  473. Building can be downgraded if it's in the village. If the building's level is 1 and it is being downgraded,
  474. demolish it (remove completely from village).
  475. If it's the Main Building, its level can't be lower than 1.
  476.  
  477. Return True if downgrading was successful, else False.
  478.  
  479. :param building_name: Name of the building to be downgraded.
  480. :return: True if downgrading was successful, else False.
  481. """
  482. if self.get_building_by_name(building_name):
  483. building = self.get_building_by_name(building_name)
  484. if building_name.lower() != "main building" and building.level == 1:
  485. self.buildings.remove(building)
  486. elif building_name.lower() == "main building" and building.level == 1:
  487. return False
  488. else:
  489. building.downgrade()
  490. return False
  491.  
  492. def can_upgrade(self, building):
  493. """Returns True if can upgrade building, else False."""
  494. if self.resources["Wood"] - ((10 + (building.level + 1) * 4) % building.resources["Wood"]) >= 0 and \
  495. self.resources["Clay"] - ((10 + (building.level + 1) * 4) % building.resources["Clay"]) >= 0 and \
  496. self.resources["Iron"] - ((10 + (building.level + 1) * 4) % building.resources["Iron"]) >= 0 and \
  497. self.resources["Wheat"] - ((10 + (building.level + 1) * 4) % building.resources["Wheat"]) >= 0:
  498. return True
  499. return False
  500.  
  501. def upgrade_building(self, building_name: str) -> bool:
  502. """
  503. Upgrade building.
  504.  
  505. Building can be upgraded if its level is not equal to them Main Building's level less than 20
  506. and there is enough resources in the village for the upgrade.
  507.  
  508. Return True if upgrading was successful, else False.
  509.  
  510. :param building_name: Name of the building to be upgraded.
  511. # :param resources_needed: Resources needed for the upgrade.
  512. :return: True if upgrading was successful, else False.
  513. """
  514. # (10 + level * 4)% ehitise algsest maksumusest
  515. if self.get_building_by_name(building_name):
  516. building = self.get_building_by_name(building_name)
  517. main_building = self.get_building_by_name("Main building")
  518. if self.can_upgrade(building) and building.level <= 19 and \
  519. (building.level + 1 > main_building.level or building == main_building):
  520. self.resources["Wood"] -= (10 + (building.level + 1) * 4) % building.resources["Wood"]
  521. self.resources["Clay"] -= (10 + (building.level + 1) * 4) % building.resources["Clay"]
  522. self.resources["Iron"] -= (10 + (building.level + 1) * 4) % building.resources["Iron"]
  523. self.resources["Wheat"] -= (10 + (building.level + 1) * 4) % building.resources["Wheat"]
  524. building.upgrade()
  525. return False
  526.  
  527. def get_building_by_name(self, name: str) -> Building:
  528. """Return Building object corresponding to the given name. If no such building, return None."""
  529. b_names = [b.name.lower() for b in self.buildings]
  530. if name.lower() in b_names:
  531. for b in self.buildings:
  532. if b.name.lower() == name.lower():
  533. return b
  534. return None
  535.  
  536. def get_resources(self) -> dict: # ?
  537. """Return the dict of resources."""
  538. return self.resources
  539.  
  540. def add_resources(self, resources_to_add: dict):
  541. """Add resources to the resource dict."""
  542. self.resources["Wood"] += resources_to_add["Wood"]
  543. self.resources["Clay"] += resources_to_add["Clay"]
  544. self.resources["Iron"] += resources_to_add["Iron"]
  545. self.resources["Wheat"] += resources_to_add["Wheat"]
  546.  
  547. def get_buildings(self) -> list:
  548. """Return buildings."""
  549. return self.buildings
  550.  
  551. def __repr__(self) -> str:
  552. """Village representation."""
  553. return f"Village: {self.name}, Buildings: {self.buildings}"
  554.  
  555.  
  556. def group_the_minions(group_sizes: List[int]) -> List[List[int]]:
  557. """
  558. You have to split minions into different groups.
  559.  
  560. #10
  561.  
  562. Each minion belongs to one certain group.
  563. You are given an array of numbers, which represents the size of the group in which the Minion belongs to.
  564. Put the minions into the right sized group. The order of groups (lists inside lists) does not matter.
  565.  
  566. Example:
  567. group_the_minions([3,3,3,3,3,1,3]) -> [[5],[0,1,2],[3,4,6]]
  568. and this would also be correct as order does not matter -> [[0,1,2],[3,4,6], [5]]
  569.  
  570. group_the_minions([2, 2]) -> [[0, 1]].
  571. """
  572. final_list = []
  573. for i in range(len(group_sizes)):
  574. if not final_list:
  575. final_list.append([i])
  576. else:
  577. for f in final_list:
  578. if len(f) < group_sizes[i]:
  579. f.append(i)
  580. if help_func(final_list, i):
  581. final_list.append([i])
  582. return final_list
  583.  
  584.  
  585. def help_func(listy, i):
  586. """Help func."""
  587. for l in listy:
  588. if i in l:
  589. return False
  590. return True
  591.  
  592.  
  593. if __name__ == "__main__":
  594. # print(sum_nums(1, 2)) # -> [3, '12']
  595. # print(sum_nums(12, 34)) # -> [46, '1234']
  596. # print(sum_nums(33, 44)) # -> [77, '3344']
  597. # print(sum_nums(0, 0)) # -> [0, '00']
  598. # print(numbers_in_list(3, 5, [5, 6, 3, 1])) # -> 8
  599. # print(numbers_in_list(0, 2, [3, 2, 9])) # -> 2
  600. # print(numbers_in_list(0, 2, [3, 0, 9])) # -> -2
  601. # print(numbers_in_list(3, 6, [5, 9, 8])) # -> 18
  602. # print(numbers_in_list(9, 9, [0, 6, 32])) # -> 0
  603. # print(multiply_after_digit('a5b4c')) # -> 'abbbbbcccc'
  604. # print(multiply_after_digit('2 0nhe2lo world3!')) # -> ' hello world!!!'
  605. # print(multiply_after_digit('thi10s end3s wit3h 31')) # -> 'thissssssssss endsss withhh '(to get 100 %)
  606. # print(mastermind_guess([1, 2, 3], [1, 2, 3])) # = > [2, 2, 2]
  607. # print(mastermind_guess([1, 2, 3], [3, 1, 2])) # = > [1, 1, 1]
  608. # print(mastermind_guess([1, 2, 3], [3, 3, 3])) # = > [1, 1, 2]
  609. # print(mastermind_guess([1, 2], [7, 3])) # = > [0, 0]
  610. # print(reformat_money({10: 'A', 20: 'B', 30: 'a', 40: 'A', 50: 'James'})) # => {'A': 50, 'B': 20, 'a': 30,
  611. # 'James': 100}
  612. # print(collatz_conjecture(12)) # -> 9, 16(sequence is [12, 6, 3, 10, 5, 16, 8, 4, 2, 1], steps - 9, biggestterm -
  613. # # 16)
  614. # print(collatz_conjecture(1)) # -> 0, 1(sequence is [1], steps - 0, biggestterm - 1)
  615. # print(collatz_conjecture(27)) # -> 111, 9232
  616. # print(collatz_conjecture(670617279)) # -> 949,
  617. # 966616035460(closetotheborderofRecursionError, butshould stillwork)
  618. # print(collatz_conjecture(0)) # -> None
  619. print(plot_the_tangerines([1, 0, 2, 3, 4, 5, 4, 3, 2, 10, 0, 3, 2, 1])) # = >
  620. # +--------------+
  621. # 5| # |
  622. # 4| ### |
  623. # 3| ##### # |
  624. # 2| ####### ## |
  625. # 1|# ######## ###|
  626. # 0+--------------+
  627.  
  628. print(plot_the_tangerines([0])) # = >
  629. # +-+
  630. # 1+ +
  631. # 0+-+
  632.  
  633. print(plot_the_tangerines([0, 0, 0, 0, 0, 0])) # = >
  634. # +------+
  635. # 1| |
  636. # 0+------+
  637.  
  638. print(plot_the_tangerines([1, 4, 5, 3, 1])) # = >
  639. # +-----+
  640. # 5| # |
  641. # 4| ## |
  642. # 3| ### |
  643. # 2| ### |
  644. # 1|#####|
  645. # 0+-----+
  646. print(group_the_minions([3, 3, 3, 3, 3, 1, 3])) # -> [[5],[0,1,2],[3,4,6]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement