Main Loops and listeners in live coding systems

My question is about the construction of main loops running in the background listening to commands and signals and how are they constructed to be efficient. For instance in live music synthesis programming languages like SuperCollider or PureData, you have somewhere a sound server waiting for changes in your source code and applying changes immediately to your program. Are these things like simple while loops running for ever, waiting for updates in the environments. Running a simple while loop in python will consume more than half of the CPU, so this can surely be not done. Can any one give me some hints?

Coding practices related to logic within function calls and conditional statements

I recently started working as a programmer and I am currently going through some codes (in C#) written by my colleagues. I have noticed that they tend to include logic within function calls within some conditional statements. For example:

if (MoveSpace(currentPos, distance * time)) { doSomething } 

They would also include logic when determining array positions. For example:

Space currentSpace = array[a*b, x*y] 

Is this a good/bad practice? Would it be better if I create a new variable for these logic results and pass in the variable instead? Thank you.

How do I construct a NTM that accepts the language consisting of the coding of turing machines that halt on one input?

I currently have a problem with the following question:

L is a language consisting of the coding of turing machines , that each have an input w they halt on in at least |w|^3 steps. I need to construct a NTM (Non-deterministic turing machine) that decides L.

My idea was to simulate every possible input <= |w|^3 on a given turing machine M, by using a separate band in my NTM for every single input word. If there is one band where M halts, then the NTM accepts.

Is this the right way to go about it? My problem is, that I don’t see why I would need a NTM to decide L, a standard turing machine would be able to do the same thing.

Full Website coding, Script modifications, Screen scrapping and Bots – PHP/MYSQL

[​IMG]

Looking for someone that can do it all? Create, manage, update and give tactical business advice?

Story

A decade ago I started developing websites, now – 10 years later this is more than a passion, it has turned into a full blown business. After 100s of happy customers, their…

Full Website coding, Script modifications, Screen scrapping and Bots – PHP/MYSQL

Create a URL to post data to google sheets WITHOUT WEB CODING

I am totally new to coding and web and Java, HTML, and everything so if the answer exists please redirect me, otherwise pleas help!

I am using a digital signage software with Google Form and spreadsheets and it used to work just fine. But Google is updating and now some features are not working anymore so I need something new that does work and keeps working.

I need a URL that when i click a button in my digital signage (it is a touchscreen (windows OS)) that it sends data to a Google Spreadsheet (there is an option in the software where I can input a URL). But I have no access to any website so I cannot use any coding. I have watched hundreds of video’s and read a thousand forms but nothing comes close to what I need.

The data that needs to be sent: A row with the time that the button was pressed,a preset name and a preset number and a text box (where they can write names and stuff).

To answer a few question I can imagine you have:

  • No I do not have access to a website and I never will. (the company won’t give away login codes or pay me for a second website only for coding)
  • No I have absolutely no coding experience so any pre-written code would be greatly appreciated!
  • The DS software is http://www.digitalsignage.com
  • The only tools i have available is google. You can do a lot with app script and google API, but still totally new so a video or pre-written step by step, or pre-written code highly recommended!

Any questions more than welcome as well as answers!

Should I be using the numpy library or should I be coding the algorithm from scratch without using numpy?

Im currently trying to learn how k means clustering works. And there is a numpy function numpy.linalg.norm(x-y) that is used to find the Euclidean distance between two points. I was wondering if i should be using that or should i be writing a function to calculate the Euclidean distance myself?

How do I use more coding techniques to shorten my text game code

I recently started coding and after learning a bit about functions and basics I tried to make a simple text escape room game. My code is working and the game functions as intended but I now there are probably neat ways to reduce the long amount of code using techniques I haven’t yet heard about. I would really appreciate it if anyone could offer some improvements I could make.

room1 ="""There's a small, silent creature huddled in the corner chained to a pipe. It faces the wall and trembles vigorously. Around the room there are many sharp objects smeared in a thick, inky liquid. It stings to the touch. You want to leave as soon as possible. In the corner of the room there is a switch on the wall.\n The doors are in front of you and to the right.\n""" room2 ="""There is a body upon a table in the middle of the room, but it doesn't look like a human. It has huge black eyes and a strangely misshapen head. The skin is an ugly greyish colour and it's blood smells like perfume. The doors are behind you, right, and forwards.\n""" room3 ="""You open the door and the room is completely filled with water, or some kind of watery substance that somehow doesn't gush out when you open the door, seemingly encased by an invisible membrane. The only way to get to the other doors is to swim through the block of water. The liquid has a yellow-green tinge to it. The doors are behind you and to the right.\n\n""" room4 ="""The rancid smell of rotting flesh fills your nose as you glance around the concrete room. You see...nothing. Until you look up and notice the 7 corpses dangling from the roof. Instantly repulsed, you think nothing can be worse than this. The doors are left, right, and forward.\n""" room5 ="""The same room you woke up in. You wonder how you ended up in this nightmarish hell-house. The doors are on all sides.\n""" room6 ="""As you open the door there is an ominous choral humming. Apprehensively, you enter into a room circled by cloaked figures, rehearsing a bone chilling chant. The longer you listen, the more you want to leave. The doors behind you, to your left, and to your right.\n""" room7 ="""All this room is, is yellow hazard writing on the wall reading 'Room 7' You get the sense this one hasn't been finished yet. The doors are to your left and forwards.\n""" room8 ="""Pleasantly, you are surprised by a room seemingly out of a museum, with beautiful pieces of art lining each of the four walls, and classical music playing. Only, the art seems to be... bleeding. The doors are behind you, left, and forward.\n""" room9 ="""A large, levitating, purple ball sits in the center of the room. All light seemes to be swallowed up by it and it produces a low frequency sound that makes your bones shake within you. You try and approach it but it repels you like a magnet and leaves you skirting around it to get to the other doors. The doors are behind you and to your left.\n""" r1 ="""\n |[ ][ ][ ]| |[ ][ ][ ]| |[^][ ][ ]| """ r2 ="""\n |[ ][ ][ ]| |[^][ ][ ]| |[ ][ ][ ]| """ r3 ="""\n |[^][ ][ ]| |[ ][ ][ ]| |[ ][ ][ ]| """ r4 ="""\n |[ ][ ][ ]| |[ ][ ][ ]| |[ ][^][ ]| """ r5 ="""\n |[ ][ ][ ]| |[ ][^][ ]| |[ ][ ][ ]| """ r6 ="""\n |[ ][^][ ]| |[ ][ ][ ]| |[ ][ ][ ]| """ r7 ="""\n |[ ][ ][ ]| |[ ][ ][ ]| |[ ][ ][^]| """ r8 ="""\n |[ ][ ][ ]| |[ ][ ][^]| |[ ][ ][ ]| """ r9 ="""\n |[ ][ ][^]| |[ ][ ][ ]| |[ ][ ][ ]| """   #!/usr/bin/python3 import time import sys import random import pygame pygame.init() start_time=time.time()  def stutter(text):     for c in text:         print(c, end="")         sys.stdout.flush()         time.sleep(.02)  def end():     stutter("\n>>>>><<<<<\nYOU DIED\n>>>>><<<<<\n")     sound.load("/home/leo/Documents/Python/Sounds/lose.mp3")     sound.play()     time.sleep(6)     start()  def win():     global start_time     end_time=time.time()-start_time     m = end_time / 60     minutes = round(m,2)     stutter("\n---------------------------------------------------\n")     stutter("Well done! You escaped in only {} minutes!\n".format(minutes))     stutter("\nThank you for playing!")     def direction():     global x     global y     global key     global gloves     global intestines     global battery     global switch     global potion     global chance       prompt = input("\n\nChoose a direction using AWSD:\n")     if prompt == "a" or prompt == "A":         if (x-1) > 0 and (x-1) <= 3:             x -= 1         else:             stutter("You hit a wall")             sound.load("/home/leo/Documents/Python/Sounds/thud.mp3")             sound.play()             direction()     elif prompt == "w" or prompt == "W":         if (y+1) > 0 and (y+1) <= 3:             y += 1         else:             stutter("You hit a wall")             sound.load("/home/leo/Documents/Python/Sounds/thud.mp3")             sound.play()             direction()     elif prompt == "s" or prompt == "S":         if (y-1) > 0 and (y-1) <= 3:             y -= 1         else:             stutter("You hit a wall")             sound.load("/home/leo/Documents/Python/Sounds/thud.mp3")             sound.play()             direction()     elif prompt == "d" or prompt == "D":         if (x+1) > 0 and (x+1) <= 3:             x += 1         else:             stutter("You hit a wall")             sound.load("/home/leo/Documents/Python/Sounds/thud.mp3")             sound.play()             direction()     else:         print("That's not a valid input")         direction()      if x==1 and y==1:         sound.load("/home/leo/Documents/Python/Sounds/walking.mp3")         sound.play()         time.sleep(2)         sound.stop()         sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")         sound.play()         print(r1)         stutter(room1)         if switch == False:             stutter("The switch on the wall seems to be missing a battery.\n")             flick_switch = input("Flick the switch?(y or n):\n")             if flick_switch == "y" or flick_switch == "Y":                 if battery == True:                     stutter("""Hastily, not wanting to spend any more time with the unnerving creature in the corner, you insert the battery into the socket and flick the switch. A series of mechanical whirrings come from one of the other rooms.""")                     sound.load("/home/leo/Documents/Python/Sounds/metal_scrape.mp3")                     sound.play()                     time.sleep(2)                     switch = True                     sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")                     sound.play()                     direction()                 elif battery == False:                     stutter(""" The cowering creature in the corner, seeminly suddenly agitated, turns to see you flicking the switch that doesn't have a battery in. Its depressing face morphs in a flash into a terrify expression of anger, and, with sudden strength and a terrifying snarl, it rips it's restraints off and bounds towards you.""")                     sound.load("/home/leo/Documents/Python/Sounds/scream2.mp3")                     sound.play()                     stutter(""" It pounces on top of you, overpowering you, and digs its knife-like nails into your eyes.""")                     sound.play()                     stutter(""" At once, you are filled with instant regret knowing that the last thing you see will be the creatures disgusting face.""")                     end()             elif flick_switch == "n" or flick_switch == "N":                 stutter("You leave the switch for the time being.")                 direction()         elif switch  == True:             direction()       elif x==1 and y==2:         sound.load("/home/leo/Documents/Python/Sounds/walking.mp3")         sound.play()         time.sleep(2)         sound.stop()         print(r2)         sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")         sound.play()         stutter(room2)         if intestines == False:             stutter("""\nIt's strange, rope-like intestines lay on another table bordering the room.""")             take_intestines = input("\nTake the intestines?(y or n):\n")             if take_intestines == "y" or take_intestines == "Y":                 if gloves == True:                     stutter("Using the gloves, you pick up the intestines.\n")                     stutter("Intestines equipped.")                     sound.load("/home/leo/Documents/Python/Sounds/ding.mp3")                     sound.play()                     time.sleep(2)                     intestines = True                     sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")                     sound.play()                     direction()                 elif gloves == False:                     sound.load("/home/leo/Documents/Python/Sounds/scream1.mp3")                     sound.play()                     stutter(""" You try to take the intestines but as soon as you touch them, spasms run up and down your arm, then through your entire body.""")                     sound.play()                     stutter("""You begin frothing at the mouth as you feel the last dregs of life force swiftly exiting your body.""")                     end()             elif take_intestines == "n" or take_intestines == "N":                 stutter("""You decide to leave the intestines for now""")                 direction()         elif intestines == True:             direction()      elif x==1 and y==3:         sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")         sound.play()         stutter(room3)         stutter("""You notice one of the doors has the bright sign saying 'EXIT' above it.\n""")         swim = input("Swim through the liquid to the door?(y or n):\n")         if swim == "y" or swim == "Y":             if potion == True:                 sound.load("/home/leo/Documents/Python/Sounds/escape.mp3")                 sound.play()                 stutter("""The potion protecting you from the deadly toxicity, you swim through the thick, cold substance, inching closer to the door every stroke, hope fills your heart as you stand in front of the exit door and grasp the possibility of escape. One shove of the door, sees it swing open and reveal a wide expanse of forest. \nYou made it! You escaped! At least for now...""")                 win()             elif potion == False:                 sound.load("/home/leo/Documents/Python/Sounds/scream3.mp3")                 sound.play()                 stutter("""As soon as you make contact with the liquid your body begins to slowly disintegrate. Piece by piece, you break apart. You look down and see your insides tumbling out your stomach.""")                 sound.load("/home/leo/Documents/Python/Sounds/scream3.mp3")                 sound.play()                 stutter("""Your eyes bulge and your limps are ripped of by an invisible force and the bleak world slowly fades away..""")                 end()         elif swim == "n" or swim == "N":             stutter("You decide to avoid touching the substance for now.")             direction()          elif x==2 and y==1:         sound.load("/home/leo/Documents/Python/Sounds/walking.mp3")         sound.play()         time.sleep(2)         sound.stop()         sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")         sound.play()         print(r4)         stutter(room4)         if key == False:             stutter("\nThere is a key tucked inside one of the body's trouser pocket.\n")             take_key = input("Take the key?(y or n):\n")             if take_key == "y" or take_key == "Y":                 stutter("Key equipped.")                 sound.load("/home/leo/Documents/Python/Sounds/ding.mp3")                 sound.play()                 time.sleep(2)                 key = True                 sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")                 sound.play()                 direction()             elif take_key =="n" or take_key =="N":                 stutter("You didn't take the key.")                 sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")                 sound.play()                 direction()         elif key == True:             direction()      elif x==2 and y==2:         sound.load("/home/leo/Documents/Python/Sounds/walking.mp3")         sound.play()         time.sleep(2)         sound.stop()         sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")         sound.play()         print(r5)         stutter(room5)         direction()      elif x==2 and y==3:         sound.load("/home/leo/Documents/Python/Sounds/walking.mp3")         sound.play()         time.sleep(2)         sound.stop()         print(r6)         sound.load("/home/leo/Documents/Python/Sounds/scary_chant.mp3")         sound.play()         stutter(room6)         if gloves == False:             stutter("""\nThere is a small locked glass case in the middle of the room with a pair of silk gloves inside.\n""")             take_gloves = input("Take the gloves?(y or n):\n")             if take_gloves == "y" or take_gloves == "Y":                 if key == True:                     stutter("Using the key, you open the case and take the gloves.\n")                     sound.load("/home/leo/Documents/Python/Sounds/unlock.mp3")                     sound.play()                     time.sleep(3)                     stutter("Gloves equipped.")                     sound.load("/home/leo/Documents/Python/Sounds/ding.mp3")                     sound.play()                     time.sleep(2)                     gloves = True                     sound.load("/home/leo/Documents/Python/Sounds/scary_chant.mp3")                     sound.play()                     direction()                 elif key == False:                     stutter("The case is locked and you can't get the gloves.")                     direction()             elif take_gloves =="n" or take_gloves =="N":                 stutter("You didn't take the gloves.")                 direction()         elif gloves == True:             direction()      elif x==3 and y==1:         sound.load("/home/leo/Documents/Python/Sounds/walking.mp3")         sound.play()         time.sleep(2)         sound.stop()         sound.load("/home/leo/Documents/Python/Sounds/ambient.mp3")         sound.play()         if switch == False or potion == True:             print(r7)             stutter(room7)             direction()         elif switch == True:             print(r7)             stutter(room7)             time.sleep(2)             stutter("\nBut wait...\n")             time.sleep(2)             stutter("""Now a small hatch has opened up in the wall. You peek inside and a small volume of liquid sits in a glass flask. This must be what the switch opened. You read the label. 'The odds are even. Will you take the chance?' You ponder what this means as you sense an important decision approaching...""")             drink = input("\nWill you drink the potion?(y or n):\n")             if drink == "n" or drink == "N":                 stutter("You might come back to the potion later.")             elif drink == "y" or drink == "Y":                 sound.load("/home/leo/Documents/Python/Sounds/glug.mp3")                 sound.play()                 time.sleep(0.6)                 sound.play()                 time.sleep(0.6)                 sound.play()                 time.sleep(0.6)                 sound.play()                 time.sleep(0.6)                 sound.play()                 time.sleep(1)                 if chance == 0 or chance == 1:                     stutter("""You tip the potion back into your mouth. Nothing goes wrong so you assume it worked.""")                     stutter("\nPotion activated.")                     sound.load("/home/leo/Documents/Python/Sounds/item_consumption.mp3")                     sound.play()                     potion = True                     direction()                 elif chance == 2:                     sound.load("/home/leo/Documents/Python/Sounds/scream2.mp3")                     stutter("You gulp the liquid down. Oh no.")                     sound.play()                     stutter(""" You bones feel like they're being hammerred at from the inside. You run your hands through your hair and every strand is stripped of and falls on the floor.""")                     sound.play()                     stutter(""" It feels like all of your nails and toenails are ripped off one by one. You try and move, but full body paralysis seems to have overcome your body. 'Fuck'.""")                     sound.load("/home/leo/Documents/Python/Sounds/scream1.mp3")                     sound.play()                     stutter(""" You suffer one last wave of astronomical pain before swiftly leaving this plane of existance.""")                     end()        elif x==3 and y==2:         sound.load("/home/leo/Documents/Python/Sounds/walking.mp3")         sound.play()         time.sleep(2)         sound.stop()         print(r8)         sound.load("/home/leo/Documents/Python/Sounds/classical_music.mp3")         sound.play()         stutter(room8)         if battery == False:             stutter("""\nYou notice a faint light behind one of the paintings and so take the hanging art of the wall. It reveals a thin cylindrical hole in the wall too thin to fit through. You can see that there is something at the end but don't know what it is.\n""")             take_battery = input("Reach for the object?(y or n):\n")             if take_battery == "y" or take_battery == "Y":                 if intestines == True:                     stutter("""Using the ropey intesines, you form them into somewhat of a lasso shape and manage to fish out the the object. It is a battery.\n""")                     stutter("Battery equipped.")                     sound.load("/home/leo/Documents/Python/Sounds/ding.mp3")                     sound.play()                     battery = True                     time.sleep(2)                     sound.load("/home/leo/Documents/Python/Sounds/classical_music.mp3")                     sound.play()                     direction()                 elif intestines == False:                     stutter("The hole is to small to reach the object through.")                     direction()              elif take_battery == "n" or take_battery == "N":                 stutter("You didn't get the object.")                 direction()         elif battery == True:             direction()      elif x==3 and y==3:         sound.load("/home/leo/Documents/Python/Sounds/walking.mp3")         sound.play()         time.sleep(2)         sound.stop()         print(r9)         sound.load("/home/leo/Documents/Python/Sounds/low_hum.mp3")         sound.play()         stutter(room9)         touch = input("\nTouch the levitating ball?(y or n):\n")         if touch == "y" or touch == "Y":             sound.load("/home/leo/Documents/Python/Sounds/scream1.mp3")             sound.play()             time.sleep(2)             end()         elif touch =="n" or touch =="N":             print("Makes sense")             direction() def start():     global x     global y     global key     global gloves     global intestines     global battery     global switch     global potion     global chance     global sound     x=2     y=2     key = False     gloves = False     intestines = False     battery = False     switch = False     potion = False     chance = random.randint(0,2)     sound = pygame.mixer.music     sound.load("/home/leo/Documents/Python/Sounds/slow_music.mp3")     sound.play()      stutter("\n\n<<<<<<<<<<<<<<<<<<<<<<<<<< Escape Room >>>>>>>>>>>>>>>>>>>>>>>>>>\n")     time.sleep(3)     stutter("A game by Leo Gortzak\n")     time.sleep(5)     stutter("""\n\nYou awake in a dark room with a rusty iron door. There is a small circular window casting a dim light across the room. There are four doors leading out. One on each wall.\n""")     print(r5)     direction()  start()