factors

Haskell sqrt type error

别说谁变了你拦得住时间么 提交于 2020-05-16 04:09:23
问题 OK, so I'm attempting to write a Haskell function which efficiently detects all the factors of a given Int . Based off of the solution given in this question, I've got the following: -- returns a list of the factors of n factors :: Int -> [Int] factors n = sort . nub $ fs where fs = foldr (++) [] [[m,n `div` m] | m <- [1..lim+1], n `mod` m == 0] lim = sqrt . fromIntegral $ n Sadly, GHCi informs me that there is No instance for (Floating Int) in the line containing lim = etc. etc. I've read

Haskell sqrt type error

一个人想着一个人 提交于 2020-05-16 04:04:46
问题 OK, so I'm attempting to write a Haskell function which efficiently detects all the factors of a given Int . Based off of the solution given in this question, I've got the following: -- returns a list of the factors of n factors :: Int -> [Int] factors n = sort . nub $ fs where fs = foldr (++) [] [[m,n `div` m] | m <- [1..lim+1], n `mod` m == 0] lim = sqrt . fromIntegral $ n Sadly, GHCi informs me that there is No instance for (Floating Int) in the line containing lim = etc. etc. I've read

Time limit excedeed error for large values

半腔热情 提交于 2020-04-07 08:01:13
问题 I have been given x and k , where x is the number of factors of a number A , and k is the number of prime factors of A . Given x and k , I have to find out whether such an A exists. For example: INPUT : 4 2 OUTPUT : 1 Since 6 is a number that has 4 factors 1, 2, 3, 6 out of which 2 are prime(2, 3). Also it is given that x and k can have any values between 1 and 10 9 . Here is my code for the this: long long int x, k; scanf("%lld%lld", &x, &k); int ans = 0; bool stop = false; for (long long

R: Why am I not getting type or class “factor” after converting columns to factor?

心已入冬 提交于 2020-01-23 13:37:28
问题 I have the following setup. df <- data.frame(aa = rnorm(1000), bb = rnorm(1000)) apply(df, 2, typeof) # aa bb #"double" "double" apply(df, 2, class) # aa bb #"numeric" "numeric" Then I try to convert one of the columns to "factor". But as you can see below, I am not getting any "factor" type or classes. Am I doing anything wrong ? df[, 1] <- as.factor(df[, 1]) apply(df, 2, typeof) # aa bb #"character" "character" apply(df, 2, class) # aa bb #"character" "character" 回答1: Sorry I felt my

R: Why am I not getting type or class “factor” after converting columns to factor?

眉间皱痕 提交于 2020-01-23 13:37:07
问题 I have the following setup. df <- data.frame(aa = rnorm(1000), bb = rnorm(1000)) apply(df, 2, typeof) # aa bb #"double" "double" apply(df, 2, class) # aa bb #"numeric" "numeric" Then I try to convert one of the columns to "factor". But as you can see below, I am not getting any "factor" type or classes. Am I doing anything wrong ? df[, 1] <- as.factor(df[, 1]) apply(df, 2, typeof) # aa bb #"character" "character" apply(df, 2, class) # aa bb #"character" "character" 回答1: Sorry I felt my

Replace values in column by factor level

旧巷老猫 提交于 2020-01-11 14:10:12
问题 I got a survey data.frame they are 100 columns and each columns have 2 factors - Yes or No. However some survey have answers like, Yes! or Nope or Yay or Nah... which really they are yes or no. My question is how can I achieve my converting all values in other columns based on their factor level? e.g if factor level is 1 replace text to Yes else No. My second question is, sometimes I am left with the 3rd level that isn't used, how can I remove all unused factors in ALL columns in data frame.

Replace values in column by factor level

拈花ヽ惹草 提交于 2020-01-11 14:09:05
问题 I got a survey data.frame they are 100 columns and each columns have 2 factors - Yes or No. However some survey have answers like, Yes! or Nope or Yay or Nah... which really they are yes or no. My question is how can I achieve my converting all values in other columns based on their factor level? e.g if factor level is 1 replace text to Yes else No. My second question is, sometimes I am left with the 3rd level that isn't used, how can I remove all unused factors in ALL columns in data frame.