def values():
for M in range(1, 10):
for O in range(1, 10):
if valid(10 * M + O, 1):
for T in range(1, 10):
for U in range(1, 10):
if valid(10 * T + U, 2):
for W in range(1, 10):
if valid(W, 3):
for H in range(1, 10):
if valid(10 * T + H, 4):
for F in range(1, 10):
if valid(F, 5):
for S in range(1, 10):
if valid(10 * S + U, 7):
for A in range(1, 10):
if valid(10 * S + A, 6):
if len(set(locals().values())) == 9:
return locals().copy()
I hate to say it but assuming valid() is linear, then it’s O(n), and it’s only O(n) because of the last conditional that constructs a set from an iterable. All the other loop ranges are constant, so they’re each just O(1).
Like one minute? Every loop runs in a constant range so you can ignore them all immediately. Then you just have to look at any other operations it does, which are call ‘valid()’ and build a set out of ‘values’. The time complexity will just be the larger of those two operations.
I think this is not that hard, IIRC old terminal fonts were 1:2 (8x16 maybe) which is most probably the same with many “modern” monospace fonts. (of course the resolution is different) This gives us y=2x which is still a pretty cute equation.
If you want to get rid of the nesting hell, you can use a comprehension:
def values():
return next(
dict(M=M, O=O, T=T, U=U, W=W, H=H, F=F, S=S, A=A)
for M in range(1, 10)
for O in range(1, 10)
if valid(10 * M + O, 1)
for T in range(1, 10)
for U in range(1, 10)
if valid(10 * T + U, 2)
for W in range(1, 10)
if valid(W, 3)
for H in range(1, 10)
if valid(10 * T + H, 4)
for F in range(1, 10)
if valid(F, 5)
for S in range(1, 10)
if valid(10 * S + U, 7)
for A in range(1, 10)
if valid(10 * S + A, 6)
if len({M, O, T, U, W, H, F, S, A}) == 9
)
48
u/Dragenby Aug 26 '21
What was it used for?
33
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Aug 26 '21 edited Aug 26 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
9
u/lachlanhunt Aug 26 '21
What is the actual output from that? What is the
validfunction?3
u/spotter Aug 26 '21
I loved the ending, 10/10 would descent into madness again.
243
u/[deleted] Aug 26 '21
somebody call the police
87
u/RedRedditor84 Aug 26 '21
What. The fuck?
168
u/[deleted] Aug 26 '21
O(wtf)
47
u/coolj492 Aug 26 '21
How tf do you even begin to debug this
26
u/netsutetsu Aug 26 '21
Angry Guido noises
25
u/StaryMD Aug 26 '21
The title is the most beautiful thing I've seen today
4
u/BenzamineFranklin Aug 26 '21
I LOVE your username
3
u/assembly_wizard Aug 26 '21
If you want to get rid of the nesting hell, you can use a comprehension:
Slightly more readable, at least IMO
4
u/greenpepperpasta Aug 26 '21
This could have been made a lot cleaner....
just use goto's and you don't have to worry about all that ugly indentation.
1
u/[deleted] Aug 26 '21 edited Jan 14 '22
.
1
u/dimonoid123 Aug 26 '21
You had to write a one - liner instead.
1
u/iamafraazhussain Aug 26 '21
Legend has it that the loop is still running to this day...
1
u/JustJude97 Aug 26 '21
Slide to the right!
1
u/wexabit Aug 26 '21
This can't be real... right?
1
u/Linux_ka_chamcha Aug 26 '21
I love this neighborhood
1
u/Cabinet-Dismal Aug 26 '21
Time for a new career field
1
u/[deleted] Aug 26 '21
If someone put this in a PR, I would delete the whole damn branch myself.
1
u/hypekk Aug 26 '21
is that yandere simulator leak
1
u/burritoboy76 depraved Aug 26 '21
Kids this is why you comment on your code
1
u/[deleted] Aug 27 '21
stairway to heaven
1
u/Python_Lab2021 Aug 27 '21
I hope it works...))
1
u/AHeroicLlama Aug 26 '21
I hate that font, the o on line 3+4 looks like a 0.
0
u/mysteriousOmlette Aug 26 '21
Use enumerate instead of range(len(iter)) you uncultured swine.
-2
u/iamasuitama Aug 26 '21
This code is 100% only good for memory leaking like a motherfucker