# Determine the algorithm

So I was given this puzzle quite some time ago and just thought it would make a nice addition to this site:

Your task is to determine the method how the result is determined from the given number. A few example cases include:

177383 -> 2
267453 -> 2
111111 -> 0
636240 -> 4
367183 -> 3
247123 -> 1
369108 -> 5


To those, who hit a brick wall, here is a tip: This puzzle is easiest for young children and gets harder the older you get... Happy guessing ;)

• Nice hint. It is really great. – Always Confused Jan 28 '17 at 9:52

The number is the number of "holes" in the written decimal representation of the number.

More specifically, each digit contributes this much to the total number:

0: 1
1: 0
2: 0
3: 0
4: 0 or 1, depending on how you draw them
5: 0
6: 1
7: 0
8: 2
9: 1


In your case above, 4 is drawn with a hole, so it contributes 1.

• No spoiler here because there really isn't much I could leave exposed if I did choose to hide all the important details. – Joe Z. Nov 30 '14 at 17:56
• Damn, you're all too good ;) – ThreeFx Nov 30 '14 at 17:56
• This is right, but 0 has 2 holes, at least in the font used. I'm kind of surprised that you got it right even with this happening. – mdc32 Nov 30 '14 at 17:57
• It's more a function of having seen these puzzles before. They're chestnuts. – Joe Z. Nov 30 '14 at 17:57
• @mdc32: on the font that I'm using, 0 has only a single hole. – Joe Z. Nov 30 '14 at 17:57

I included mathematics :)

The method is as follows:

2. If step $1$'s result has a $9$, subtract $2$
3. If step $1$'s result has a $6$, add $1$
4. If the original number has a $0$, multiply by $2$ then subtract $4$
6. Mod $7$ step $5$'s result

Now use this method on your numbers:

$1+7+7+3+8+3=29$
$29-2=27$
$2+7=9$
$9\equiv2\mod7$

$2+6+7+4+5+3=26$
$26+1=27$
$2+7=9$
$9\equiv2\mod7$

$1+1+1+1+1+1=6$
$6+1=7$
$7=7$
$7\equiv0\mod7$

$6+3+6+2+4+0=21$
$21\times2-4=38$
$3+8=11$
$11\equiv4\mod7$

$3+6+7+1+8+3=28$
$2+8=10$
$10\equiv3\mod7$

$2+4+7+1+2+3=19$
$19-2=17$
$1+7=8$
$8\equiv1\mod7$

$3+6+9+1+0+8=27$
$2\times27-4=50$
$5+0=5$
$5\equiv5\mod7$

• Not what I was looking for, but creative :D – ThreeFx Dec 1 '14 at 7:16
• @ThreeFx damnit :D – Abraham Zhang Dec 1 '14 at 7:27
• In general, when the number of rules is equal or close to the number of cases, then the rules are made up to fit the data. – Florian F Dec 1 '14 at 8:24
• I know this is for fun, but your equation breaks on 600000 :) +1 for you – Brian J May 8 '15 at 19:11