Numbers
These puzzles provide means for various operations with numbers in your scenario.
![Visual programming blocks to calculate numbers](files/puzzles/puzzles-numbers.jpg)
Contents
Puzzles Reference
number
This universally used puzzle provides the means to supply some number to your Puzzles scenario.
![Visual logic block to create numbers](files/puzzles/puzzles-numbers-number.jpg)
Numbers can be written without decimals (integers) or with decimals (floating-point numbers). Extra large or extra small numbers can be written with scientific (exponent) notation.
![Using number block](files/puzzles/puzzles-numbers-number-example.jpg)
angle
This puzzle allows you to visually define angle (in degrees).
![Visual programming block to create angle values](files/puzzles/puzzles-numbers-angle.jpg)
arithmetic operation (with two inputs)
This puzzle allows you to perform elementary arithmetic operations: addition (+), subtraction (-), multiplication (×) and division (÷), as well as exponentiation (^).
![Visual programming block to perform various math operations](files/puzzles/puzzles-numbers-elementary-operation.jpg)
Please note that floating-point arithmetic is not always 100% accurate, and may produce unpredictable results when comparing numeric values. To get rid of those precision issues, you may use rounding with precision.
![Using operation block with two inputs](files/puzzles/puzzles-numbers-elementary-operation-example.jpg)
arithmetic operation (with single input)
This puzzle allows you to perform the following mathematical operations: square root (√), absolute value aka modulus (|x|), sign change aka negation (-), natural logarithm (ln), decimal logarithm (log10), natural exponential function (e^), and power of ten (10^).
![Visual programming block to perform math operation on single value](files/puzzles/puzzles-numbers-arithmetic-operation-single-input.jpg)
Examples:
![Using operation block with a single input](files/puzzles/puzzles-numbers-arithmetic-operation-single-input-example.jpg)
Please note that floating-point arithmetic is not always 100% accurate, and may produce unpredictable results when comparing numeric values. To get rid of those precision issues, you may use rounding with precision.
round (to integer)
This puzzle rounds a specified number. The round variant rounds a number to the nearest integer: 2.49 will be rounded down (producing 2), and 2.5 will be rounded up (producing 3). The round up variant rounds a number upward to the nearest integer: 2.1 will be rounded up (producing 3). The round down variant rounds a number downward to the nearest integer: 2.9 will be rounded down (producing 2).
![Visual logic block to round a value](files/puzzles/puzzles-numbers-round.jpg)
Examples:
![Rounding example](files/puzzles/puzzles-numbers-round-examples.jpg)
round with precision
This puzzle rounds a given number using the specified precision.
![Visual logic block to round with precision](files/puzzles/puzzles-numbers-round-with-precision.jpg)
Examples:
![Rounding example script 1](files/puzzles/puzzles-numbers-round-with-precision-example.jpg)
Floating-point arithmetic is not always 100% accurate, and may produce unpredictable results when comparing numeric values. To get rid of those precision issues, you may use rounding with precision as follows:
![Rounding example script 2](files/puzzles/puzzles-numbers-round-with-precision-example2.jpg)
check
This puzzle checks whether a specified number is even, odd, prime, whole, positive, negative, or divisible by some other number. The result is true if this is the case and false if not. For using with Logic puzzles.
![Check - visual programming block](files/puzzles/puzzles-numbers-check.jpg)
Examples:
![Using check block](files/puzzles/puzzles-numbers-check-examples.jpg)
clamp
This puzzle constraints a number to be between the specified limits (inclusive).
![Clamp - visual programming block](files/puzzles/puzzles-numbers-clamp.jpg)
Examples:
![Using clamp block](files/puzzles/puzzles-numbers-clamp-example.jpg)
map range
This puzzle maps a given value from one range to another.
![Map range visual programming block](files/puzzles/puzzles-numbers-map-range.jpg)
Example: converting position of the slider that moves from -10 to 10 units along axis X to percentage value from 0% to 100%.
![Map range example](files/puzzles/puzzles-numbers-map-range-example.jpg)
random integer
This puzzle returns a random integer number between specified numbers (inclusive both limits).
![Visual programming block to generate random integer](files/puzzles/puzzles-numbers-random-integer.jpg)
Note: supplying non-integer limits is possible, although this extends the range as this puzzle performs some additional rounding under the hood.
Examples:
![Random integer example script](files/puzzles/puzzles-numbers-random-integer-examples.jpg)
random fraction
This puzzle returns a random floating-point number between 0 (inclusive) and 1 (exclusive).
![Visual logic block to generate random fraction](files/puzzles/puzzles-numbers-random-fraction.jpg)
In the following example this puzzle is used to generate a random color for a material:
![Random fraction example script](files/puzzles/puzzles-numbers-random-fraction-example.jpg)
remainder
This puzzle finds the remainder after division of one number by another (aka the modulo operation).
![Logic block to calculate division remainder](files/puzzles/puzzles-numbers-remainder.jpg)
Examples:
![Calculating remainder](files/puzzles/puzzles-numbers-remainder-examples.jpg)
operations on list
Performs an operation on the numbers of a specified list.
![List operation visual logic block](files/puzzles/puzzles-numbers-operations-on-list.jpg)
- sum - calculates the sum of all numbers in the list.
- min - finds the smallest number.
- max - finds the largest number.
- average - finds the arithmetic mean (as the sum of all numbers divided by the length of the list).
- median - finds the median (as the middle number when all numbers are sorted from smallest to largest).
- modes - finds the modes (as a list of numbers that appear the most frequently in the list).
- standard deviation - calculates the standard deviation (as the square root of the average of the squared deviations from the arithmetic mean).
- random item - returns a randomly chosen item.
Examples:
![Examples of visual programming scripts using operations on list](files/puzzles/puzzles-numbers-operations-on-list-examples.jpg)
trigonometric functions
This puzzle allows you to calculate the values of the trigonometric functions sine (sin), cosine (cos), and tangent (tan), as well as the values of their inverse counterparts arcsine (asin), arccosine (acos), and arctangent (atan). The puzzle expects (or returns) values expressed in degrees.
![Visual logic block to calculate trigonometric functions](files/puzzles/puzzles-numbers-trigonometric-functions.jpg)
Examples:
![Calculating various trigonometric functions](files/puzzles/puzzles-numbers-trigonometric-functions-examples.jpg)
Please note that floating-point arithmetic is not always 100% accurate, and may produce unpredictable results when comparing numeric values. To get rid of those precision issues, you may use rounding with precision.
constants
This puzzle returns the following mathematical constants: pi (π), Euler's number e, the golden ratio (φ), square root of 2, square root of ½, and infinity value (∞).
![Math constants visual programming block](files/puzzles/puzzles-numbers-constants.jpg)
Examples:
![Example scripts using math constants](files/puzzles/puzzles-numbers-constants-examples.jpg)
create vector
This puzzle returns a new three-dimensional vector which consists of the given X, Y, Z coordinates.
![Visual programming block to create vectors](files/puzzles/puzzles-numbers-create-vector.jpg)
set vector value
This puzzle set the given value (x, y, z coordinate or length) for the given vector.
![Visual programming block to set vector value](files/puzzles/puzzles-numbers-set-vector-value.jpg)
get vector value
This puzzle returns the given value taken from the given vector.
![Visual programming block to get vector value](files/puzzles/puzzles-numbers-get-vector-value.jpg)
Returned values:
- x - X coordinate.
- y - Y coordinate.
- z - Z coordinate.
- is zero - true if the vector has zero length, false otherwise.
- length - vector length.
- negated - a new vector which points in the reverse direction.
- normalized - a new vector with length 1.
vector math
This puzzle performs a math operation between two vectors and returns a new vector.
![Visual programming block to do vector math](files/puzzles/puzzles-numbers-vector-math.jpg)
Operations:
- + - add vectors.
- - - subtract vectors.
- × - multiply vectors (per-component).
- / - divide vectors (per-component).
- dot - calculate and return a dot product between vectors.
- cross - calculate and return a cross product between vectors.
- rotate - rotate a vector by Euler angles given as the second parameter. Euler angles are specified in degrees.
Having Troubles with Puzzles?
Seek help on the forums!