Skip to content

Number

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

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

value output
#f B
’() B
0 A
42 A
-2045 A

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

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

predicate value output
zero? 0 A
zero? 1 B
positive? 42 A
positive? -42 B
negative? -42 A
negative? 42 B
even? 2 A
even? 3 B
odd? 3 A
odd? 2 B

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

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

predicate value output
number? 0 A
number? 1 A
number? -42 A
complex? 0 A
complex? 1 A
complex? -42 A
real? 0 A
real? 1 A
real? -42 A
rational? 0 A
rational? 1 A
rational? -42 A
integer? 0 A
integer? 1 A
integer? -42 A

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “B”.

predicate
number?
complex?
real?
rational?
integer?

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the exit status should be 0.

value
0
1
42
-1
-42

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

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

value output
127 C
128 D
129 E

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

expression value
(+) 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

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

expression value
(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-quotient 5 1) 5
(floor-quotient 5 2) 2
(floor-quotient 5 3) 1
(floor-quotient -5 2) -3
(floor-quotient -5 -2) 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
(floor-remainder 6 2) 0
(floor-remainder 6 -2) 0
(floor-remainder -6 2) 0
(floor-remainder -6 -2) 0

Given a file named “main.scm” with:

(import (scheme base))
(define-values (x y) <expression>)
(write-u8 (if (= x <quotient>) 65 66))
(write-u8 (if (= y <remainder>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “AA”.

expression quotient remainder
(floor/ 8 3) 2 2
(floor/ 8 -3) -3 -1
(floor/ -8 3) -3 1
(floor/ -8 -3) 2 -2
(truncate/ 8 3) 2 2
(truncate/ 8 -3) -2 2
(truncate/ -8 3) -2 -2
(truncate/ -8 -3) 2 -2

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

value result
-3 9
-2 4
-1 1
0 0
1 1
2 4
3 9

Calculate a square root of an exact integer

Section titled “Calculate a square root of an exact integer”

Given a file named “main.scm” with:

(import (scheme base))
(define-values (x y) (exact-integer-sqrt <value>))
(write-u8 (if (= x <root>) 65 66))
(write-u8 (if (= y <remainder>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “AA”.

value root remainder
0 0 0
1 1 0
4 2 0
5 2 1
8 2 4
9 3 0

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (gcd <x> <y>) <z>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

x y z
0 0 0
1 1 1
6 2 2
2 6 2
6 3 3
3 6 3
30 42 6
42 30 6
-30 42 6
-30 -42 6

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (lcm <x> <y>) <z>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

x y z
1 1 1
2 3 6
3 2 6
6 10 30
10 6 30
-6 10 30
-6 -10 30

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (numerator 42) 42) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (denominator 42) 1) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

Given a file named “main.scm” with:

(import (scheme base))
(write-u8 (if (= (expt <base> <exponent>) <result>) 65 66))

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

base exponent result
1 0 1
1 1 1
2 0 1
2 3 8
3 5 243

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

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

Compare numbers with an insufficient number of arguments

Section titled “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 stak main.scm

Then the stdout should contain exactly “A”.

values
0

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

values output
0 0
1 1
1 2 1
1 2 3 1
2 3 1 1
3 1 2 1

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “A”.

values output
0 0
1 1
1 2 2
1 2 3 3
2 3 1 3
3 1 2 3

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

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

value radix output
0 0
1 1
2 2
42 42
-1 -1
-2 -2
-42 -42
0 16 0
1 16 1
2 16 2
15 16 f
42 16 2a
-1 16 -1
-2 16 -2
-42 16 -2a
0 32 0
1 32 1
2 32 2
31 32 v
42 32 1a
-1 32 -1
-2 32 -2
-42 32 -1a

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

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

value radix output
0 0
1 1
2 2
42 42
-1 -1
-2 -2
-42 -42
0 16 0
1 16 1
2 16 2
f 16 15
2a 16 42
2A 16 42
-1 16 -1
-2 16 -2
-2a 16 -42
-2A 16 -42
0 32 0
1 32 1
2 32 2
v 32 31
1a 32 42
1A 32 42
-1 32 -1
-2 32 -2
-1a 32 -42
-1A 32 -42

Given a file named “main.scm” with:

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

When I successfully run stak main.scm

Then the stdout should contain exactly “B”.

value
x
foo
-
2x
-x
-2x