i am new here and i need some help with my simple code if it possible
in visual prolog i want check the number in 4 cases
-1 , negative odd
1 , positive odd
-2 , negative even
2 , positive even
i try this one
Predicates
Print.
Clauses
Print:- write ("enter number "),nl, readint(X),
X>0,X mod 2= 0,write("positive ","even"),
X<0,X mod 2= 0,write("negative ","even") ,
X>0,X mod 2 <> 0,write("positive ","odd"),
X<0,X mod 2 <> 0,write("negative ","odd") .
Goal
Print.
any idea to help me with this problem
Related
I am trying to calculate different price decreases when each statement is true for example
Statement 1 - Y
Statement 2 - N
Statement 3 - N
Statement 4 - N
I have been able to get it to work with one of the statements being true using
=IF(EXACT(L9,"Y"),I29-I9*C21,I29)
However, I don't know how I would be able to add that together if all 4 of the statements were Y as each of the statements is taking away different amounts of money if True.
My guess for it was
=IF(EXACT(L9,"Y"),I29-I9*C21,I29,IF(EXACT(L8,"Y"),I32-I8*C20,I32))
however, to many arguments were being made for the function
any help would be much apricated :)
This is what my excel document looks like at the moment. Don't think I did very well trying to explain it :/.
Excel Document
So more or less what I have been trying to do is when bought is changed to Y it would change that total however I've only been able to find out how to do it with one statement which has been changed to Y using:
=IF(EXACT(J6,"Y"),H18-H6*I6,H18)
sorry for the lack of being to explain much :/
This is how you can build more complex logical functions with IF statements.
If all four statements equal "Y"....
=if(and(A1="Y",B1="Y",C1="Y",D1="Y"),[Calculation if True],[Calculation if False])
So, here is an example of multiple tests nested in a statement.
Test 1: Are all 4 cells equal to "Y"?
If yes, then "Test 1 equals True".
If not,
Test 2: Are the first 3 cells equal to "Y" and the 4th cell equal "N"?
If yes, then "Test 2 equals True"
If not, "Neither Test 1 or Test 2 equal True"
This is the formula:
=if(and(A1="Y",B1="Y",C1="Y",D1="Y"),"Test 1 equals True",if(and(A1="Y",B1="Y",C1="Y",D1="N"),"Test 2 equals True","Neither Test 1 nor Test 2 equal True"))
I am trying to understand the maths in this code that converts binary to decimal. I was wondering if anyone could break it down so that I can see the working of a conversion. Sorry if this is too newb, but I've been searching for an explanation for hours and can't find one that explains it sufficently.
I know the conversion is decimal*2 + int(digit) but I still can't break it down to understand exaclty how it's converting to decimal
binary = input('enter a number: ')
decimal = 0
for digit in binary:
decimal= decimal*2 + int(digit)
print(decimal)
Here's example with small binary number 10 (which is 2 in decimal number)
binary = 10
for digit in binary:
decimal= decimal*2 + int(digit)
For for loop will take 1 from binary number which is at first place.
digit = 1 for 1st iteration.
It will overwrite the value of decimal which is initially 0.
decimal = 0*2 + 1 = 1
For the 2nd iteration digit= 0.
It will again calculate the value of decimal like below:
decimal = 1*2 + 0 = 2
So your decimal number is 2.
You can refer this for binary to decimal conversion
The for loop and syntax are hiding a larger pattern. First, consider the same base-10 numbers we use in everyday life. One way of representing the number 237 is 200 + 30 + 7. Breaking it down further, we get 2*10^2 + 3*10^1 + 7*10^0 (note that ** is the exponent operator in Python, but ^ is used nearly everywhere else in the world).
There's this pattern of exponents and coefficients with respect to the base 10. The exponents are 2, 1, and 0 for our example, and we can represent fractions with negative exponents. The coefficients 2, 3, and 7 are the same as from the number 237 that we started with.
It winds up being the case that you can do this uniquely for any base. I.e., every real number has a unique representation in base 10, base 2, and any other base you want to work in. In base 2, the exact same pattern emerges, but all the 10s are replaced with 2s. E.g., in binary consider 101. This is the same as 1*2^2 + 0*2^1 + 1*2^0, or just 5 in base-10.
What the algorithm you have does is make that a little more efficient. It's pretty wasteful to compute 2^20, 2^19, 2^18, and so on when you're basically doing the same operations in each of those cases. With our same binary example of 101, they've re-written it as (1 *2+0)*2+1. Notice that if you distribute the second 2 into the parenthesis, you get the same representation we started with.
What if we had a larger binary number, say 11001? Well, the same trick still works. (((1 *2+1 )*2+0)*2+0)*2+1.
With that last example, what is your algorithm doing? It's first computing (1 *2+1 ). On the next loop, it takes that number and multiplies it by 2 and adds the next digit to get ((1 *2+1 )*2+0), and so on. After just two more iterations your entire decimal number has been computed.
Effectively, what this is doing is taking each binary digit and multiplying it by 2^n where n is the place of that digit, and then summing them up. The confusion comes due to this being done almost in reverse, let's step through an example:
binary = "11100"
So first it takes the digit '1' and adds it on to 0 * 2 = 0, so we
have digit = '1'.
Next take the second digit '1' and add it to 1* 2 =
2, digit = '1' + '1'*2.
Same again, with digit = '1' + '1'*2 +
'1'*2^2.
Then the 2 zeros add nothing, but double the result twice,
so finally, digit = '0' + '0'*2 + '1'*2^2 + '1'*2^3 + '1'*2^4 = 28
(I've left quotes around digits to show where they are)
As you can see, the end result in this format is a pretty simple binary to decimal conversion.
I hope this helped you understand a bit :)
I will try to explain the logic :
Consider a binary number 11001010. When looping in Python, the first digit 1 comes in first and so on.
To convert it to decimal, we will multiply it with 2^7 and do this till 0 multiplied by 2^0.
And then we will add(sum) them.
Here we are adding whenever a digit is taken and then will multiply by 2 till the end of loop. For example, 1*(2^7) is performed here as decimal=0(decimal) +1, and then multiplied by 2, 7 times. When the next digit(1) comes in the second iteration, it is added as decimal = 1(decimal) *2 + 1(digit). During the third iteration of the loop, decimal = 3(decimal)*2 + 0(digit)
3*2 = (2+1)*2 = (first_digit) 1*2*2 + (seconds_digit) 1*2.
It continues so on for all the digits.
(1:)`(3:)#.(1&=)"0 i.2
1 3
(1:,2:)`(3:)#.(1&=)"0 i.2
1 2
3 0
I want to get
1 2 3
Without new dimensions. Without zeros.
The shape changes dramatically between (1:) and (1:,2:).
$ 1: 'a'
$ 1 $ 1: 'a'
1
$ (1:,2:) 'a'
2
(1&$ 1:)`(1&$ 3:)#.(1&=)"0 i.2
1
3
There's probably a better way, but to my way of thinking, you're generating arrays of unequal length, which should be boxed, and then you want to turn them into a single list.
Thus:
; ((1:,2:)`(3:))#.(1&=)"0&.> i.2
1 2 3
Which can be refactored and improved a bit:
;#:((1:,2:)`(3:)#.(1&=)each) i.2
1 2 3
You could have used (1:,2:,3:) 'ignored argument' to form the list, but that doesn't address why you were using #.
Dane's comment about boxing intermediate results and then razing the resulting list is relevant if you want to merge irregularly shaped results. (Which might be what you were trying for, here.)
I am creating a form that will generate sequential number for report types. Each number is sequential so first report is number 1 and second report is number 2 and so on.
The thing is, the report number needs to be in 4 digits, if the report number is not enough to make 4 digits, fill it in with 0's.
For example:
Report 1 number is 0001, report 2 number is 0002, report 10 number is 0010, report 100 number is 0100
I was thinking about adding 4 0's to the report number and do a substring formula, but the problem is I do not know the starting number.
Appreciate the help
I suggest to generate the report number once this is submitted by the user, this way you can get the sharepoint list id number, and then apply a simple set of rules like this:
Condition:
If Id does not match pattern Custom Pattern: \d{4}
Run this Actions
Set reportNumber's value: result = concat (substring("0000", 1 , 4 - string-length(Id))
Check the box to prevent the next rule to run when the condition is met
Add a new rule under this one just to print the Id if the condition is met.
So this way, numbers below 4 digits will be concatenated, and ids with 4 digits will just be displayed.
I hope this help you.
I am very happy to discoverd this site. I get very good help. Hope you guys can help me with another problem. I want to round a number. Lets say I have a number 39 if I devide this into 2 then I get 18.5. Which makes very logical. But when you are counting in persons then you can't cut a person in half. So I am looking for a formule in vba. I tried the round function
group=39
devideby = 3 'devideby can be 2 or 3
test = round(group/devideby)
If I do this I get test=20. I want to have 2 or 3 separate answers: if devided by the number 2 then I want to have 20 and 19. If devided by 3 then I want to have 13, 13 and 13. Is there a way to solve this?
You could try something like this:
Dim arrOutput(2)
Select Case divideby
Case 2
arrOutput(0) = Int(group / divideby)
arrOutput(1) = group - arrOutput(0)
arrOutput(2) = 0
Case 3
arrOutput(0) = Int(group / divideby)
arrOutput(1) = Int((group - arrOutput(0)) / 2)
arrOutput(2) = (group - arrOutput(0)) - arrOutput(1)
Case Else
MsgBox "Error"
End Select
It's not very elegant but I think it does what you are asking