Skip to content

Instantly share code, notes, and snippets.

@bearloga
Created June 5, 2015 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bearloga/2037bafecc8fe6dbf304 to your computer and use it in GitHub Desktop.
Save bearloga/2037bafecc8fe6dbf304 to your computer and use it in GitHub Desktop.
To answer the question "Does time saved by swimming better make up for time spent panickedly taking off pants?" (https://twitter.com/R0mination/status/606874583283597312)
d <- 20
time_pants <- 15 # seconds
# Average human swimming speed: 2 miles per hour
speed_avg <- birk::conv_unit(2, "mph", "m_per_sec") # install.packages('birk')
perc <- seq(0.25, 0.95, 0.01)
speed_slow <- speed_avg * perc
plot(perc * 100, (d / speed_slow)/60, type = "l", las = 1, lwd = 2,
xlab = "Speed in pants as % of average speed (2 mph ~ 0.89 m/s). In other words, how much the pants slow you down.",
ylab = sprintf("Minutes spent swimming %.f meters", d),
main = "Taking pants off before rescuing a drowning person vs not (taking pants off)",
xaxt = "n")
axis(1, at = seq(25, 95, 5), labels = sprintf("%.f%%", seq(25, 95, 5)))
time_in_pants <- (d / speed_avg)/60 + time_pants/60
x <- perc[which.min(abs((d / speed_slow)/60 - time_in_pants))] * 100
polygon(c(10, x, x, 10), c(0, 0, 100, 100), col = "#FF000044", border = NA)
polygon(c(100, x, x, 100), c(0, 0, 100, 100), col = "#0000FF44", border = NA)
text(53, 1, "Take Pants Off", col = "red") # x and y coords need to be manually input
text(67, 1, "Keep Pants On", col = "blue") # # x and y coords need to be manually input
abline(h = (d / speed_avg)/60, lty = "dotted", lwd = 2)
abline(h = (d / speed_avg)/60 + time_pants/60, lty = "dashed", lwd = 2)
legend("topright", c("At 0.89 m/s", "At 0.89 m/s + initial 15 second investment of taking pants off", "% of 0.89 m/s"),
lty = c("dotted", "dashed", "solid"), bty = "n", lwd = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment