Skip to content

Instantly share code, notes, and snippets.

@daknuett
Last active June 14, 2018 16:45
Show Gist options
  • Select an option

  • Save daknuett/ecffc0d9899e588a4ec20484ae048472 to your computer and use it in GitHub Desktop.

Select an option

Save daknuett/ecffc0d9899e588a4ec20484ae048472 to your computer and use it in GitHub Desktop.
Makes everything ok, optional by using a neuronal network.
#!/usr/bin/python3
#
# Copyright(c) 2017 Daniel Knüttel
#
# This script is free software.
# Anyways if you think this script is worth it
# and we meet shout a drink for me.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Dieses Programm ist Freie Software: Sie können es unter den Bedingungen
# der GNU Affero General Public License, wie von der Free Software Foundation,
# Version 3 der Lizenz oder (nach Ihrer Wahl) jeder neueren
# veröffentlichten Version, weiterverbreiten und/oder modifizieren.
#
# Dieses Programm wird in der Hoffnung, dass es nützlich sein wird, aber
# OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
# Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
# Siehe die GNU Affero General Public License für weitere Details.
#
# Sie sollten eine Kopie der GNU Affero General Public License zusammen mit diesem
# Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
import shutil, math, sys, time, random
from collections import deque
"""
make_everything_ok:
makes everything ok by using the following techniques:
- Using a neuronal network (because neuronal networks are a fashion)
- Making you wait until the problem is solved [1]_
.. [1]: If you are dead all your problems are solved per definition.
Run using -n [<number of neurons>] for neuronal network mode.
"""
red = '\033[91m'
end = '\033[0m'
bold = '\033[1m'
italic = '\033[3m'
yellow = '\033[93m'
text_space = 26
def get_int(prompt):
i = None
while(i == None):
try:
i = int(input(prompt))
except:
pass
return i
class Neuron(object):
def __init__(self, value, id_, log_file_name):
self.children = []
self.value = value
self._id = id_
self.log_file_name = log_file_name
self.schedule = deque()
def add_child(self, child):
self.children.append(child)
def activate(self, value):
self.schedule.append(value)
def run_all(self):
while(len(self.schedule) > 0):
self.run_activate()
def run_activate(self):
value = self.schedule.popleft()
if(value > 0):
f = open(self.log_file_name, "a")
f.write("+Neuron[{}] activated: {}\n".format(self._id, value))
f.close()
for child in self.children:
child.activate(self.value + value - 3)
else:
f = open(self.log_file_name, "a")
f.write("-Neuron[{}] END\n".format(self._id))
f.close()
def print_load_bar(width, textspace, text, load_time, symbol = "#", symstart = "[" , symend = "]", color = None):
width_to_fill = (width - textspace) - len(symend) - len(symstart)
steps = width_to_fill // len(symbol)
time_to_wait = load_time / steps
print(" " * (textspace - 1), end = "")
print(symstart, end = "", flush = True)
print(" " * width_to_fill, end = "")
print(symend, end = "\r", flush = True)
print_pretext(textspace - 1 , text)
print(symstart, end = "", flush = True)
if(color != None):
print(color, end = "")
for i in range(steps):
print(symbol, end = "", flush = True)
time.sleep(time_to_wait)
if(color != None):
print(end)
else:
print()
def print_pretext(width_for_text, text, color = None):
if(color != None):
print(color, end = "")
if(len(text) < width_for_text):
print(text + ":" + " " * (width_for_text - 1 - len(text)), end = "")
elif(len(text) == width_for_text):
print(text, end = "")
else:
print(text[:width_for_text], end = "")
if( __name__ == "__main__"):
width, height = shutil.get_terminal_size()
use_neurons = False
problem = input("Enter your Problem > ")
args = sys.argv
neurons = 20
if(len(args) > 1 and args[1] in ("-n", "--neuronal", "-neuronal-network")):
open("neurons.log", "w").close()
if(len(args) > 2):
try:
neurons = abs(int(args[2]))
except:
pass
neurons = [Neuron(i - (neurons // 2) - 1, i, "neurons.log") for i in range(neurons)]
print_load_bar(width, text_space, "Creating Neurons", len(neurons) // 10)
for no, neuron in enumerate(neurons):
print_load_bar(width, text_space, "Setting up Neuron #{}".format(no), 0.5)
if(no < len(neurons) // 2):
neuron.add_child(neurons[-1 * no])
if(no % 2 == 0):
for i in range(1, len(neurons) // 2, 2):
neuron.add_child(neurons[i])
else:
for i in range(0, len(neurons) // 2, 2):
neuron.add_child(neurons[i])
use_neurons = True
print_load_bar(width, text_space, "Processing Input", len(problem))
print_load_bar(width, text_space, "Calculating Solution", len(problem))
if(use_neurons):
print_load_bar(width, text_space, "Running Neuronal Network", len(problem))
neurons[-1].activate(len(problem))
one_clear_run = False
while(not one_clear_run):
this_run_is_clear = True
for neuron in neurons:
if(len(neuron.schedule) != 0):
this_run_is_clear = False
neuron.run_all()
if(this_run_is_clear):
one_clear_run = True
print_load_bar(width, text_space, "Testing Environment", random.randint(1, 10))
print("Running Submodule mtwabp: Making the world a better place")
print_load_bar(width, text_space, "Progress", 10, color = yellow)
print_load_bar(width, text_space, "Making everything OK", len(problem), color = red)
print("\n")
print(red + bold + "Everything should be OK now." + end)
print("\n")
if(input("Is everything OK now? ") in ("N", "n", "no", "No", "nein", "Nein")):
age = get_int("Please enter your Age > ")
persistance = get_int("Please enter the number of days the problem persisted > ")
print_load_bar(width, text_space, "Calculating Errors", min(persistance, 10) + 1)
print("Your Description was not sufficient.")
to_live = (120 - age) * 365
to_live *= 24 * 60 * 60
chrs = to_live / 3
wrds = chrs / 4
print("Use a longer description.")
print(int(wrds), "Words should be sufficient to calculate the solution properly")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment