Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
18
Task/Population-count/R/population-count.r
Normal file
18
Task/Population-count/R/population-count.r
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
library(bit64)
|
||||
popCount <- function(x) sum(as.numeric(strsplit(as.bitstring(as.integer64(x)), "")[[1]]))
|
||||
finder <- function()
|
||||
{
|
||||
odious <- evil <- integer(0)
|
||||
x <- odiousLength <- evilLength <- 0
|
||||
while(evilLength + odiousLength != 60)#We could be smarter, but this condition suffices.
|
||||
{
|
||||
if(popCount(x) %% 2 == 0) evil[evilLength + 1] <- x else odious[odiousLength + 1] <- x
|
||||
x <- x + 1
|
||||
evilLength <- length(evil)
|
||||
odiousLength <- length(odious)
|
||||
}
|
||||
cat("The pop count of the 1st 30 powers of 3 are:", sapply(3^(0:29), popCount), "\n")
|
||||
cat("The first 30 evil numbers are:", evil, "\n")
|
||||
cat("The first 30 odious numbers are:", odious)
|
||||
}
|
||||
finder()
|
||||
Loading…
Add table
Add a link
Reference in a new issue