Tags: algorithms 

Rating:

```
#!/usr/bin/env python3
import re
from pwn import *

if __name__ == '__main__':
nc = remote('travelling-salesman.hsctf.com', 1337)

while True:
string = nc.recvline()
if b"flag{" in string:
print("[+]Here is your flag:", string.decode("utf-8"))
exit(0)
if b"order:" not in string:
# print("[Debug]String= ",string)
string += nc.recvuntil(b"order: ")
string = string.decode("utf-8")

#extract only the list of classrooms
string = re.findall(r"\[(.*)\]", string, re.DOTALL)[0]

#sort the list of classrooms
list = [ int(x) for x in string.split(',')]
print("[!]Classrooms: ", list)
list = sorted(list)
print("[+]Classrooms sorted=",list,"\n[!]Sending...")
sorted_class = ' '.join([str(x) for x in list])

#send the sorted list
nc.sendline(bytes(sorted_class,"utf-8"))
print("[+]Done")
```