Last active
July 9, 2019 12:35
-
-
Save klashxx/e42afafddda9342c5204fd02f6af750f to your computer and use it in GitHub Desktop.
FB coding interview problem solved by awk
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
awk -F, 'FNR>1 && NR==FNR{a[$1]=$2+0;next} | |
FNR>1 && $3=="bipedal"{ | |
leg=a[$1]+0 | |
stride=$2+0 | |
speed=(leg==0 || stride == 0 ) ? 0 : ((stride / leg) - 1) * sqrt(leg * (9.8 ** 2)) | |
print $1, speed | |
} | |
' dataset1.csv dataset2.csv | sort -nr -k 2|awk '{print $1}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You will be supplied with two data files in CSV format.
Given the following formula,
speed = ((STRIDE_LENGTH / LEG_LENGTH) - 1) * SQRT(LEG_LENGTH * g) Where g = 9.8 m/s^2
(gravitational constant)` Write a program to read in the data files from disk, it must then print the names of only the bipedal dinosaurs from fastest to slowest. Do not print any other information.