Boolean position of a point - geogebra

I want to have a point that belongs or not to a straight line dependanding on a boolean value.
I tried
(4.54, -1.82) a + (1 - a) Point(f)
in the definition of my point, where (4.54, -1.82) is the curent random position, a the boolean name, f the straight line. But it does not work.
Any other idea ?

you must know that a boolean is not 0 or 1 , it's take true or false ,
so create an integer called n and write this : n=if(a,1,0)
then u can complete ur work as
(4.54, -1.82) n + (1 - n) Point(f)
otherwise i don't know

Related

Picking a chosen amount of things from a table without repetition

So I'm currently working on a little side project, so this is my first time learning LUA and I'm currently stuck. So what I'm trying to do is create a function that will randomly choose two numbers between 1 and 5 and make it so they can not collide with the player. I can not seem to get the ability to chose two numbers at random without them being the same. I've been looking around, but have not been able to find a clear answer. Any help would be much appreciated!
My code so far:
local function RandomChoice1()
local t = {workspace.Guess1.CB1,workspace.Guess1.CB2,workspace.Guess1.CB3,workspace.Guess1.CB4,workspace.Guess1.CB5}
local i = math.random(1,5)
end
If you need to select one with probability 20% (one from 1..5 range) and the second one with probability 25% (one from 1..5 range minus the first choice), then something like this should work:
local i1 = math.random(1,5) -- pick one at random from 1..5 interval
-- shift the interval up to account for the selected item
local i2 = math.random(2,5) -- pick one at random from 2..5 interval
-- assign 1 in case of a collision
if i2 == i1, then i2 = 1 end
This will guarantee the numbers not being equal and satisfying your criteria.
Instead of generating i2 you can generate difference i2 - i1
local i1 = math.random(5) -- pick one at random from 1..5 interval
local diff = math.random(4) -- pick one at random from 1..4 interval
local i2 = (i1 + diff - 1) % 5 + 1 -- from 1..5 interval, different from i1
print(i1, i2)
You could use recursion. Save the previous number and if it's the same just generate a new one until its not the same. This way you are garaunteed to never have the same number twice.
local i = 0;
function ran(min,max)
local a = math.random(min,max);
if (a == i) then
return ran(min,max);
else
i = a;
return a;
end
end
Example: "2 from 5" without doubles...
local t = {}
for i = 1, 5 do
t[i] = i
end
-- From now a simple table.remove()...
-- ( table.remove() returns the value of removed key/value pair )
-- ...on a random key avoids doubles
for i = 1, 2 do
print(table.remove(t, math.random(#t)))
end
Example output...
1
4

Lua Dot After Integer

I have a script that return a double value. When it return a integer value I need to add a dot after integer. Is there any clean way to do that.
Example
return 3/2 --> 1.5 (its ok )
return 8/2 --> 4 (its not ok. I need to print 4. (4 with dot). )
return 8/2--> 4. (This is what I want)
Ps. Im not a native english speaker. If I wrote sth funny sorry about that
return 1 + .0
will convert an integer 1 to a float 1.0
Usually you would divide by a float if you want a float result.
return 8/2.0
I don't see why you would want to print that number with a decimal point if there are no decimals. That doesn't make too much sense.
If you insist to do so you should use string.format to format your string.
if math.type(n) == "integer" then
print(string.format("%d.", n))
elseif math.type(n) == "float" then
print(string.format("%f", n))
end

Wrong value calculated by Delphi

I have a record declared as
T3DVector = record
X,Y,Z: Integer;
end;
One variable V of type T3DVector holds:
V.X= -25052
V.Y= 34165
V.Z= 37730
I then try to the following line. D is declared as Double.
D:= (V.X*V.X) + (V.Y*V.Y) + (V.Z*V.Z);
The return value is: -1076564467 (0xFFFFFFFFBFD4EE0D)
The following code should be equivalent:
D:= (V.X*V.X);
D:= D + (V.Y*V.Y);
D:= D + (V.Z*V.Z);
But this,however, returns 3218402829 (0x00000000BFD4EE0D), which actually is the correct value.
By looking at the high bits, I thought this was an overflow problem. When I turned on overflow checking, the first line halted with the exception "Integer overflow". This is even more confusing to me because D is Double, and I am only storing values into D
Can anyone clarify please ?
The target of an assignment statement has no bearing on how the right side is evaluated. On the right side, all you have are of type Integer, so the expression is evaluated as that type.
If you want the right side evaluated as some other type, then at least one operand must have that type. You witnessed this when you broke the statement into multiple steps, incorporating D into the right side of the expression. The value of V.Y * V.Y is still evaluated as type Integer, but the result is promoted to have type Double so that it matches the type of the other operand in the addition term (D).
The fact that D is a double doesn't affect the type of X, Y and Z. Those are Integers, and are apparently not large enough to store the squares of such large numbers, and their multiplication is what overflows. Why don't you declare them as doubles, too?

Ruby ceil is not working for my data in method, only in view

I have such code in controller's method for rounding (only higher) and display ceil part of number:
#constr_num.each do |cn|
non_original_temp_var2 = get_non_tecdoc_analogs(cn.ARL_SEARCH_NUMBER, #article.supplier.SUP_BRAND, false)
non_original << non_original_temp_var2
end
#non_original = non_original.flatten!
#non_original.each do |n_original|
n_original.price = my_round2(n_original.price * markup_for_user)
end
def my_round2 a
res = (a / 1.0).ceil * 1
res
end
But for some reasons i see with every price comma with 0 after it, for example: 5142.0 but it must be 5142
Main strange part is that, if i try to write:
n_original.price = 123
in view i see 123.0
What happend?
Only when i write in view (when displaying price):
price.ceil
i see normal numbers, without comma
What i di wrong? How to ceil my numbers with rounding (but only high, for example 2.24 is 3 3.51 is 4 and 2.0 is 2)? Becouse now for some reasons i see comma and nul after my number, even if i try to "hardcode" number in controller.
How about using the next or succ function of the Integer class? Try something like the following:
def my_round2 a
(a.is_a? Integer) ? a : a.to_i.next
end
If a is an Integer then return a otherwise cast it to Integer using the to_i method and call next or succ method on it.
Reference: http://www.ruby-doc.org/core-2.0/Integer.html
I guess I missed the second part of your question. To avoid the decimal places I guess you would have to use the a.to_i like Philip Hallstrom has suggested.
My guess is that your price field is a Float. Floats will be printed with a decimal spot by default. You need to either cast it to an Integer earlier on (say in my_round2 method) or in your view task a .to_i onto the output.

Function recursion, what happens in the SAS?

I have this scenario: a recursive procedure (or function) is called like
{DoSomething Data C}
and C is the variable that should store the final result, the function prototype is
proc {DoSomething Data N}
%..
%..
{DoSomething Data M}
N = 1 + M
end
and N is the variable that should store the final result too but in the local scope of the procedure.
Now it was told to me that at first, when the procedure is called, the SAS is:
Notice equivalence sets between C and N (both unbound for the moment)
then after all recursions have been completed, the SAS is
notice that both C and N are bound to a value (6)
After exiting the procedure the SAS is left with
because you destroy the N variable. And that's fine.
My question is: what happens during the procedure recursions? Does the C variable link to a partial value structure 1 + M ? And then next time M links to 1 + M2 ?
No, there are no partial structures in Oz, as long as we talk about simple integer arithmetics.
This statement:
N = 1 + M
will block until M is fully determined, i.e. is bound to an integer.
To really understand what is going on, I would have to see the full code.
But I assume that there is a base case that returns a concrete value. Once the base case is reached, the recursion will "bubble up", adding 1 to the result of the inner call.
In other words, the binding of C will only change at the end of the outermost procedure call, where M is 5 and C is therefore bound to 6.

Resources