<div style="line-height:18px;background-color:#1e1e1e;"> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ce9178;">'''</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ce9178;">ecrypt.py</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ce9178;">'''</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ce9178;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"> <div><font color="#ffffff">동기 : 오유에서 파이썬을 C로 바꿔달라는 글을 보고 하게 되었습니다. 파이썬으로만 작성해봤습니다.</font></div> <div><font color="#ffffff">목적 : 주어진 영어문장에서 알파벳의 순서를 3칸씩 뒤로 가게 만들어 주게 하는 프로그램</font></div><font color="#d4d4d4"></font></div><font color="#d4d4d4" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></font> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff">ALPHABET = [</font><span style="color:#ce9178;">'a'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'b'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'c'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'d'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'e'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'f'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'g'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'h'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'i'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'j'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'k'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'l'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'m'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'n'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'o'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'p'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'q'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'r'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'s'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'t'</span><font color="#d4d4d4">, </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ce9178;">'u'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'v'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'w'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'x'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'y'</span><font color="#d4d4d4">, </font><span style="color:#ce9178;">'z'</span><font color="#ffffff">]</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><br></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff">아래는 처음 생각 </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#608b4e;"># len(A) = 26 #</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#608b4e;"># list boundary is from 0 to 26 #</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#608b4e;"># We want to make 'abc' -> 'xyz'</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#608b4e;"># 012 -> 24 25 26 <=> -3 -2 -1</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#608b4e;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ffffff;">먼저, 목표설정을 하고 구상을 했습니다. </span><span style="font-size:9pt;color:#ffffff;">그에 따라 </span><span style="font-size:9pt;color:#ffffff;">알고 있는 것이 무엇인지 파악했습니다.</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ffffff;font-size:9pt;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ffffff;font-size:9pt;">사실)알파벳은 26개이고, 파이썬의 list에서 양의 나머지는 그에 대응하는 음의 나머지와 같습니다. </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff" style="font-size:9pt;">idea) 알파벳의 순서를 3칸을 뒤로 넘길 겁니다. 즉, </font><span style="font-size:9pt;color:#ffffff;">a는 x로, b는 y로, c는 z로 바꿔줄 겁니다. </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><br></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff">위키백과에 따르면 list는 순서가 정해진 값의 나열을 의미합니다. 순서가 있기 때문에 list에 순서를 입력해주면 그 순서에 해당하는 값이 출력됩니다.</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff">그런데, 자연수만 입력할 수 있는 게 아니라 음의 정수도 입력할 수 있습니다. 파이썬에서 list의 색인은 음의 나머지와 똑같습니다. </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff">쉽게 예를 들자면, 사탕 42개를 26명에게 똑같이 나눠줄 때 몇개가 남는지 생각해봅시다. 42개를 26명에게 나눠주면 1개씩 </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff">26개를 나눠주게 되므로 16</font><span style="color:#ffffff;font-size:9pt;">개가 남습니다. 이는 2개씩 나눠주려면(52명에게 1개씩) 10개가 부족함과 똑같습니다.</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;">즉, '42개를 26명에게 똑같이 나눠준다' = 42 / 26 = 26*1 + 16 = 26 + 26 - 26 + 16 = 26*2 - 10 </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;">이 내용을 list에 적용해봅시다.</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;">A = ['b', 'a', 'a', 'a', 'a', 'a'] 라는 list가 있습니다. 색인의 번호는 list의 길이가 6이니 6로 나눌 때의 나머지입니다.</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;">(나누는 수가 n이라면 </span><span style="color:#ffffff;font-size:9pt;">나머지는 항상 </span><span style="color:#ffffff;font-size:9pt;">0 ~ n - 1) </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;">0 1 2 3 4 5 => 'b' 'a' 'a' 'a' 'a' 'a' </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;">7로 나눠서 나머지가 1이 나왔습니다. 나머지가 1이니까 7 / 6 = 6 + 1 = 7 - 6 + 6 = 13 - 6 = 2*6 - 5 </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;">그러므로, </span><span style="color:#ffffff;font-size:9pt;"> A[0] = A[-6] = 'a', </span><span style="color:#ffffff;font-size:9pt;">A[1] = A[-5] = 'b' </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></div><font color="#d4d4d4" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></font> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#569cd6;">def</span> <span style="color:#dcdcaa;">find_indexnumberencrypt</span>(<span style="color:#9cdcfe;">input_yourcode</span>):</div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"> <span style="color:#ce9178;">'''</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ce9178;"> encrypt 'abc' -> 'xyz'</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ce9178;"> '''</span></div><font color="#d4d4d4" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></font> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"> output_list = []</div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="white-space:pre;"> </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#d4d4d4;"> <span style="color:#c586c0;">for</span> </span><font color="#ffffff">INPUTS_ALPHABET</font><span style="color:#d4d4d4;"> <span style="color:#569cd6;">in</span> </span><font color="#ffffff">input_yourcode:</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#d4d4d4;"> <span style="color:#c586c0;">for</span> </span><font color="#ffffff">ALPHABET_INDEX</font><font color="#d4d4d4"> </font><span style="color:#569cd6;">in</span><font color="#d4d4d4"> </font><span style="color:#dcdcaa;">range</span><font color="#d4d4d4">(</font><span style="color:#dcdcaa;">len</span><font color="#ffffff">(ALPHABET)):</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#d4d4d4;"> <span style="color:#c586c0;">if</span> </span><font color="#ffffff">INPUTS_ALPHABET == ALPHABET[ALPHABET_INDEX]:</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> output_list.append(ALPHABET_INDEX)</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><br></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><span style="white-space:pre;"> </span>append는 '첨부하다'라는 뜻인데 output_list라는 list에 괄호 안의 데이터를 주어진 list에 넣어주도록 하는 명령어입니다.</font><span style="color:#ffffff;font-size:9pt;"> </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><span style="white-space:pre;"> </span>output_list에 주어진 알파벳의 순서를 넣어주려고 합니다. 'a' -> 0, 'b' -> 1 etc.</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><span style="white-space:pre;"> </span>그래서 append를 이용했습니다. 더 좋은 방법이 있다면 언제든지 적어주시면 감사하겠습니다!</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><br></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><span style="white-space:pre;"> </span>list에 1:'a' 같은 dictionary 형태의 데이터는 넣을 수 없습니다. </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ffffff;font-size:9pt;"> </span><span style="color:#ffffff;font-size:9pt;">tuple(순서쌍), int(정수), double(실수), list, set 형태의 자료는 넣을 수 있었습니다. </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><span style="white-space:pre;"> </span>혹여 빠진 게 있다면 덧글로 피드백 해주시면 감사하겠습니다. </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><br></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"> <span style="color:#c586c0;">break</span></div><font color="#d4d4d4" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></font> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#d4d4d4"> </font><font color="#ffffff">'''</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> for ALPHABET_INDEX in range(len(ALPHABET)):</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> for INPUTS_ALPHABET in input_yourcode:</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> if INPUTS_ALPHABET == ALPHABET[ALPHABET_INDEX]:</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> output_list.append(ALPHABET_INDEX)</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> 위 for이 처음에 했던 건데 이건 예상했던 결과와 다르게 출력을 했습니다. </font><font color="#ff0000">(위 for은 i)의 for입니다.)</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> ['a','a','b','a']라면 [0, 0, 1, 0]로 output_list가 나와야 하는데 [0,0,0,1]</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> 즉, 정렬(sort)을 시켜줬습니다.</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> 왜 그런가 IDLE를 돌려보았습니다. </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><br></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> 잘 확인이 안돼서 이렇게 바꿔서 했습니다. </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><br></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><span style="color:#ffffff;white-space:pre;"> </span><font color="#ffff00">for ALPHABET_INDEX in range(len(ALPHABET)):</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffff00"><span style="white-space:pre;"> </span>print(ALPHABET_INDEX)</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffff00"><span style="white-space:pre;"> </span>print("AAAAAAAAAAAAAAAAAA")</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffff00"><span style="white-space:pre;"> </span>for INPUTS_ALPHABET in input_yourcode:</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffff00"><span style="white-space:pre;"> </span>print(INPUTS_ALPHABET)</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffff00"><span style="white-space:pre;"> </span>print("HIHIHIHIHIHIHIHI")</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffff00"><span style="white-space:pre;"> </span>if INPUTS_ALPHABET == ALPHABET[ALPHABET_INDEX]:</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffff00"><span style="white-space:pre;"> </span>output_list.append(ALPHABET_INDEX)</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;line-height:18px;"> <div><font color="#ffff00"><span style="white-space:pre;"> </span>print(output_list)</font></div> <div><font color="#ffff00"><span style="white-space:pre;"> </span>print("CCCCCCCCCCCCCCCCCCCCCCC")</font></div> <div><font color="#ffffff"> </font></div></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> i) 위 for을 돌렸을 때 </font><span style="font-size:9pt;"><font color="#ffffff">( 넣은 값 input_yourcode = ['a','b','a','a'])</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><br></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> --> 다음과 같은 결과가 나왔습니다. ( 결과 :</font><span style="color:#ffffff;font-size:9pt;">['a','b','a','a'] --> [0,0,0,1] )</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> 0</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffffff"> AAAAAAAAAAAAAAAAAA</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;line-height:18px;"> <div><font color="#ffffff"> a</font></div> <div><font color="#ffffff"> HIHIHIHIHIHIHIHI</font></div> <div><font color="#ffffff"> [0]</font></div> <div><font color="#ffffff"> CCCCCCCCCCCCCCCCCCCCCCC</font></div> <div><font color="#ffffff"> b</font></div> <div><font color="#ffffff"> HIHIHIHIHIHIHIHI</font></div> <div><font color="#ffffff"> a</font></div> <div><font color="#ffffff"> HIHIHIHIHIHIHIHI</font></div> <div><font color="#ffffff"> [0, 0]</font></div> <div><font color="#ffffff"> CCCCCCCCCCCCCCCCCCCCCCC</font></div> <div><font color="#ffffff"> 1</font></div> <div><font color="#ffffff"> AAAAAAAAAAAAAAAAAA</font></div> <div><font color="#ffffff"> a</font></div> <div><font color="#ffffff"> HIHIHIHIHIHIHIHI</font></div> <div><font color="#ffffff"> b</font></div> <div><font color="#ffffff"> HIHIHIHIHIHIHIHI</font></div></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><span style="font-size:9pt;"> [0, 0, 1]</span><span style="font-size:9pt;"> </span></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></div><font color="#d4d4d4" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></font> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ce9178;"> </span><font color="#ffffff"> ii)</font><span style="color:#ce9178;"> </span><span style="color:#c586c0;font-size:9pt;">for</span><span style="color:#d4d4d4;font-size:9pt;"> </span><span style="font-size:9pt;"><font color="#ffffff">INPUTS_ALPHABET</font></span><span style="color:#d4d4d4;font-size:9pt;"> </span><span style="color:#569cd6;font-size:9pt;">in</span><span style="font-size:9pt;"><font color="#ffffff"> input_yourcode:를 돌린 결과 ( 넣은 값 input_yourcode = ['a','b','a','a'])</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><br></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> </font><font color="#ffffff" style="font-size:9pt;">--> 다음과 같은 결과가 나왔습니다. ( 결과 : </font><span style="font-size:9pt;color:#ffffff;">['a','b','a','a'] --> [0,1,0,0] )</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#d4d4d4;font-size:9pt;"> a</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;line-height:18px;"> <div> AAAAAAAAAAAAAAAAAA</div> <div> <span style="color:#b5cea8;">0</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> [<span style="color:#b5cea8;">0</span>]</div> <div> CCCCCCCCCCCCCCCCCCCCCCC</div> <div> <span style="color:#b5cea8;">1</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">2</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">3</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">4</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">5</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">6</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">7</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">8</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">9</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">10</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">11</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">12</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">13</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">14</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">15</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">16</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">17</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">18</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">19</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">20</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">21</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">22</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">23</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">24</span></div> <div> HIHIHIHIHIHIHIHI</div> <div> <span style="color:#b5cea8;">25</span></div> <div> HIHIHIHIHIHIHIHI</div></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ce9178;"> </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#ce9178;"> </span><font color="#ffffff">iii)비교했더니 <span style="font-size:9pt;">다음과 같은 결론이 나왔습니다. </span></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffffff"><span style="white-space:pre;"> </span>i)는 a부터 z까지 문자의 개수를 먼저 세준다. 왜냐하면 주어진 list를 a로 훑고 나서 그 다음 문자로 훑기 때문입니다.</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffffff"><span style="white-space:pre;"> </span>ii)는 예상한 결과를 도출했습니다. ii)의 'for'이 우리가 넣은 첫번째 문자를 a부터 z까지 비교하고, 다음 문자로 넘어가는 것이었습니다. </font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="font-size:9pt;"><font color="#ffffff"><span style="white-space:pre;"> </span>(이 생각은 MATLAB에서 list끼리 </font></span><span style="color:#ffffff;font-size:9pt;">boolean을 이용해서 </span><span style="color:#ffffff;font-size:9pt;">똑같은지 다른지 비교할 수 있다는 점에서 착안했습니다.)</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#ce9178;"> </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ce9178"> iv)<font size="3"> i</font></font><span style="color:#c586c0;"><font size="3">f</font></span><font color="#ffffff"><span style="font-size:9pt;">뒤에 </span><span style="font-size:9pt;">break를 추가했습니다. 굳이 불필요한 연산을 하고 싶지 않았습니다. </span></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"> </div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><span style="white-space:pre;"> </span>그렇게 ['a','b','a','a']를 [0,1,0,0]로 바꾸는데 성공했습니다. </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"><span style="white-space:pre;"> </span>이제 [0,1,0,0]을 이용해서 'aaba'(python에서 string을 list처럼 생각할 수 있습니다.)를 'xxyx'로 바꿔야 합니다. </font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"> </div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#d4d4d4;"> </span><font color="#ffffff"> output_string = </font><span style="color:#ce9178;">''</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><br></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="white-space:pre;"><font color="#ffffff"><span style="white-space:pre;"> </span>'a'에서 'x'를 도출하고, 'b'에서 'y'를 도출한 결과물을 더해야 합니다. 붙여주려면.</font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="white-space:pre;"><font color="#ffffff"><span style="white-space:pre;"> </span>계산하기 전에는 아무 것도 없도록 설정해줬습니다. </font></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><br></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#d4d4d4;"> <span style="color:#c586c0;">for</span> </span><font color="#ffffff">component_of_list</font><font color="#d4d4d4"> </font><span style="color:#569cd6;">in</span><font color="#d4d4d4"> </font><font color="#ffffff">output_list:</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#d4d4d4;"> </span><font color="#ffffff"> output_string += ALPHABET[component_of_list - </font><span style="color:#b5cea8;">3</span><font color="#ffffff">]</font><font color="#d4d4d4"> </font><span style="color:#608b4e;"># A[0] = 'a' -> A[24 == -3] = 'x'</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#608b4e;"> <font size="3">여기는 각 알파벳을 뒤로 3칸을 보내고 하나의 문자열로 만들어주는 과정입니다.</font> </span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#608b4e;font-size:9pt;"><span style="white-space:pre;"> </span># ['a', 'x', 'u'] -> 'x'+'u'+'r' -> 'xur'</span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><font color="#ffffff"> output = output_string</font></div><font color="#d4d4d4" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="white-space:pre;"> </span></font><span style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#608b4e;font-size:medium;">우리가 더한 문자열을 출력값으로 해줍니다.</span><font color="#d4d4d4" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></font> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#d4d4d4;"> <span style="color:#c586c0;">return</span> </span><font color="#ffffff">output</font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><span style="color:#608b4e;font-size:medium;"><span style="white-space:pre;"> </span>출력값을 함숫값으로 설정해줍니다.</span><font color="#ffffff"><span style="white-space:pre;"> </span></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><br></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"> <div style="color:#000000;font-family:'굴림';white-space:normal;"><font color="#ffffff" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></font></div> <div style="color:#000000;font-family:'굴림';white-space:normal;"><font color="#ffffff" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;">결과 : 'whereareyou' -> '</font><font color="#ffffff" face="Menlo, Monaco, Courier New, monospace"><span style="white-space:pre;">tebobxobvlr'</span></font></div> <div><font color="#ffffff" face="Menlo, Monaco, Courier New, monospace"><span style="white-space:pre;"><br></span></font></div></div> <div><font face="Menlo, Monaco, Courier New, monospace" color="#ffffff"><span style="white-space:pre;">>>> encrypt.find_indexnumberencrypt('where are you?!')</span></font></div> <div><font face="Menlo, Monaco, Courier New, monospace" color="#ffffff"><span style="white-space:pre;">'tebobxobvlr'</span></font></div> <div><font face="Menlo, Monaco, Courier New, monospace" color="#ffffff"><span style="white-space:pre;"><br></span></font></div> <div><font color="#ffffff" face="Menlo, Monaco, Courier New, monospace" size="4"><span style="white-space:pre;">부족한 점: 띄어쓰기를 반영해야 함 & '?'나 '!' 같은 문장부호도 그대로 넣도록 해야 함. </span></font></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#608b4e;"><br></span></div> <div style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;color:#d4d4d4;"><span style="color:#608b4e;"><br></span></div><font color="#d4d4d4" style="font-family:Menlo, Monaco, 'Courier New', monospace;white-space:pre;"><br></font></div>