Code puzzle thread +_+

Ok...

Here is a new digit code puzzle (@Arakhor, @Thrasybulos etc)
I solved it (the solution was mentioned in a page and they gave the same answer). It's not difficult, but slightly tedious for a second after the first move.

1727847526549.png
 
Last edited:
The code is 51324
Spoiler Solution :

  • (1) + (5): (5) only has correctly placed digits, (1) only incorrecly placed ones, so we can exclude any digit that has the same place in both -> no 6,9
  • (4) + (5): both have only correctly placed digits, here there are two cases:
    • Case 1: we can exclude digits that are in different positions -> no 7,0
      • (5): one correct digit in (5) but we already excluded 0,6,7,9 -> the code is xxx2x
      • (4): same as above -> x1x24
      • (1): has only two correct digits, we already have 2 and 4 -> no 8
      • (3): has one correctly placed digit, due to only two positions left either 3 or 8. we already excluded 8 -> the code is x1324
      • (2): has three correct digits, we only have found two and excluded two, so the last one must be in the code -> 51324 (0,6,7,8,9 have been excluded)
    • Case 2: a digit appearing in different positions is correct in both -> no 2, one out of 0,7
      • (1) we excluded 2,6,9, so the other two digits must be in the code -> 8,1 in the code
      • (2) has three correct digits, we currecntly have one (7 or 0), so two more digits must be right
      • Since 0 or two would appear twice we now have to include six digits in a five-digit code, this is impossible, so this case is false, the other one true.
  • The code is 51324
(Note: assuming each digit to appear only once (2) becomes superfluous and we do not need to differentiate between cases. So if we assume this puzzle to have been posted with a minimal set of hints we have to differentiate between the two cases.)
 
Spoiler :

"4" + "5":
7, 0, and 9 are common but placed differently so can't be right.
=> _ 1 6 _ 4 or _ 1 _ 2 4

"1"
1 has already been identified as correct, 9 as incorrect, and one of 2 or 6 as correct
=> 8 is wrong
=> If 6 were correct, it can't be both in the right and the wrong spot => incorrect
=> _ 1 _ 2 4

"2"
0 & 7 already excluded, so 5 & 3 are the missing digits

"3"
8, 6, & 0 already excluded
2 is the wrong spot
=> _ _ 3 _ _

So the code is 5 1 3 2 4
 
7 2 1 9 5 ....... Three digits correct but wrongly placed.
3 7 9 5 8 ....... Three digits correct but wrongly placed.
0 3 6 2 9 ....... Three digits correct but wrongly placed.
9 5 7 4 2 ....... Three digits correct but wrongly placed.
1 2 3 7 6 ....... Three digits correct but wrongly placed.
8 0 9 2 3 ....... Three digits correct but wrongly placed.

I made this one, so same caveat as last time (and hopefully with no mistake this time) : I checked, double-checked, and triple-checked, and found at least one way to solve it, but well... I know the answer. ;)
 
So I suppose
Spoiler :
that this is another pigeonhole-based one? You have three correct in each set, and 6 sets, which means that there are 18 correct cases of at most five numbers. I will try tomorrow, it's 4.30 AM here...
 
Spoiler :

First I looked at 5,7,9, because that appears in three hints (1), (2) and (4).
Obviously it is not possible for none to be in the code (each hint has three correct digits). If all three are correct, we can exclude 1,2,3,4,8, but then (5) is impossible. If only one is correct, then the other two digits in those hints must be correct, so we end up with 1,2,3,4,8 and one out of 5,7,9 being correct. That is six digits for a five digit code and thus impossible. As a consequence exactly two out of 5,7,9 are correct.
Next, an observation: (1) and (4) as well as (3) and (6) differ in only one digit (and order). Since all hints have the same amount of correct digits the differening digits are either both correct or both incorrect. This applies to the pairs 1,4 and 6,8.
Next up we are left with three digits we did not consider yet: 0,2,3. Those three all appear in (3) and (6). We know that two out of 5,7,9 are correct and that 1,4 and 6,8 only appear if the other one appears, so in any case we will have an even number of correct digits, so the number of correct digits in 0,2,3 has to be odd, since 5 is odd.
If all three are correct we know five correct digits, so all possible digits in the code: 0,2,3, two out of 5,7,9. Requireing that in each hint only three digits are correct, we can eliminate 9 due to (3). 0,2,3,5,7 proves to ba a valid set of digits. Now for positions: Since in each hint all digits are wrongly placed we have to look at where a digit does not appear. This leaves only one possibility for 7 and 3: xxx37. Now we can fill in xx037 and now neither 2 or 5 can appear in the second position, making the assumption wrong. Thus only one out of 0,2,3 is correct.
In (6) and (3) only one out of 0,2,3 is correct, so the other two digits have to be correct. This leaves us with 6,8,9. Consequently both 1 and 4 are incorrect. (5) now results in 7 being correct and 0 and 5 incorrect. And finally (2) excludes 3 being correct, so we are left with 2,6,7,8,9. Again there are some digits that can only appear in one position, namely 7 and 9: x9xx7. The first digits is not 8, the third not 6 and the fourth not 2, so we have two valid combinations: 29867 and 69287.
Due to eliminating all other possibilities these are the only correct codes.
 
Spoiler :

so we have two valid combinations: 29867 and 69287.
Due to eliminating all other possibilities these are the only correct codes.
Spoiler :

There is a 3rd possibility, which was the intended solution, but since these work too, well done. :thumbsup:

Adding clues would have allowed me to remove those as well I guess, but the more clues there are, the easier the problem gets...
 
Spoiler correction to my previous solution :

so the number of correct digits in 0,2,3 has to be odd
This assumes that each digit appears only once. This is a mistake.
The case with an odd number of digits in 0,2,3 being correct has already been treated. Now consider an even number:
If none out of those are correct, again the hints (3) and (6) can not be fulfilled. Thus only the case if two out of these are correct is relevant.
Now we have two out of 0,2,3 and two out of 5,7,9. This excludes 1,4,6,8 due to them only appearing in pairs. (5) now results in 2,3,7 being correct and (3) then results in 9 being correct. So we have 2,3,7,9 and they fulfill the conditions. Ordering: as before 3,7,9 have only one position they can appear in. This results in the code 29237.
 
A new one. Fyi, this one comes from a math advent calendar. I only made slight modifications. Have fun:

The code is a fixed point in the following Algorithm (meaning further iterations will not change it). Find all possible codes!

1. Choose a number from 0 to 9999.
2. Add zeros to the front of the number so that you have four digits.
3. By rearranging the digits, build the highest and the lowest number.
4. Subtract the lowest number from the highest number.
5. Write this number down and with it follow the instructions from step 2 again.
 
One possible code is obvious: that would be 0.

As for the other one(s)...
Spoiler :

Well, I know it is 6174 because I cheated and wrote a script. :p

Now need to find how to get at that result honestly!
 
I did prove which number (and in which order) it is, (minus one introductory condition; see inside the spoiler), but what I did was the opposite of elegance:

Spoiler :
1728110861490.png



And (due to frustration with the other part) I didn't prove the assumption that (in the non-trivial case) a,b,c,d have to be all different digits.Not that I have a reason to suspect itself would be difficult (at worst it'd be menial).


And although I can't try it now, I suspect a method using min/max and distances on the real line might have been a better idea.
 
Last edited:
I did prove which number (and in which order) it is, (minus one introductory condition; see inside the spoiler), but what I did was the opposite of elegance:

Spoiler :
View attachment 705178


And (due to frustration with the other part) I didn't prove the assumption that (in the non-trivial case) a,b,c,d have to be all different digits.Not that I have a reason to suspect itself would be difficult (at worst it'd be menial).


And although I can't try it now, I suspect a method using min/max and distances on the real life might have been a better idea.

Spoiler :

Actually that is not very far from my reference solution. The basic Idea is the same, looking at both ordered numbers and the actual solution.
Concerning the digits having to be different: If all digits are the same, that obviously results in 0. Note that all digits being different can be considered to be a conclusion, not an assumption, if you treat all cases.
Next consider the case b=c, and then a=b, c=d. Those are quite simple to exclude. (using only abcd-dcab=x1x2x3x4, x1+x2+x3+x4=18 and a >=b>=c>=d) Now all that is left is the case where all are different.

As for making the proof more elegant, basically all that you wrote in blue can be dropped in favour of considering x1-x4 and the red can be simplified quite a bit.
I will wait a bit with posting my version.

Technically it would also be possible to notice, that after a>b>c>d and x1+x4=10, x2+x3=8 only 10 possiblities are left ... and try those.
 
But regarding the blue
Spoiler :
6c=4b was about the only elegant bit of the argument :) It just simplifies to c=4,b=6 since b,c EN, b,c<10


Tbh, I'd expect something at most at around 3/5 of what I wrote, to be an elegant solution. Not that I wasn't very aware of going almost in circles at one point; it's why I got frustrated. I'd had much preferred to be looking at it from a summit, instead of walking here and there in a dark forest and constructing a computer there.
 
Last edited:
Spoiler Solution for mine :

First the easy part: If all digits are the same this obviously results in 0000. Thus all other cases must have at least two different digits.

I will use the convention, that a>=b>=c>=d, with x1x2x3x4 being the code. Note that {a,b,c,d} = {x1,x2,x3,x4}, and abcd-dcba=x1x2x3x4. Also here the notation abcd does not imply a multiplication but the number formed by the digits in that order. All appearing variables have a single digit.
We know that at least two different digits have to appear, that means a>d, and thus a>0, d<9. It is possible for less than four digits being different if a=b, b=c or c=d. We will consider these cases first:
Spoiler a>b>c>d>0 :

b=c: x4 = 10+d-a, x2=x3=9 and x1 = a-d-1. Thus a=9, b=9 and c=9, also x4=1+d, x1=8-d<9, thus x4=9=1+d. OTOH 10>1+d>d thus d=8-d -> d=4. This can not be. It follows b>c.
b>c allows some important statements: we get x4=10+d-a, x3=10+c-b-1=9+c-b, x2=b-c-1, x1=a-d. Thus x1+x4=10, x2+x3=8 [1], and also x1+x2+x3+x4=18 and x1+x4-x2-x3=2 [2].
Now consider d=0. It follows x4=10-a>0, x3=9+c-b, x2=b-c-1, x1=a>0, so one out of {x2,x3} has to be 0. The other is 8. Since x1=a this implies a>=8, and x4 \in {1,2} and x4\in {b,c}. Since 8>2 it follows that b=8, c\in {1,2}. This implies x2>=8-2-1=5>0 and x3>=9+1-8=2>0. Thus 0 is not in {x1,x2,x3,x4} and we can conclude that d>0 [3].

a=b: aacd-dcaa=x1x2x3x4, with x4=10+d-a, x3=10+c-1-a=9+c-a, x2=a-c-1, x1=a-d. Since a>a-c-1>=0 it follows that x2 \in {c,d}. Since [3] it follows that x1\in {c,d}. If we want a to appear twice in {x1,x2,x3,x4} we now have to demand x3-x4=0 (or more specifically x3=x4=a). Thus 0=9+c-a-10-d+a=c-d-1 and thus c=d+1. This now implies x2=x1, which contradicts c>d. Thus a>b.

c=d: x4=10+c-a, x3=10+c-1-b=9+c-b, x2=b-c-1, x1=a-c. b>x2>0 (=0 excluded due to [3]), thus x2=c and 2c=b-1. This excludes x1=c, since that would result in 2c=a=b-1, contradicting a>b. Thus x1=b=a-c. It follows x4=10-b >= x3=9+c-b, since c>=d>0. Thus x4=c, x3=a, a=2c-1=b-2<b, which is impossible.
Now we obtained a>b>c>d>0 [4]. With [1,2,3] we now only have 7 possibilities for {a,b,c,d} left.


Spoiler Identifying the code :

Since we have [1] we will now look into these. We want to establish the correspondence between {a,b,c,d} and {x1,x2,x3,x4}. Due to [1,4] we can conclude, that if x1+x4=e+f, with e,f \in {a,b,c,d} and e not f, that x1, x4\in {e,f} and x1 not x4.
First we observe that x1+x4=x2+x3+2, excluding x1+x4=c+d, b+d, since those are smaller than a+b and a+c, respectively.
From [4] we obtain a>=c+2, b>=d+2, thus a+b>=c+d+4, excluding x1+x4=a+b.
Also a>=b+1, c>=d+1>=2 [3], so if a+c=x1+x4, we get a=b+1 and c=d+1. So x4=10+c-a-1, x3=10+c-a, x2=a-c-2, x1=a-c+1. Consequently x4-x3=-1, so x3>x4, meaning x4=c, x3=b. Thus x1=a=a-d, which contradicts [3].
Now consider x1+x4=a+d. x4-x1=10-2a+2d=3d-a. x1=a-d must be in {a,d}, due to [3] this means that 2d=a. Now d+2d=3d=10. That is impossible for d integer.

Thus we are left with x1+x4=b+c=10 and x2+x3=a+d=8. Remember, that x4=10+d-a, x3=10+c-b-1=9+c-b, x2=b-c-1, x1=a-d. Again consider x4-x3=d-a+c-b+1. d-a<0 and c-b<0 are obvious due to [4]. Thus x4-x3<0, meaning x3>x4, implying x3=a, x2=d.
Now consider x4-x1=10+2d-2a, with a=8-d, we obtain x4-x1=10-16+4d=-6+4d. That leaves two cases: x4>x1, if d>=2, or x1>x4, if d=1.
Consider d>=2. This implies a<=6, b<=5, c<=4, due to [4]. Thus b+c<=9, contradicting b+c=10. That leaves x1=b>x4=c and d=1,a=7. Since x1=a-d=6, we obtain b=6, c=4 and our non-trivial code is 6174.

For those interested the Algorithm is known as Kaprekar's routine. In the advent calendar cited as origin, this was task 15 "Safe cracking" in 2023, with both their (slightly simpler) task and solution available in english.

Edit: corrected typo
 
Last edited:
Sorry, wasn't available this week-end.
As for those "find the next element" types of puzzles, they're not my favourites, but it's more of the hit-or-miss kind.
Some I find clever and interesting, others elicit more of a "oh yeah? whatever" reaction. ;)

This one is made harder because you don't know how to parse it (I suppose it's deliberate): are you looking for the figure which completes the row? the column? the whole square? all of that? none of that?
 
Last edited:
Top Bottom