formula

Prime Number Formula

人走茶凉 提交于 2019-12-28 06:27:48
问题 I am trying to write a prime number function in C# and I am wondering if the follow code will work. It "appears" to work with the first 50 numbers or so. I just want to make sure it will work no matter how big the number is: static bool IsPrime(int number) { if ((number == 2) || (number == 3) || (number == 5) || (number == 7) || (number == 9)) return true; if ((number % 2 != 0) && (number % 3 != 0) && (number % 5 != 0) && (number % 7 != 0) && (number % 9 != 0) && (number % 4 != 0) && (number

What does the capital letter “I” in R linear regression formula mean?

我与影子孤独终老i 提交于 2019-12-28 02:35:07
问题 I haven't been able to find an answer to this question, largely because googling anything with a standalone letter (like "I") causes issues. What does the "I" do in a model like this? data(rock) lm(area~I(peri - mean(peri)), data = rock) Considering that the following does NOT work: lm(area ~ (peri - mean(peri)), data = rock) and that this does work: rock$peri - mean(rock$peri) Any key words on how to research this myself would also be very helpful. 回答1: I isolates or insulates the contents

Base64 length calculation?

允我心安 提交于 2019-12-27 10:59:49
问题 After reading the base64 wiki ... I'm trying to figure out how's the formula working : Given a string with length of n , the base64 length will be Which is : 4*Math.Ceiling(((double)s.Length/3))) I already know that base64 length must be %4==0 to allow the decoder know what was the original text length. The max number of padding for a sequence can be = or == . wiki :The number of output bytes per input byte is approximately 4 / 3 (33% overhead) Question: How does the information above settle

Macro in Excel to Copy a Worksheet (by referencing every cell)

做~自己de王妃 提交于 2019-12-25 19:37:08
问题 I've found lots of examples for Copying Worksheets in VBA, or replacing formulas with values etc. What I want to do is copy an entire worksheet, but on the new worksheet, every cell refers back to its original. So in cell A1 of the new worksheet, it would simply have the formula "='Sheet1'!A1" Is there an easy way to do this? Thanks P.S. I need it to be a Macro, as I need to be able to run it on specific sheets, to copy all the cells from that sheet into a new one, not always from "Sheet1"

SUM of offset cells that contain a value

丶灬走出姿态 提交于 2019-12-25 17:44:35
问题 I'm trying to make a basic SUM of offsetted cells. Basically I have 4 columns, column A being just a title, column B being a counted number, and columns C and D referencing another value. The thing I'm trying to accomplish is the number count on column G. It should be a SUM of all of the values in column B IF that number appears in the reference columns An example would be that G2 would equal 15, since 1 appears in C2 (so it should add 7 from B2) and D3 (and add 8 from B3). I have the basic

Array returning #N/A for some elements, want blank

 ̄綄美尐妖づ 提交于 2019-12-25 13:15:24
问题 I am using the excel tools OFFSET and INDEX to import an array from a different sheet, into a workbook with room for 7 entries. The sheet that is being referenced has an ID number and the number could be listed several times for different entries. If you are not familiar with the offset function, the second to last input is how many rows you want returned in the array. The number I have here is a COUNTIF for how many times an ID appears. My code works, however because it is in an array format

R and factor coding in formula

廉价感情. 提交于 2019-12-25 08:19:52
问题 How do I use the formula interface if I want custom valued dummies, e.g. if I want values 1 and two, rather than 0 and 1. The estimation might look like the following where supp is a factor variable. fit <- lm(len ~ dose + supp, data = ToothGrowth) In this example, there is not much use of the different values, but in many cases of a "re-written" model it can be useful. EDIT: Actually, I have e.g. 3 levels, and want the two columns to be coded differently, so one is a 1/0 variable, and the

Why didn't the complement's formula work?

好久不见. 提交于 2019-12-25 04:42:43
问题 I have just learnt that to get the formula to find the 1st Complement is -x = 2^n - x - 1 I have managed to apply it on a binary case: -00001100 (base 2) = 2^8 - 12 - 1 = 243 = 11110011 (1s) However, when I try to apply the same formula to a base 5 number, -1042 (base 4) = 5^4 - 1042 - 1 = 625 - 1042 - 1 = - 400 (which is not the answer) Can some one help me out here? Thanks 回答1: you cannot calculate any formula with numbers in 2 different bases, you have to use their decimal representation

Excel formula to take string value from cell and sort its characters in alphabetical order

独自空忆成欢 提交于 2019-12-25 04:29:30
问题 Can you please help me to make Excel formula that takes string value from cell and sorts its characters in alphabetical order? Ex. original cell value: ' BACR ' sorted characters cell: ' ABCR ' 回答1: This UDF will sort numbers and Text character by character: Function sortletter(rng As Range) If rng.Count > 1 Then Exit Function Dim srtArr() As String Dim i&, j&, k& ReDim srtArr(1 To Len(rng)) srtArr(1) = Mid(rng, 1, 1) For i = 2 To UBound(srtArr) For j = 1 To UBound(srtArr) If srtArr(j) = ""

How do I handle empty number fields/variables in Crystal Reports?

青春壹個敷衍的年華 提交于 2019-12-25 03:26:08
问题 I have the following formula in my group footer, but am having problems with displaying 0 if sample_perc is empty; this value gets empty if #rt_sample_ordered is blank. NumberVar sample_perc := {#rt_sample_ordered}%{@sum_of_sample}; if (sample_perc>0)then sample_perc else 0 How do i print 0 when sample_perc is blank? 回答1: If Isnull({#rt_sample_ordered}) Or Isnull({@sum_of_sample}) Then 0 Else If ( {#rt_sample_ordered}%{@sum_of_sample} ) > 0 Then sample_perc Else 0 来源: https://stackoverflow