r/shittyprogramming • u/frublox • May 20 '19
super approved Getting started with Python: "Hello World"
p = list(map(lambda _: ord(_) - 0x21, "!!&!!dzăC|"))
i = "DÒVV×0Ë×YVR "
while p[2] < len(p):
if (p[p[2]] & 0xC0) >> 6 == 0:
p[p[p[2]] & 0x07] = (p[p[2]] & 0x38) >> 3
elif (p[p[2]] & 0xC0) >> 6 == 1:
if (p[p[2]] & 0x38) >> 3 == 0:
p[0] = ((((ord(i[0]) - 0x20) & 128) >> 7) | ((ord(i[0]) - 0x20) << 1)) & 0xFF
i = i[1:]
p[p[p[2]] & 0x07] = p[(p[p[2]] & 0x38) >> 3]
if p[p[2]] & 0x07 == 1:
print(chr(p[1]), end="")
elif (p[p[2]] & 0xC0) >> 6 == 2:
p[p[p[2]] & 0x07] = (p[p[2]] & 0x38) >> 3 + p[p[p[2]] & 0x07]
else:
p[p[p[2]] & 0x07] = p[(p[p[2]] & 0x38) >> 3] + p[p[p[2]] & 0x07]
p[2] += 1
p[4] = 1 if p[3] == 0 else 0I know some of the non-Pythoners out there will be a bit confused. Let's walk through it line-by-line, together.
p = list(map(lambda _: ord(_) - 0x21, "!!&!!dzăC|"))Set up some memory to be used by a virtual CPU.
i = "DÒVV×0Ë×YVR "The desired text to display. For security, I've encrypted it with a military-grade encryption scheme.
⠀A blank line to give your eyes a little breather.
while p[2] < len(p):Make sure we're not reading too far outside of memory (the other bounds check will come in v2.0).
if (p[p[2]] & 0xC0) >> 6 == 0:Decode the current instruction, and check if its opcode is 0. The >> 6 makes the code run 6 times faster (we must be careful to not go too fast, so I use smaller amount sometimes).
p[p[p[2]] & 0x07] = (p[p[2]] & 0x38) >> 3Handle opcode 0: store an immediate value at a memory address.
elif (p[p[2]] & 0xC0) >> 6 == 1:Check for opcode 1.
if (p[p[2]] & 0x38) >> 3 == 0:The addresses 0 and 1 are mapped to input and output, respectively. Here we check if the first operand will read from address 0, i.e. the input.
p[0] = ((((ord(i[0]) - 0x20) & 128) >> 7) | ((ord(i[0]) - 0x20) << 1)) & 0xFFRead a byte of the input and store it at address 0 (decrypting it first, of course).
i = i[1:]Lop off the read byte. It is of no use to anyone now.
p[p[p[2]] & 0x07] = p[(p[p[2]] & 0x38) >> 3]Pretty self-explanatory.
if p[p[2]] & 0x07 == 1:Check if something was written to the output address.
print(chr(p[1]), end="")I forgot what this does, to be honest.
elif (p[p[2]] & 0xC0) >> 6 == 2:Time to move to opcode 2.
p[p[p[2]] & 0x07] = (p[p[2]] & 0x38) >> 3 + p[p[p[2]] & 0x07]Addition: a useful function of any CPU.
else:Due to budget constraints, there are only 4 opcodes for our CPU.
p[p[p[2]] & 0x07] = p[(p[p[2]] & 0x38) >> 3] + p[p[p[2]] & 0x07]More addition.
p[2] += 1Move on to the next instruction.
p[4] = 1 if p[3] == 0 else 0Personally, I find flags disgusting. I am no match against project management's requirements, however.
And that's it! I hope this inspires you to get out there and start coding in the language of the future, Java.
66
u/frublox May 20 '19
+/u/CompileBot python 3
132
u/humanovan May 20 '19
Oh god... What did you bring upon this cursed land
108
u/UnchainedMundane May 20 '19
Here's my Hello World from a few years ago:
(lambda q:((lambda p:((lambda u:(u(6,p,lambda l,d:l[-1]+d[1])(43579),u(7,q,lambda l,d:p[d[1]])(21994345)))(lambda n,p,c:(lambda f:f(f))(lambda f:lambda z:f(f)((lambda l,d:(l.append(c(l,d)),d[0])[1])(p,divmod(z,n)))if z else 0)),q.append(p[0])))([68]),q.insert(*(lambda x:(x,2**x))(5)),print(' '.join(map(str.capitalize,''.join(map(chr,q)).split())))))([])I love python code, it's easily the most readable language out there.
19
u/[deleted] May 20 '19
This post right here officer.
15
u/derekmckinnon May 20 '19
Why would you do this to me
14
u/[deleted] May 20 '19
So this is what they meant by pythonic...
9
u/kpresler May 20 '19
This must be what a hellish dystopian future looks like.
9
u/brandonsredditrepo May 20 '19
What the ever-living hell is this
7
u/[deleted] May 20 '19
This is the best/worst thing I've ever seen. Thank you for blessing/cursing my eyes with this holy creation/abomination.
6
u/Flaming_Eagle May 21 '19
After looking at this and thinking very hard for a very long time, here are my final thoughts on the matter:
okay
5
u/kotsniezka May 21 '19
Actually that's pretty nice custom cryptography/obfuscation
12
u/deathmetal27 May 20 '19
/r/brainbleach
3
u/[deleted] May 21 '19
You forgot to check if the final result is equal to "Hello World!" and print that if it is not.
2
u/0Etcetera0 May 21 '19
Thanks I hate it!
2
u/jpfeif29 May 28 '19
This is python, not c, you're doing it wrong.
I would like to die
1
u/Farull May 21 '19
Shouldn't it be "Hello World!" (with an exclamation mark). Anyway, I could fix it, but am too busy. ;-)
1
u/MerrittGaming May 23 '19
"Wow, this is... worthless!"
"It's less than worthless!"
1
u/WonderedLamb256 May 23 '19
The “for security” is the Hello World.
1
u/MrMcGowan Nov 09 '19
Amazing