Last active
April 22, 2017 22:39
-
-
Save pwnall1337/9534aaa43442ae5026b826ab52706563 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Time to code it: 50 minutes, raw only builtin core python modules used. | |
| pwnall@pwnall-desktop:~$ python fbtest.py | |
| Tyrannosaurus Rex | |
| Velociraptor | |
| Struthiomimus | |
| Hadrosaurus | |
| pwnall@pwnall-desktop:~$ cat fbtest.py | |
| #!/usr/bin/env python | |
| def open_file(fd): | |
| with open(fd, 'r') as f: | |
| lines=f.read().split('\n') | |
| d=[s for s in lines if len(s) > 2] | |
| rows=[] | |
| for line in d: | |
| if not line.startswith('NAME'): | |
| s=line.split(',') | |
| s=[d.lstrip() for d in s] | |
| rows.append(s) | |
| return rows | |
| def speed(stride, leg): | |
| g=9.8 | |
| equation=((stride / leg) -1) * ((leg * g)**.5) | |
| return equation | |
| data1=open_file('data1.csv') | |
| data2=open_file('data2.csv') | |
| def compare(data1, data2): | |
| dinos=[] | |
| for s in data1: | |
| sname,leg,diet=s | |
| leg=float(leg) | |
| for d in data2: | |
| dname,stride,stance=d | |
| stride=float(stride) | |
| if sname==dname and 'bipedal' in stance: | |
| dino_dat=(sname,int(speed(stride,leg))) | |
| dinos.append(dino_dat) | |
| return dinos | |
| raw_list=compare(data1, data2) | |
| sorted_list=sorted(raw_list,key=lambda x:x[1], reverse=True) | |
| for dino,speed in sorted_list: | |
| print dino | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment