Random Fun :)

HOW TO BREAK A TYPING TEST :P

Behold! The speed we all dream of achieving on typingtest.org:


You too can join the fun and challenge this record speed, and all you need is the AHK language (download free here: http://ahkscript.org/ ), or some sendkeys program (available in most programming languages). Here is the AHK script for Aesop's Fables (between the stars):
********************************************************************************************************

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
^l::
    send, Aesop was one of the great Greek writers. He is best known for his fables, stories that have a moral. They teach us something about how we should live our lives. Aesop wrote thousands of these stories. Here are a few.{ENTER}The Wolf in Sheep's Clothing{ENTER}Once upon a time, a Wolf decided to disguise the way he looked. He thought it would help him get food more easily. He put on the skin of a sheep, then he went out with the flock into the pasture. Even the shepherd was fooled by his clever costume. In the evening, the shepherd put him in with the rest of the sheep. He closed the gate and made sure it was secure before he went to bed. In the middle of the night, he came back to the fold to get some meat for the next day. Instead of a sheep, though, he grabbed the Wolf, killing him instantly.{ENTER}Those who look to harm others will be harmed themselves.{ENTER}The Bat and the Weasel{ENTER}A Bat fell on the ground and was caught by a Weasel. It begged the Weasel to spare its life, but the Weasel refused. It told the Bat that birds, by nature, were its enemy. The Bat assured him that it was not a bird, it was a mouse. The Weasel thought a moment, then set it free. A while later, the Bat fell again to the ground, and it was caught by another Weasel. It begged this Weasel not to eat him, either. The Weasel, though, said it did not like mice at all and would eat it. The Bat told the Weasel that it was not a mouse, but a bat. The second Weasel had no good answer, so he let it go.{ENTER}The Bat knew it is always wise to turn events to your advantage.{ENTER}The Lion and the Mouse{ENTER}A sleeping Lion was woken up by a Mouse running over his face. He got up angrily and caught the scared little Mouse. He was about to kill the Mouse, but it said in its squeaky little voice, "If you would only spare my life, I would be sure to repay your kindness." The Lion laughed at such nonsense, but he let him go. A short time later, though, the Lion was caught by some hunters. They bound him by ropes to the ground. The Mouse recognized his roar, and he rushed over and gnawed the rope with his teeth, setting the Lion free. The Mouse said "You laughed at the idea of my ever being able to help you. Now you know that it is possible for even a small little Mouse to help a great big Lion."

*******************************************************************************************************

.GIF IN MATLAB!

So, I was bored. And found you can make .gif files in MATLAB.  I used the roots of unity for x^6+1 to draw the Star of David (click on the image to see the animation):
Here is the code I used (admittedly not very pretty, since I switched the point indices from the default output), modified from here https://www.mathworks.com/matlabcentral/answers/94495-how-can-i-create-animated-gif-images-in-matlab:

x = 0:0.01:1;

figure(1)

filename = 'stardavid.gif';

rootsunity2 = solve('x^6+1')
rootsunity(7) = rootsunity2(6);
rootsunity(8) = rootsunity2(5);
rootsunity(1) = rootsunity2(6);
rootsunity(2) = rootsunity2(5);
rootsunity(3) = rootsunity2(1);
rootsunity(4) = rootsunity2(3);
rootsunity(5) = rootsunity2(4);
rootsunity(6) = rootsunity2(2);


for n = 1:6

      plot([rootsunity(n), rootsunity(n+2)], '-o'); hold on

      drawnow

      frame = getframe(1);

      im = frame2im(frame);

      [imind,cm] = rgb2ind(im,256);

      if n == 1;

          imwrite(imind,cm,filename,'gif', 'Loopcount',inf);

      else

          imwrite(imind,cm,filename,'gif','WriteMode','append');

      end

end




Click inside the box below and press enter to play a game of Lord of the Rings hangman! (Coded by yours truly) 
The Hangman Code!
Feel free to use it on your own website via trinket or adapt it to tkinter (though I would appreciate a reference to www.learnchess.info) Note: the word list is different than the executed code above to prevent spoilers ;)

def setup():
        thestart = input("--> Please press enter to begin a new game.\n")
        print(("""Welcome to LOTR hangman! You can guess an individual letter or the entire word/phrase.\nIf frustrated, use "give up" to see the answer :)""" + "\n"))
        import random
        import re
       
thewords = ["lower", "case", "words", "go", "here" ]
        word = random.choice(thewords)
        count = 0
        finalword = word             
        scarred = re.sub("[a-z]", "-", word)
        print(("""""" + scarred + "\n"))
        print(("""______\n|\n|\n|\n|\n|\n|________""" + "\n"))
        while True:
            let = re.compile("\A(?P<letter>.{1})\Z")
            wor = re.compile("(?P<stuff>..+)")
            giveup = re.compile("give up")
            yourguess = input("Your guess:\n")
            le = let.search(yourguess)
            wo = wor.search(yourguess)
            gu = giveup.search(yourguess)
            if gu:
                print("Answer: " + finalword.upper() + "\n")
                setup()
            if wo:
               try:
                  a = str(wo.group('stuff'))
                  if finalword == a:
                     print(("""""" + a.upper() + "\n"))
                     done = """You got the word(s); thanks for playing!"""
                     print((done + "\n"))
                     setup()
                  else:
                     print(("""Incorrect!""" + "\n"))
                     count = count + 1
                     print(("""wrong count: """ + str(count) + "\n"))
                     if count == 1:
                        print(("""______\n|....|\n|\n|\n|\n|\n|________""" + "\n"))
                     if count == 2:
                        print(("""______\n|....|\n|....O\n|\n|\n|\n|________""" + "\n"))
                     if count == 3:
                        print(("""______\n|....|\n|....O\n|....| \n|\n|\n|________""" + "\n"))
                     if count == 4:
                        print(("""______\n|....|\n|....O\n|...\|\n|\n| \n|________""" + "\n"))
                     if count == 5:
                        print(("""______\n|....|\n|....O\n|...\|/\n|\n| \n|________""" + "\n"))
                     if count == 6:
                        print(("""______\n|....|\n|....O\n|...\|/\n|....|\n| \n|________""" + "\n"))
                     if count == 7:
                        print(("""______\n|....|\n|....O\n|...\|/\n|....|\n|.../  \n|________""" + "\n"))
                     if count == 8:
                        print(("""______\n|....|\n|....O\n|...\|/\n|....|\n|.../ \ \n|________\nYou're HUNG! (But can keep on playing if you like)""" + "\n"))
               except UnboundLocalError:
                  pass
            if le:
               try:
                  a = le.group('letter')
                  if 'a' in a:
                     word = re.sub("a", "A", word)
                     display = re.sub("[^ aA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'b' in a:
                     word = re.sub("b", "B", word)
                     display = re.sub("[^ bA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'c' in a:
                     word = re.sub("c", "C", word)
                     display = re.sub("[^ cA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'd' in a:
                     word = re.sub("d", "D", word)
                     display = re.sub("[^ dA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'e' in a:
                     word = re.sub("e", "E", word)
                     display = re.sub("[^ eA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'f' in a:
                     word = re.sub("f", "F", word)
                     display = re.sub("[^ fA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'g' in a:
                     word = re.sub("g", "G", word)
                     display = re.sub("[^ gA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'h' in a:
                     word = re.sub("h", "H", word)
                     display = re.sub("[^ hA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'i' in a:
                     word = re.sub("i", "I", word)
                     display = re.sub("[^ iA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'j' in a:
                     word = re.sub("j", "J", word)
                     display = re.sub("[^ jA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'k' in a:
                     word = re.sub("k", "K", word)
                     display = re.sub("[^ kA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'l' in a:
                     word = re.sub("l", "L", word)
                     display = re.sub("[^ lA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'm' in a:
                     word = re.sub("m", "M", word)
                     display = re.sub("[^ mA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'n' in a:
                     word = re.sub("n", "N", word)
                     display = re.sub("[^ nA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'o' in a:
                     word = re.sub("o", "O", word)
                     display = re.sub("[^ oA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'p' in a:
                     word = re.sub("p", "P", word)
                     display = re.sub("[^ pA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'q' in a:
                     word = re.sub("q", "Q", word)
                     display = re.sub("[^ qA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'r' in a:
                     word = re.sub("r", "R", word)
                     display = re.sub("[^ rA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 's' in a:
                     word = re.sub("s", "S", word)
                     display = re.sub("[^ sA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 't' in a:
                     word = re.sub("t", "T", word)
                     display = re.sub("[^ tA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'u' in a:
                     word = re.sub("u", "U", word)
                     display = re.sub("[^ uA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'v' in a:
                     word = re.sub("v", "V", word)
                     display = re.sub("[^ vA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'w' in a:
                     word = re.sub("w", "W", word)
                     display = re.sub("[^ wA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'x' in a:
                     word = re.sub("x", "X", word)
                     display = re.sub("[^ xA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'y' in a:
                     word = re.sub("y", "Y", word)
                     display = re.sub("[^ yA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if 'z' in a:
                     word = re.sub("z", "Z", word)
                     display = re.sub("[^ zA-Z0-9]", "-", word)
                     print(("""""" + display + "\n"))
                  if finalword.upper() == display:
                     a = """You got the word(s); thanks for playing!"""
                     count = count - 1
                     print((a + "\n"))
                     setup()
                 
                  if a not in finalword:
                     count = count + 1
                     print(("""wrong count: """ + str(count) + "\n"))
                     if count == 1:
                        print(("""______\n|....|\n|\n|\n|\n|\n|________""" + "\n"))
                     if count == 2:
                        print(("""______\n|....|\n|....O\n|\n|\n|\n|________""" + "\n"))
                     if count == 3:
                        print(("""______\n|....|\n|....O\n|....| \n|\n|\n|________""" + "\n"))
                     if count == 4:
                        print(("""______\n|....|\n|....O\n|...\|\n|\n| \n|________""" + "\n"))
                     if count == 5:
                        print(("""______\n|....|\n|....O\n|...\|/\n|\n| \n|________""" + "\n"))
                     if count == 6:
                        print(("""______\n|....|\n|....O\n|...\|/\n|....|\n| \n|________""" + "\n"))
                     if count == 7:
                        print(("""______\n|....|\n|....O\n|...\|/\n|....|\n|.../  \n|________""" + "\n"))
                     if count == 8:
                        print(("""______\n|....|\n|....O\n|...\|/\n|....|\n|.../ \ \n|________\nYou're HUNG! (But can keep on playing if you like)""" + "\n"))

               except UnboundLocalError:
                  pass
while True:
    setup()

Comments