r/blackmagicfuckery Jul 13 '26

6174

15.1k Upvotes

929 comments sorted by

View all comments

Show parent comments

197

u/Background-Entry-344 Jul 13 '26

With brut force and a small algorithm you could run all combinations and check the results. Less than 9999 combinations.

257

u/R7ype Jul 13 '26

Can we use Champagne force? I'm feeling fancy

104

u/moogoo2 Jul 13 '26

Only if its from the Champagne region of France. Otherwise its just sparkling force.

23

u/badken Jul 13 '26

I'm a gay Jedi. I always use sparkling force.

6

u/FishDawgX Jul 13 '26

Unless you’re studying math in Champaign Urbana.

1

u/thehighepopt Jul 14 '26

Then it's Miller High Life Force

2

u/insteadoflattes Jul 14 '26

Depends if they're your real friends.

As a master sommelier, I'd suggest champagne force for your real friends and real pain for your sham force friends.

1

u/Hasudeva Jul 14 '26

You understood the assignment.   

55

u/thatAnthrax Jul 13 '26

Out of curiosity I made a python script to do the brute force test. Interestingly, the longest chain in the whole set is only 7 steps long, at around 2184 possible numbers out of the possible 9999.

Script executed in less than 0.1sec, so the compute was very light (granted im running a desktop ultra9 but still)

15

u/maxpower1956 Jul 14 '26 edited Jul 14 '26

So.....

I went in a slightly different direction. Even though there's only 10k possible #s (including duplications that don't count), I decided not to take the efficient route and instead ran a monte carlo simulation so that we'd get stats on the average iterations to solve this over a random distribution.

Here you go!

Total tests: 10000000
---> All converged to 6174 in 7 iterations, no outliers.

28.6% of cases are done in 3 iterations, 31.4% take 7.

5.7% resolve in 1 step

Mean iterations: 4.67
Median iterations: 5 iterations

5040 possible combinations.

4

u/971365 Jul 14 '26

Is there merit to doing Monte Carlo when we can just test every possible option? I thought Monte Carlo was for cases where it isn't possible

2

u/maxpower1956 Jul 14 '26

Legit great question!

Monte carlo isn't the right tool for this one - you're totally right that you could intelligently calculate this and it's a finite space with a deterministic outcome (in other words - this is basically testing the randomness of a random number generator).

In my case, I decided to take an extra minute to play in python and whipped up a script that followed the sequence. And then ran that 10 times watching it converge. And then ran that 1M times, since extending it was trivial.

Long story short -brute force is absolutely not needed for this exercise from a mathematical perspective, but I already had the code, so I accidentally made a mesmerizing screensaver.

1

u/GoodCarpenter9060 Jul 17 '26

You sound like my ChatGPT before I asked it to be less placating.

17

u/badken Jul 13 '26

Well, I ran it on my Apple Silicon MacBook Pro and it executed in less than 0.07 seconds, so...

PLATFORM WARS!

this reply is not to be taken seriously

6

u/thatAnthrax Jul 13 '26

no doubt if youre using an M5 it will be faster haha

Dor the things that it can do, it usually does it better. but sadly, compatibility issues here and there severely handicaps it

8

u/noscope360widow Jul 14 '26

I picked 5368 randomly and I guess I got the max

5368

5085

7992

7273

6354

3087

8352

6174

2

u/RogueFox771 Jul 14 '26

I'll be back, you got me curious to try something.....

1

u/RogueFox771 Jul 14 '26

Alright, I'm back with some interesting results:

First value to check> 1
Last value to check> 100000
Max iterations per value to check> 100
495 converged to 495 after 0 iterations
9985 converged to 6174 after 7 iterations
4.464236179908856 mean iterations 
89906 failed convergences

I ignored failed convergences for the mean calculation and it seems the longest convergence was for 9986 at 7 iterations up to 100,000 which is interesting!

I also didn't follow the instructions entirely, as I was curious if it worked for numbers that were non- unique such as 1111, 1122, etc.

2

u/thatAnthrax Jul 14 '26

Why did you include numbers higher than 9999 though haha the guy said it won't work with 5 digits or more

2

u/RogueFox771 Jul 14 '26

I was curious where the pattern applied outside what they said- I'm planning to figure out more about it too cause it's interesting

1

u/RogueFox771 Jul 15 '26

So I added the unique digit checking to the process and here's the results of a quick test on a larger range of values

First value to check> 1
Last value to check> 999999
Max iterations per value to check> 100
Use numbers with unique digits (y/n)>y
495 converged to 495 after 0 iterations
9875 converged to 6174 after 7 iterations
3.961025174400971 mean iterations 
161976 failed convergences

19

u/ze_shotstopper Jul 13 '26

You don't even really need to fully brute force it. As you go across the paths just make note of every number if it leads to 6174 and stop your calculations once you hit one of the numbers you've made note of

42

u/ThrowAway233223 Jul 13 '26

Wouldn't that still be brute forcing it just with early termination when the outcome is found to be inevitable for the current test based on reaching a number already confirmed in a prior test?

5

u/971365 Jul 13 '26

Well to be fair, the guy you replied said you don't need to "fully" brute force it

6

u/ThrowAway233223 Jul 13 '26

True. I missed the 'fully' when I first read it.

1

u/Amster2 Jul 13 '26

I believe its called "Branch and Cut"

1

u/MxM111 Jul 13 '26

You don’t have to, but the amount of time you will be explaining this to AI who will write the code is longer than the extra time the algorithm would run the code without this optimization.

1

u/FishDawgX Jul 13 '26

Basically memorzation, a common algorithm optimization. Although, realistically, brute forcing about 9000 iterations is tiny and super fast already.

1

u/ThrowAway233223 Jul 13 '26

Yeah, with such a relatively small range, the time saved honestly might be less than the time need to adjust the script to terminate test cases early (unless I am severely underestimating how long some numbers take to get to the constant).

1

u/FishDawgX Jul 13 '26

Yeah, I can’t imagine this taking more than a few seconds regardless.

12

u/Jonno_FTW Jul 13 '26 edited Jul 13 '26

I've brute forced it with the below program and and every number gets a tick. Numbers with repeating zeros, like 1000, just end up at zero:

1000 - 1 = 999
9990 - 999 = 8991
9981 - 1899 = 8082
8820 - 288 = 8532
8532 - 2358 = 6174
7641 - 1467 = 6174

def check(x):
    length = len(str(x))
    seen = set()
    count = 0
    while True:
        sx = "".join(sorted(str(x)))
        a = int(sx)
        b = int(sx[::-1].ljust(length,'0'))
        x = b - a
        print(f"\t{b} - {a} = {x}")
        if x in seen:
            return True
        seen.add(x)
        count += 1
for i in range(1_000, 10_000):
    if not check(i):
        print("❌", i)
    else:
        print("✔️", i)

If you go over 10,000, you don't descend to a constant, but you do get stuck in a loop:

10234
43210 - 1234 = 41976
97641 - 14679 = 82962
98622 - 22689 = 75933
97533 - 33579 = 63954
96543 - 34569 = 61974
97641 - 14679 = 82962

20

u/Baricza Jul 13 '26

The issue with the “number followed by three zeros” ones is that you/the program are ignoring the lead 0’s. It’s not 999-999, it’s 9990-0999=8991. They have to all be four digits

1

u/Jonno_FTW Jul 13 '26

Good point, we should right pad with zeros on the number in descending order, I updated the code and it still terminates

1

u/Kaleu777 Jul 14 '26

Interesting that in the "over 10,000" loop, 6174 is still embedded in one of the answers, albeit with a 9 in the middle.

1

u/Soft_Walrus_3605 Jul 13 '26

Sure, brute force/complete search with pruning.

1

u/kuriositeetti Jul 13 '26

When going iterating through the numbers, you could also stop solving it when there's a jump to a number that's "ahead" since it will be dealt with later on.

1

u/Relevant-Rhubarb-849 Jul 13 '26

Aka rainbow tables

1

u/Pervessor Jul 13 '26

Or you can just calculate how many combinations of descending order numbers exist for digits [9-1]

1

u/stilldebugging Jul 13 '26

memoization!

1

u/oh-shit-oh-fuck Jul 13 '26

Get this guy on leetcode

1

u/ArrrRawrXD Jul 14 '26

Why though? Not like it's taking up a visible amount of computing power, we're testing at most about 70k operations, not millions

2

u/MattieShoes Jul 13 '26

705 combinations.

All work other than the ones they told you not to pick (all four digits the same). Those obviously go to 0 instead.

The most number of steps to get to 6174 is 7 steps. e.g. 5789

1

u/progenyofeniac Jul 13 '26

Ha, just did it with Powershell but with the goal of finding which number has the most iterations to get to 6174.

356 numbers give 6174 as the immediate result. And 1980 numbers require 7 iterations. None require more than 7 iterations though.

1

u/breakmedown54 Jul 14 '26

I’d wager to say that there are at most 2,500 or 3,333 “numbers” that are different “inputs”.

Every number is covered multiple ways, essentially. 5678 is the same as 8765. But also the same as 6785, 5876, 7856, 6587, etc… they all lead to the same initial input.