
    Mg                         S SK r S SKrS SKrS SKJr  S SKJrJrJr  \" S5      \" SS9\" S5       " S S	5      5       5       5       rg)
    N)Fore)aliaspluginrequirezproject eulerT)networkeulerc                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
Euler
   z
Gives acces to problems from https://www.projecteuler.net via jarvis
Usage: type 'euler' or 'project euler' and select the desired menu item.
c                     SU l         g )Nzhttps://www.projecteuler.net)project_url)selfs    C/Users/admin/workspace/ai/Jarvis/jarviscli/plugins/project_euler.py__init__Euler.__init__   s
    9    c                    Xl         U R                  5       U l        U R                   R                  S[        R
                  5        U R                   R                  S[        R
                  5        U R                   R                  S5        U R                   R                  S5        U R                   R                  S5        U R                   R                  S5        U R                   R                  S5        U R                   R                  S5        U R                   R                  S	[        S
SS9nUS
:X  a<  U R                   R                  S[        S
U R                  S9nU R                  U5        g US:X  a3  [        R                  " S
U R                  5      nU R                  U5        g US:X  a  U R                  5         g g )Nz#Welcome to the ProjectEuler plugin!z#----------------------------------- zPlease select an option below:z1) Get the problem by numberz2) Get random problemz3) Infoz4) ExitzYour choice:       )rtyperminrmaxz"Please, enter the desired number:       )jarvisget_last_problem_idlast_problem_idsayr   GREENinput_numberintget_problem_by_numberrandomrandint	show_info)r   r   schoiceproblem_numbers        r   __call__Euler.__call__   sM     $779=tzzJ=tzzJ8967/0	"	"))/1ST)UQ;![[556Z<?;<;?;O;O 6 QN &&~6q[#^^At/C/CDN&&~6q[NN r   c                    U R                   S-   [        U5      -   n [        R                  " U5      n[        R                  " UR                  S5      nUR                  SSS9nUR                  S5      R                  5       nS[        U5      -   S	-   U-   nU R
                  R                  S
5        U R
                  R                  U[        R                  5        UR                  SSS9nUR                  5       n	U	R                  5       n	Sn
U
[!        U	5      S-
  :  a1  X   S
:X  a  X   XS-      :X  a  X	 OU
S-  n
U
[!        U	5      S-
  :  a  M1  U	S   S
:w  a  U	R#                  SS
5        U	[!        U	5      S-
     S
:w  a  U	R#                  [!        U	5      S
5        SnUR%                  U	5      nU R
                  R                  U5        U R
                  R                  S[        R                  5        U R
                  R                  U5        g ! [         a-    U R
                  R                  S[        R                  5         g f = f)Nz	/problem=zCan't get info from site, exithtml.parserdivcontentidh2zProblem z. r   problem_content)class_r   r   
zVIf it seems to you that text is not displayed correctly you can follow the link below.)r   strrequestsgetConnectionErrorr   r   r   REDbs4BeautifulSoupr/   findget_textr    
splitlinesleninsertjoin)r   numberurlpagesoupr/   problem_headerheader_to_showproblem_div
dirty_textisepproblem_texts                r   r#   Euler.get_problem_by_number6   s    ,s6{:	<<$D   }= ))Ei)0 !d+446#c&k1D8>I

3 ll51BlC ))+
  **,
#j/A%%}"z}
q58I'IMQ	 #j/A%% a=Ba$c*o)*b0c*or2 xx
+ 	%prvr|r|}]  	KKOO<dhhG	s   H 4IIc                    U R                   R                  S5        U R                   R                  SU R                  -   [        R                  5        U R                   R                  S5        SnUS-  nUS-  nUS-  nUS[        U R                  5      -   S-   -  nUS	-  nUS
-  nU R                   R                  U5        U R                   R                  S5        g )Nr   z	Website: z_Project Euler (named after Leonhard Euler) is a website dedicated to a series of computational z7problems intended to be solved with computer programs. z]The project attracts adults and students interested in mathematics and computer programming. zjSince its creation in 2001 by Colin Hughes, Project Euler has gained notability and popularity worldwide. zIt now includes z; problems. A new one is added once every one or two weeks. znProblems are of varying difficulty, but each is solvable in less than a minute of CPU time using an efficient z*algorithm on a modestly powered computer. )r   r   r   r   r    r6   r   )r   	info_texts     r   r&   Euler.show_infol   s    d&6&66

Cu	NN	tt	  B  	B	'#d.B.B*CCIJ 	J	  F  	F	AA		"r   c                 *   U R                   S-   n[        R                  " U5      n[        R                  " UR
                  S5      nUR                  SSS9nUR                  S5      S   n[        UR                  S5      R                  5       5      nU$ )	Nz/recentr-   tableproblems_tabler0   trr   td)
r   r7   r8   r;   r<   r/   r=   find_allr"   r>   )r   rD   rE   rF   problem_tablelast_problem_rowr   s          r   r   Euler.get_last_problem_id}   s     *||C   }= 		'.>	? )11$7: .33D9BBDEr   )r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r*   r#   r&   r   __static_attributes__ r   r   r
   r
   
   s"    
:@4l" r   r
   )	r$   r;   r7   coloramar   r   r   r   r
   ra   r   r   <module>rc      sQ     
   ) ) B  B    B r   