Skip to content

Instantly share code, notes, and snippets.

View cpfiffer's full-sized avatar
🤙
LOVING IT

Cameron Pfiffer cpfiffer

🤙
LOVING IT
View GitHub Profile
# Misc functions for conservation biology stats in R.
shannon <- function (x) {
proportion_x = x/sum(x)
print(proportion_x)
print(log(proportion_x))
print(proportion_x * log(proportion_x))
print(sum(proportion_x * log(proportion_x)))
return(-sum(proportion_x*log(proportion_x)))
}
@cpfiffer
cpfiffer / integer_chain.jl
Created July 31, 2017 19:30
This is a Julia implementation to solve the Riddler Classic problem this week, whereby you have to make the longest chain of integers according to some rules.
# Cameron Pfiffer
# July 31st, 2017
# Julia Does Numbers 2: The Mathening
# See the link below for information about the challenge.
# https://fivethirtyeight.com/features/pick-a-number-any-number/
#=
From Itay Bavly, a chain-link number problem:
@cpfiffer
cpfiffer / candle_blows.r
Created January 17, 2017 09:07
Solves for the birthday candle riddle at FiveThirtyEight
#The riddle can be found at https://fivethirtyeight.com/features/how-long-will-it-take-to-blow-out-the-birthday-candles/
tests = 10000000
blows <- rep(0,tests)
i = 1
while (i <=tests) {
candles = 30
while (candles > 0) {