Skip to content

Number

Check if a value is a number

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (number? <value>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<output>”.

Examples

valueoutput
#fB
’()B
0A
42A
-2045A

Check a number trait

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (<predicate> <value>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<output>”.

Examples

predicatevalueoutput
zero?0A
zero?1B
positive?42A
positive?-42B
negative?-42A
negative?42B
even?2A
even?3B
odd?3A
odd?2B

Check a number class of integers

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (<predicate> <value>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<output>”.

Examples

predicatevalueoutput
number?0A
number?1A
number?-42A
complex?0A
complex?1A
complex?-42A
real?0A
real?1A
real?-42A
rational?0A
rational?1A
rational?-42A
integer?0A
integer?1A
integer?-42A

Check a number class of floating point numbers

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (<predicate> <value>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<output>”.

Examples

predicatevalueoutput
number?3.14A
number?-42.2045A
complex?3.14A
complex?-42.2045A
real?3.14A
real?-42.2045A
rational?0A
rational?1A
rational?-42A
rational?3.14A
rational?-42.2045A
rational?(exp 1)A
integer?3.14B
integer?-42.2045B

Check a number class of non-numbers

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (<predicate> #f) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “B”.

Examples

predicate
number?
complex?
real?
rational?
integer?

Use literals

Given a file named “main.scm” with:

(import (scheme base))
(define x <value>)

When I successfully run scheme main.scm

Then the exit status should be 0.

Examples

value
0
1
42
-1
-42

Use a negative integer

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (+ 66 -1))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Use large (but not big) integers

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (- 1065 1000))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Use integers around the encoding base

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (- <value> 60))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<output>”.

Examples

valueoutput
127C
128D
129E

Use arithmetic operators

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= <expression> <value>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

expressionvalue
(+)0
(+ 1)1
(+ 1 2)3
(- 1)-1
(- 0 1)-1
(- 0 1 2)-3
(*)1
(* 2)2
(* 2 3)6
(/ 6 2)3
(/ 6 2 3)1

Use division operators

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= <expression> <value>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

expressionvalue
(quotient 6 2)3
(quotient 6 3)2
(quotient -6 2)-3
(quotient -6 -2)3
(truncate-quotient 6 2)3
(truncate-quotient 6 3)2
(truncate-quotient -6 2)-3
(truncate-quotient -6 -2)3
(remainder 8 3)2
(remainder 8 -3)2
(remainder -8 3)-2
(remainder -8 -3)-2
(truncate-remainder 8 3)2
(truncate-remainder 8 -3)2
(truncate-remainder -8 3)-2
(truncate-remainder -8 -3)-2
(modulo 5 1)0
(modulo 5 2)1
(modulo 8 3)2
(modulo 8 -3)-1
(modulo -8 3)1
(modulo -8 -3)-2
(floor-remainder 5 1)0
(floor-remainder 5 2)1
(floor-remainder 5 3)2
(floor-remainder -5 2)1
(floor-remainder -5 -2)-1

Calculate a multiplicative inverse

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (/ 2) (/ 1 2)) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Calculate an exponentiation

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (< (abs (- (expt 2 3) (exp (* (log 2) 3)))) 0.000001) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Calculate a logarithm

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (< (abs (- (log 2 3) (/ (log 2) (log 3)))) 0.000001) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Truncate a number

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (= (truncate <input>) <output>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

inputoutput
00
0.10
0.90
11
1.11
1.91
22
-0.90
-1-1
-1.9-1
-2-2
-2.1-2

Calculate a floor

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (= (floor <input>) <output>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

inputoutput
00
0.10
0.90
11
1.11
1.91
22
-0.9-1
-1-1
-1.9-2
-2-2
-2.1-3

Calculate a ceiling

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (= (ceiling <input>) <output>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

inputoutput
00
0.11
0.91
11
1.12
1.92
22
-0.90
-1-1
-1.9-1
-2-2
-2.1-2

Round a number

Given a file named “main.scm” with:

(import (scheme base) (scheme inexact))
(write-u8 (if (= (round <input>) <output>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

inputoutput
00
0.10
0.490
0.50
0.91
11
1.11
1.491
1.52
1.92
22
2.52
3.54
-1-1
-0.9-1
-1.5-2
-1.51-2
-1.9-2

Compare numbers

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if <expression> 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

expression
(< 0 1)
(< 0 1 2)
(> 1 0)
(<= 0 1)
(<= 0 0)
(>= 1 0)
(>= 0 0)

Compare numbers with an insufficient number of arguments

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (< <values>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

values
0

Calculate a minimum

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (min <values>) <output>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

valuesoutput
00
11
1 21
1 2 31
2 3 11
3 1 21

Calculate a maximum

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (max <values>) <output>) 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “A”.

Examples

valuesoutput
00
11
1 22
1 2 33
2 3 13
3 1 23

Convert a number to a string

Given a file named “main.scm” with:

(import (scheme base))
(write-string (number->string <value> <radix>))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<output>”.

Examples

valueradixoutput
00
11
22
4242
-1-1
-2-2
-42-42
0160
1161
2162
1516f
42162a
-116-1
-216-2
-4216-2a
0320
1321
2322
3132v
42321a
-132-1
-232-2
-4232-1a

Convert a floating point number to a string

Given a file named “main.scm” with:

(import (scheme base))
(write-string (number->string <value>))

When I successfully run scheme main.scm

Then the stdout should contain “<value>”.

Examples

value
0.5
0.125
1.2
3.14
-3.14

Convert a string to a number

Given a file named “main.scm” with:

(import (scheme base))
(write-string (number->string (string->number "<value>" <radix>)))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<output>”.

Examples

valueradixoutput
00
11
22
4242
-1-1
-2-2
-42-42
0160
1161
2162
f1615
2a1642
2A1642
-116-1
-216-2
-2a16-42
-2A16-42
0320
1321
2322
v3231
1a3242
1A3242
-132-1
-232-2
-1a32-42
-1A32-42

Convert a string to a floating point number

Given a file named “main.scm” with:

(import (scheme base))
(write-string (number->string (string->number "<value>")))

When I successfully run scheme main.scm

Then the stdout should contain exactly “<value>”.

Examples

value
0.5
0.125
1.2
3.14
-3.14

Convert an invalid string to a number

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (string->number "<value>") 65 66))

When I successfully run scheme main.scm

Then the stdout should contain exactly “B”.

Examples

value
x
foo
-
2x
-x
-2x