CoddityTeam / movaicode

Concours mensuel du Pire Développeur de France
123 stars 10 forks source link

Python -- Reversing using rotation matrix #49

Closed Effey46 closed 2 years ago

Effey46 commented 3 years ago
#Requirements: numpy et matplotlib

import numpy as np
import matplotlib.pyplot as plt

#To learn more about rotation matrix, check out this video: https://www.youtube.com/watch?v=dQw4w9WgXcQ

def plot_progress(ZA_WARUDO,pause_time):
    x=[j[1][0] for j in ZA_WARUDO]
    y=[j[1][1] for j in ZA_WARUDO]
    lbl=[j[0] for j in ZA_WARUDO]
    plt.scatter(x,y,c='w')
    for p,v in enumerate(lbl):
        plt.annotate(v, (x[p], y[p]))
    plt.draw()
    plt.pause(pause_time)

string=input('please enter a string:\n')
string2=input('\nJust to be sure, please enter your string again:\n')
if string==string2:
    print("\nAlright, alright... Let's do this!")
    print("Just so you know the graphic display option is activated by default and is quite greedy when it comes to ressources.")
    print("Obviously it hasn't been optimised, who am I to optimise stuff, huh ? ")
    print("Oh and you cannot deactivate this option either, I'm way to lazy when to program these things.")
else:
    print("\nYou seem to be quite confused. Go take a quick nap and come back...")
    exit()

string_length=len(string)

if string_length%2==1:
    mid_length=int(string_length//2)
elif string_length%2==0:
    mid_length=int(string_length//2)
else:
    print('what a weird situation you are in...')
    exit()

plt.axis([-(mid_length)-0.5,mid_length+0.5,-(mid_length)-0.5,mid_length+0.5])

if mid_length>1:
    theta_list=np.linspace(0,180,2*mid_length**2,endpoint=True)
else:
    theta_list=np.linspace(0,180,10,endpoint=True)
increment_list=[np.radians(theta_list[i+1]-theta_list[i]) for i in range(len(theta_list)-1)]
pause_time=12/len(increment_list)

if string_length%2==1:
    ZA_WARUDO=[[v,np.array((i-mid_length,0))] for i,v in enumerate(string)]
else:
    ZA_WARUDO=[[v,np.array((i-mid_length+0.5,0))] for i,v in enumerate(string)]

plot_progress(ZA_WARUDO,pause_time)

for i in increment_list:
    magic_rotor=np.array(((np.cos(i),-np.sin(i)),(np.sin(i),np.cos(i))))
    ZA_WARUDO=[[j[0],magic_rotor.dot(j[1])] for j in ZA_WARUDO]
    plot_progress(ZA_WARUDO,pause_time)
plt.close()

if string_length%2==1:
    ODURAW_AZ=[[j[0],round(j[1][0]+mid_length)] for j in ZA_WARUDO]
else:
    ODURAW_AZ=[[j[0],round(j[1][0]+mid_length-0.5)] for j in ZA_WARUDO]

reversed_list=['-']*string_length

for i in ODURAW_AZ:
    reversed_list[int(i[1])]=i[0]

print('\nWell, well, well, seems like the reversed string you wanted is:')
print(''.join(reversed_list))
print("Just to be sure, you should try to reverse this string and see if it's the same as the one you gave me.")
print("You know, shits happen...")
eleissor commented 3 years ago

JOJO ?!

mehdi-dalil commented 3 years ago

Ho hooo...you're approaching me ?!

louismarslen commented 3 years ago

Cher @Effey46, j'ai le plaisir et l'honneur de vous annoncer que vous n'avez PAS gagné le concours MOVAI CODE. Ce qui fait de vous un EKSSELAN Codeur.

SPOILER : j'espère qu'on aura le plaisir de recevoir votre participation à l'episode 2 du MOVAI CODE (stay tuned).

Bravo toutefois pour votre belle contribution 😊

louismarslen commented 2 years ago

Je fais un peu de ménage dans les issues -> d'ailleurs go participer à l'édition 5