Page 1 of 1

Turing Help.

Posted: Wed Apr 13, 2005 8:56 am
by Anonymous
Hey, just got an account, have a few Turing problems.

I know what they do, but i need to know how they work. Like the pre-coded function. What is it? What is the code behind mod div ceil and floor

any help would be greatly appreciated.

Archived topic from Iceteks, old topic ID:3242, old post ID:26364

Turing Help.

Posted: Wed Apr 13, 2005 8:09 pm
by Sockoo
Syntax mod

Description The mod (modulo) operator produces the modulo of one number with another. In other words, the result is always a number between 0 and the second operand. If both operands are positive, the result is identical to the remainder operator. For example, 7 mod 2 produces 1 and 12 mod 5 produces 3.

Example In this example, hours is the current time. It is moved back and forth by a random amount, but the final result must always be between 1 and 12 (the mod operation produces a number between 0 and 11 and then 0 becomes 12).

var hours : int := 12
var hoursPassed : int
put "The time is now ", hours, " o'clock"
loop
randint (hoursPassed, -12, 12)
exit when hoursPassed = 0
if hoursPassed < 0 then
put hoursPassed, " hours before " ..
else
put hoursPassed, " hours later " ..
end if
put hours, " o'clock" ..
hours := (hours + hoursPassed) mod 12
if hours = 0 then
hours = 12
end if
put " it was ", hours, " o'clock"
end loop

Details If the second operand is positive, then the result is always non-negative. Likewise, if the second operand is negative, then the result is always non-positive. If both operands are negative, the result is the same as the remainder operator.


Archived topic from Iceteks, old topic ID:3242, old post ID:26372

Turing Help.

Posted: Wed Apr 13, 2005 8:09 pm
by Sockoo
Syntax div

Description The div operator divides one number by another and produces the integer result, truncated in the direction of zero. For example, 7 div 2 produces 3 and -7 div 2 produces -3.

Example In this example, eggCount is the total number of eggs. The first put statement determines how many dozen eggs there are. The second put statement determines how many extra eggs there are beyond the last dozen.

var eggCount : int
get eggCount
put "You have ", eggCount div 12, " dozen eggs"
put "You have ", eggCount mod 12, " left over"



Archived topic from Iceteks, old topic ID:3242, old post ID:26373

Turing Help.

Posted: Wed Apr 13, 2005 8:10 pm
by Sockoo
Syntax ceil (r : real) : int

Description Returns the smallest integer greater than or equal to r.

Details The ceil (ceiling) function is used to convert a real number to an integer. The result is the smallest integer that is greater than or equal to r. In other words, the ceil function rounds up to the nearest integer. For example, ceil (3) is 3, ceil (2.25) is 3 and ceil (-8.43) is -8.




Syntax floor ( r : real ) : int

Description Returns the largest integer that is less than or equal to r.

Details The floor function is used to convert a real number to an integer. The result is the largest integer that is less than or equal to r. In other words, the floor function rounds down to the nearest integer. For example, floor (3) is 3, floor (2.75) is 2 and floor (-8.43) is -9.




hope this helps :) .. would of put it in one post but .. would of been huge .. sorry if this causes any problems .. if soo just put it all in one post w/e ..

Archived topic from Iceteks, old topic ID:3242, old post ID:26374