Skip to content

Instantly share code, notes, and snippets.

@tbates
Created September 27, 2012 21:51
Show Gist options
  • Save tbates/3796663 to your computer and use it in GitHub Desktop.
Save tbates/3796663 to your computer and use it in GitHub Desktop.
Turned coins
n = 1000;
coins = rep(0, n)
for (i in 2:n) {
whatToFlip = seq(from = i, to = n, by = i)
coins[whatToFlip] = coins[whatToFlip] + 1
}
sqrt(which(!as.logical(coins%%2)))
# [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment