From b2b7d6d85356b4953a14ab20abc9007e158fd22b Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 9 Feb 2020 21:30:58 +0100 Subject: [PATCH] Add python script to plot numbers --- plot-numbers.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 plot-numbers.py diff --git a/plot-numbers.py b/plot-numbers.py new file mode 100644 index 0000000..e9982e2 --- /dev/null +++ b/plot-numbers.py @@ -0,0 +1,37 @@ +import matplotlib.pyplot as plt + + +def all_the_same(digits) -> bool: + first = digits[0] + for dig in digits: + if dig != first: + return False + return True + + +with open('./rotatable.txt', 'r') as file: + numbers = [int(num.strip('\n')) for num in file.readlines()] + numbers.sort() + x = [] + y = [] + rem_three = {0: 0, 1: 0, 2: 0} + for i in numbers: + i_dig = list(str(i)) + if not all_the_same(i_dig): + print(i % 3) + last = i_dig.pop() + i_dig.insert(0, last) + #x.append(i%3) + rem_three[i%3] += 1 + x.append(int(''.join(i_dig))) + y.append(i) + fix, axs = plt.subplots(1, 2) + print(x, y) + axs[0].scatter(x, y) + axs[0].set(xlabel='right rotation', ylabel='number') + axs[0].set_title('Numbers and their right rotation') + axs[0].grid() + axs[1].bar([0, 1, 2], [rem_three[0], rem_three[1], rem_three[2]]) + axs[1].set(xlabel='num % 3', ylabel='count') + axs[1].set_title('Remainder of the number and 3') + plt.show() \ No newline at end of file