r/ProgrammerHumor • • Jun 06 '20

It's the law!

Post image
38k Upvotes

1.1k comments sorted by

View all comments

Show parent comment

69

u/frosted-mini-yeets Jun 06 '20

None of you have ever had nested loops and gone i, j, k, l?

57

u/MattTheGr8 Jun 06 '20

I do a weird thing and skip L and go right to M, to avoid confusion between lowercase L and numeral 1, which look identical in some monospaced fonts.

135

u/_zsa Jun 06 '20

If you nest 4 for loops you should apologize and retire.

35

u/xorgol Jun 06 '20

My defense to all criticism is that the choices were driven by domain-specific issues. It's not necessarily true, but it sure shuts people up :D

14

u/splendidsplinter Jun 06 '20

just claim it's a heuristic

→ More replies (1)

9

u/why_rob_y Jun 06 '20

Or write a sequel to Primer.

→ More replies (3)

25

u/LonelyContext Jun 06 '20

My record is 26 in solving ProjectEuler #96:

import extended as xt
import numpy as np
from tqdm import tqdm
import sympy as sp
sum([int(''.join([str(z) for z in y[0,:3]])) for y in [xt.nest(lambda f: [[np.vstack([g[:f[1]],[[w[x] for x in range(9)]],g[f[1]+1:]]) for g in f[0] for l in [np.array([g[:3,:3],g[:3,3:6],g[:3,6:],g[3:6,:3],g[3:6,3:6],g[3:6,6:],g[6:,:3],g[6:,3:6],g[6:,6:]]).reshape([3,3,9])] for p in [[h([k,l[f[1]//3, m//3],g[f[1]]]) for m,k in enumerate(g.T)]] for q in [[n for n,o in enumerate(g[f[1]]) if o==0]] for s in [[n for n,o in enumerate(g[f[1]]) if o!=0]] for t in sp.utilities.iterables.cartes(*[p[r] for r in q]) for w in [{**dict(zip(q,t)),**{u:g[f[1]][u] for u in s}}] if len(t)==len(np.unique(t))], f[1]+1],([[e],0]),9)[0][0] for h in [lambda i: [j for j in range(1,10) if j not in sp.utilities.iterables.flatten(i)]] for a in [open('sudoku.txt').read()+'\n'] for b in tqdm(a.split('Grid')[1:],position=0,leave=True) for e in [np.array([[int(d) for d in c] for c in b.split('\n')[1:-1]])]]])

40

u/BattlePope Jun 06 '20

You've managed to make python ugly

9

u/Rellac_ Jun 06 '20

This is what most people see when they look at normal code

→ More replies (1)

0

u/[deleted] Jun 06 '20

[deleted] — view deleted comment

6

u/JuniorSeniorTrainee Jun 06 '20

But look how compact it is! 🙄

11

u/JohnDoen86 Jun 06 '20

That is terrifying

6

u/BattlePope Jun 06 '20

It's brutality

8

u/deljaroo Jun 06 '20

omg surely you could have done that in separate lines

8

u/coldnebo Jun 06 '20

“oh no, vectorization sounds too complicated, I’ll just write some loops”

8

u/HodortheGreat Jun 06 '20

Eli5 vectorization vs loops for a newbie? :)

4

u/coldnebo Jun 06 '20

Say you have an apple orchard full of trees with ripe apples on them.

nested loops: I’m going to pick each apple one at a time from this tree, then go to the next tree and pick those apples, and so on until I’ve picked all the apples.

vectorization: I’m going to hire one person for every tree and ask them to pick all the apples in parallel and put them in the truck when they are done.

→ More replies (1)
→ More replies (1)
→ More replies (13)
→ More replies (4)

34

u/[deleted] Jun 06 '20

Once you reached the end of the alphabet you may be in some deep trouble.

That's some serious O(n4 ) shit you got going there, kiddo. Better hope n is small any you never need to debug that mofo.

9

u/AndrasKrigare Jun 06 '20

I just make every line of my code in a loop that runs once. That way if I every need to make a loop, the structure is all there.

6

u/[deleted] Jun 06 '20

You sick, sick bastard.

→ More replies (3)

6

u/[deleted] Jun 06 '20

I try and find some sane representation in that case. Even if it's still a letter I'd use the first letter of what it is if that makes sense. Makes it easier to follow in the future.

Eg if you had book, page, word, letter I might use b, p, w, l.

18

u/B4-711 Jun 06 '20

why not just use book, page, word, letter? makes for some very readable code.

→ More replies (4)
→ More replies (17)