My car has a four digit number with no leading zeros, and the following properties:
Its last digit is double the first digit
its middle two digits are the same
its last two digits are double the first two digits
What is my car's number?
Puzzling Stack Exchange is a question and answer site for those who create, solve, and study puzzles. It only takes a minute to sign up.
Sign up to join this communityMy car has a four digit number with no leading zeros, and the following properties:
Its last digit is double the first digit
its middle two digits are the same
its last two digits are double the first two digits
What is my car's number?
Answer should be
4998
Script I used :
# RUBY
for i in 0..9999
j = i.to_s.rjust(4, "0") # 0 padding
a = j[0]
b = j[1]
c = j[2]
d = j[3]
if (b != c) then next end # Rule2
if d.to_i != (2 * a.to_i) then next end #Rule1
if 2 * (a.to_s + b.to_s).to_i != (c.to_s + d.to_s).to_i then next end #Rule3
puts j
next
end
Last digit is the double of first digit;
1..2
2..4
3..6
4..8
Middle two digits are same. It has to be a number when multiplied by 2 has the last digit in it;
1662
2774
3886
4998
Last two digits are the double of first two digits The only correct possible answer
4998
A deductive approach:
The number has form abb(2a) for digits a and b. Since the last two digits are double the first two, 10b + 2a = 2(10a + b). So 8b = 18a and 4b = 9a. Therefore b = 9, a = 4, and the solution is 4998.
I think it's
4 9 9 8
Good math problem! ;)
Done in the old way, not programming took place!
From the clues we have:
a b c d
d = 2*a
b = c
10*c + d = 2*(10*a + b)
Doing some substitution we achieve:
10*b + 2*a = 2*(10*a + b)
8*b = 18*a
4*b = 9*a
So
a has to be a 4
b has to be a 9
cd has to be 49*2 = 98
well...
0 0 0 0
Seems to fit :)
My car has four digit number
. Means a valid number.. However I will edit my answer. Sorry for misunderstanding..
$\endgroup$
Jan 21, 2016 at 10:15
If a
is the first digit b
is the second and third and d
is the last, then
20*a + 2*b = 10*b + d
because its last two digits are double the first two digits
.
Or, simplifying
20*a = 8*b + d
Because Its last digit is double the first digit
, we can rewrite this as
20*a = 8*b + 2*a
Which amounts to
9*a = 4*b
Since the 0 solution is forbidden, and both a and b are naturals less than 10, evidently the answer is
4 9 9 8, where a = 4, b = 9 and d = a*2 = 8
x 0 0 2x
where 0<x<4
.
Its last digit is double the first digit [x and 2x, check]
its middle two digits are the same [0&0, check]
its last two digits are double the first two digits [x+0 and 0+2x, check]
For the last digit to be double the first digit but also the last two digits being double the first two digits then the first two digits must differ by 5, giving (a)(a+5)(a+5)(2a). The restriction on the third digit then requires a+5 = 2a+1 (from the carry from 2(a+5)) which simplifies to a=4.
Without looking at any answers, it's:
4998.
Because:
Form the first two clues it's of the form a b b (2a).
So from the last: 20a + 2b = 10b + 2a.
Or: 9a = 4b.
The only single nonzero digits this works for is a = 4 and b = 9
A little bit different coding solution: This can be done by creating the cartesian product of four instances of the set of numbers 0-9. This results in a list of our products, each of length 4 (ten thousand such lists, or 104); first is (0, 0, 0, 0)
, last is (9, 9, 9, 9)
. Then we filter that list based on the given constraints
In scala:
val toTen = Range.inclusive(0, 9)
val candidates = for { x <- toTen; y <- toTen;
z <- toTen; a <- toTen } yield (x, y, z, a)
val result = candidates.drop(1) // exclude 0000
.filter(x =>
(x._4 == 2*x._1) && (x._2 == x._3) &&
(x._3*10 + x._4) == 2*(x._1 * 10 + x._2))
.head
res1: (Int, Int, Int, Int) = (4,9,9,8)