Skip to main content
added 887 characters in body
Source Link
molbdnilo
  • 67.1k
  • 3
  • 46
  • 90

Don't wrap your arguments in parentheses - (abs(x)) means "call the procedure x and pass the result to abs.
(cons (first(y)second(y)) means "cons these four things: the value of first; the result of calling the procedure y; the value of second; and the result of calling the procedure y".
(You've called procedures correctly in some places. Stick to the same pattern.)

You're also missing a comparison in a couple of conditions; (= (modulo (abs x) 1000) 0).

The inputs are not lists, they're integers, so you can't apply length, first, or any such things to them.
The result should be an integer, not a list, so you can't construct it using append and cons, you should only use arithmetic.

These facts about integers should get you started:

  • A number has fewer than five digits if it is smaller than 10000.
  • The last four digits of a non-negative number n is (modulo n 10000).
  • If x is 12 and y is 34, x * 100 + y is 1234.
  • To get the three leftmost digit in an integer, you can divide by 10 repeatedly until you have a number less than 1000.

Also note that the second number only has one condition on its digits while the first has two, and that the note about defining auxiliary functions was not left there as a challenge for you to do without them.

For instance, if you had the auxiliary functions

  • (left-digits n x), which produces the leftmost n digits of x, and
  • (right-digits n x), which produces the rightmost n digits of x

you could write (it's also probably not a coincidence that the description uses the words "if" and "or"):

(define (make5 x y) (if (or ( ... )) -2 (+ (* 100 (right-digits 3 x)) (left-digits 2 y)))) 

Since you want to ignore the sign of the numbers, it's convenient to take care of abs once at the start, using let:

(define (make5 signed-x signed-y) (let ((x (abs signed-x)) (y (abs signed-y))) (if (or ( ... )) -2 (+ (* 100 (right-digits 3 x)) (left-digits 2 y))))) 

"All" that's left now is filling in the conditions and writing the two digit-extracting functions.

Don't wrap your arguments in parentheses - (abs(x)) means "call the procedure x and pass the result to abs.
(cons (first(y)second(y)) means "cons these four things: the value of first; the result of calling the procedure y; the value of second; and the result of calling the procedure y".
(You've called procedures correctly in some places. Stick to the same pattern.)

You're also missing a comparison in a couple of conditions; (= (modulo (abs x) 1000) 0).

The inputs are not lists, they're integers, so you can't apply length, first, or any such things to them.
The result should be an integer, not a list, so you can't construct it using append and cons, you should only use arithmetic.

These facts about integers should get you started:

  • A number has fewer than five digits if it is smaller than 10000.
  • The last four digits of a non-negative number n is (modulo n 10000).
  • If x is 12 and y is 34, x * 100 + y is 1234.
  • To get the three leftmost digit in an integer, you can divide by 10 repeatedly until you have a number less than 1000.

Also note that the second number only has one condition on its digits while the first has two, and that the note about defining auxiliary functions was not left there as a challenge for you to do without them.

Don't wrap your arguments in parentheses - (abs(x)) means "call the procedure x and pass the result to abs.
(cons (first(y)second(y)) means "cons these four things: the value of first; the result of calling the procedure y; the value of second; and the result of calling the procedure y".
(You've called procedures correctly in some places. Stick to the same pattern.)

You're also missing a comparison in a couple of conditions; (= (modulo (abs x) 1000) 0).

The inputs are not lists, they're integers, so you can't apply length, first, or any such things to them.
The result should be an integer, not a list, so you can't construct it using append and cons, you should only use arithmetic.

These facts about integers should get you started:

  • A number has fewer than five digits if it is smaller than 10000.
  • The last four digits of a non-negative number n is (modulo n 10000).
  • If x is 12 and y is 34, x * 100 + y is 1234.
  • To get the three leftmost digit in an integer, you can divide by 10 repeatedly until you have a number less than 1000.

Also note that the second number only has one condition on its digits while the first has two, and that the note about defining auxiliary functions was not left there as a challenge for you to do without them.

For instance, if you had the auxiliary functions

  • (left-digits n x), which produces the leftmost n digits of x, and
  • (right-digits n x), which produces the rightmost n digits of x

you could write (it's also probably not a coincidence that the description uses the words "if" and "or"):

(define (make5 x y) (if (or ( ... )) -2 (+ (* 100 (right-digits 3 x)) (left-digits 2 y)))) 

Since you want to ignore the sign of the numbers, it's convenient to take care of abs once at the start, using let:

(define (make5 signed-x signed-y) (let ((x (abs signed-x)) (y (abs signed-y))) (if (or ( ... )) -2 (+ (* 100 (right-digits 3 x)) (left-digits 2 y))))) 

"All" that's left now is filling in the conditions and writing the two digit-extracting functions.

added 182 characters in body
Source Link
molbdnilo
  • 67.1k
  • 3
  • 46
  • 90

You should be getting a completely different error if you try to pass it two integers, so you're probably not testing the procedure correctly.

Don't wrap your arguments in parentheses - (abs(x)) means "call the procedure x and pass the result to abs.
(cons (first(y)second(y)) means "cons these four things: the value of first; the result of calling the procedure y; the value of second; and the result of calling the procedure y".
(You've called procedures correctly in some places. Stick to the same pattern.)

You're also missing a comparison in a couple of conditions; (= (modulo (abs x) 1000) 0).

The inputs are not lists, they're integers, so you can't apply length, first, or any such things to them.
The result should be an integer, not a list, so you can't construct it using append and cons, you should only use arithmetic.

These facts about integers should get you started:

  • A number has fewer than five digits if it is smaller than 10000.
  • The last four digits of a non-negative number n is (modulo n 10000).
  • If x is 12 and y is 34, x * 100 + y is 1234.
  • To get the three leftmost digit in an integer, you can divide by 10 repeatedly until you have a number less than 1000.

Also note that the second number only has one condition on its digits while the first has two, and that the note about defining auxiliary functions was not left there as a challenge for you to do without them.

You should be getting a completely different error if you try to pass it two integers, so you're probably not testing the procedure correctly.

Don't wrap your arguments in parentheses - (abs(x)) means "call the procedure x and pass the result to abs.
(cons (first(y)second(y)) means "cons these four things: the value of first; the result of calling the procedure y; the value of second; and the result of calling the procedure y".
(You've called procedures correctly in some places. Stick to the same pattern.)

You're also missing a comparison in a couple of conditions; (= (modulo (abs x) 1000) 0).

The inputs are not lists, they're integers, so you can't apply length, first, or any such things to them.
The result should be an integer, not a list, so you can't construct it using append and cons, you should only use arithmetic.

These facts about integers should get you started:

  • A number has fewer than five digits if it is smaller than 10000.
  • The last four digits of a non-negative number n is (modulo n 10000).
  • If x is 12 and y is 34, x * 100 + y is 1234.

Also note that the second number only has one condition on its digits while the first has two.

Don't wrap your arguments in parentheses - (abs(x)) means "call the procedure x and pass the result to abs.
(cons (first(y)second(y)) means "cons these four things: the value of first; the result of calling the procedure y; the value of second; and the result of calling the procedure y".
(You've called procedures correctly in some places. Stick to the same pattern.)

You're also missing a comparison in a couple of conditions; (= (modulo (abs x) 1000) 0).

The inputs are not lists, they're integers, so you can't apply length, first, or any such things to them.
The result should be an integer, not a list, so you can't construct it using append and cons, you should only use arithmetic.

These facts about integers should get you started:

  • A number has fewer than five digits if it is smaller than 10000.
  • The last four digits of a non-negative number n is (modulo n 10000).
  • If x is 12 and y is 34, x * 100 + y is 1234.
  • To get the three leftmost digit in an integer, you can divide by 10 repeatedly until you have a number less than 1000.

Also note that the second number only has one condition on its digits while the first has two, and that the note about defining auxiliary functions was not left there as a challenge for you to do without them.

added 477 characters in body
Source Link
molbdnilo
  • 67.1k
  • 3
  • 46
  • 90

You should be getting a completely different error if you try to pass it two integers, so you're probably not testing the procedure correctly.

Don't wrap your arguments in parentheses - (abs(x)) means "call the procedure x and pass the result to abs.
(cons (first(y)second(y)) means "cons these four things: the value of first; the result of calling the procedure y; the value of second; and the result of calling the procedure y".
(You've done itcalled procedures correctly in some places. Stick to the same pattern.)

You're also missing a comparison in a couple of conditions; (= (modulo (abs x) 1000) 0).

The inputs are not lists, they're integers, so you can't apply length, first, or any such things to them.
The result should be an integer, not a list, so you can't construct it using append and cons, you should only use arithmetic.

These facts about integers should get you started:

  • A number has fewer than five digits if it is smaller than 10000.
  • The last four digits of a non-negative number n is (modulo n 10000).
  • If x is 12 and y is 34, x * 100 + y is 1234.

Also note that the second number only has one condition on its digits while the first has two.

Don't wrap your arguments in parentheses - (abs(x)) means "call the procedure x and pass the result to abs.
(You've done it correctly in some places.)

The inputs are not lists, they're integers, so you can't apply length, first, or any such things to them.
The result should be an integer, not a list, so you can't construct it using append and cons, you should only use arithmetic.

These facts about integers should get you started:

  • A number has fewer than five digits if it is smaller than 10000.
  • The last four digits of a non-negative number n is (modulo n 10000).
  • If x is 12 and y is 34, x * 100 + y is 1234.

You should be getting a completely different error if you try to pass it two integers, so you're probably not testing the procedure correctly.

Don't wrap your arguments in parentheses - (abs(x)) means "call the procedure x and pass the result to abs.
(cons (first(y)second(y)) means "cons these four things: the value of first; the result of calling the procedure y; the value of second; and the result of calling the procedure y".
(You've called procedures correctly in some places. Stick to the same pattern.)

You're also missing a comparison in a couple of conditions; (= (modulo (abs x) 1000) 0).

The inputs are not lists, they're integers, so you can't apply length, first, or any such things to them.
The result should be an integer, not a list, so you can't construct it using append and cons, you should only use arithmetic.

These facts about integers should get you started:

  • A number has fewer than five digits if it is smaller than 10000.
  • The last four digits of a non-negative number n is (modulo n 10000).
  • If x is 12 and y is 34, x * 100 + y is 1234.

Also note that the second number only has one condition on its digits while the first has two.

Source Link
molbdnilo
  • 67.1k
  • 3
  • 46
  • 90
Loading