ScripticXLearn programming visually
Platform
Problems
Community
Leaderboard
Learn
Docs
MiniScript+ basicsVariablesOperators and expressionsInput and outputConditions and decisionsLoopsStringsSums, counts, and extremaDigits of a numberDivisibility and prime numbersNumeric sequences and recurrencesNumber basesFunctions and parametersRecursion
Examples
Basic programsConditionsInput and outputLoopsAlgorithmsWorking with textDigit problemsBase conversionsFunctions and recursionEncode text with a key
What's newHelpContact
Loading…

Examples

MiniScript+

ExamplesMiniScript+
Fundamentals
Basic programsConditionsInput and output
Programming patterns
LoopsAlgorithmsWorking with textDigit problemsBase conversionsFunctions and recursionEncode text with a key
Examples/Digit problems

Digit problems

Count selected digits and check numeric palindromes.

On this page
Count even digits, including zeroCheck a numeric palindromeTry it

Use non-negative integers within the exact integer range. MOD 10 extracts the last digit; DIV 10 removes it. See digits of a number.

Count even digits, including zero#

MS+MiniScript+
1n = 40722x = n3count = 04IF x == 0 THEN5  count = 16END7WHILE x > 08  IF (x MOD 10) MOD 2 == 0 THEN9    count = count + 110  END11  x = x DIV 1012END13PRINT count

The result is 3: digits 4, 0, 2. For n = 0, the answer is 1 because zero is written with one even digit. Without the separate case, the loop would never run and the count would remain zero.

Check a numeric palindrome#

MS+MiniScript+
1n = 12212x = n3reversed = 04WHILE x > 05  reversed = reversed * 10 + x MOD 106  x = x DIV 107END8PRINT reversed9PRINT n == reversed

The output is 1221, then TRUE. For 120, the numeric reversal is 21 and the check gives FALSE. For 0, expect 0, then TRUE. Numbers do not preserve leading zeros; use text and the string palindrome example for identifiers such as "00100".

Try it#

Test 7, 20, 135, 2002. Predict each result before running. To accept negative inputs, first decide whether the sign should be ignored, then explicitly use ABS(n).

PreviousWorking with textNextBase conversions

On this page

Count even digits, including zeroCheck a numeric palindromeTry it