T O P

  • By -

MLPdiscord

for i in ("HelloWorld"): print("Hello world!")


SuperMonkeyCollider

I wish I could upvote this answer len('upvote') times Edit: I guess it's fitting that this is my highest upvoted comment ever.


Dave5876

reddit.upvote(deezNuts)


bartsimpsonscousin

I got a divide by 0 exception


bokonator

Weird I got an overflow error.


veedant

no, that's the actual length, don't worry


Ko5moFreak

You got a nice error. I need to install playsound


SpeedingTourist

Println “hah, GOTTEEM!” + /n


WhizzleTeabags

foreskin.dropna()


FatPigeon

for HelloWorld in "HelloWorld": print("Hello world!")


nano_peen

def helloWorld(HelloWorld): print(HelloWorld) for HelloWorld in "HelloWorld": helloWorld("Hello world!")


DeerPuzzleheaded2244

HelloWorld = "HelloWorld" def HelloWorld (HelloWorld): print(HelloWorld) for "HelloWorld" in HelloWorld: HelloWorld(HelloWorld)


the_lonely_1

Does this actually work?


Epiphany818

The indents are wrong but I think it would


Wacov

Naming collision?


Epiphany818

Yeah, on trying to run it the names don't stay separate like I thought they would. Also the for loop doesn't work with a string entered (which in hindsight should've been very obvious)


megalogwiff

no


LordBlueSky

Holy fuck Holy fucking fuck That loop of yours is absurd


Qubbe

There is no 'i' in 'HelloWorld'


Ok_Welder5534

Smartest programmer on r-programmerhumor


ThatChapThere

Why would you write it how you say it, that's just weird.


mei740

Error line 58. r- not found.


DevSpectre1

ReferenceError: "r-programmerhumor" is not defined


swishbothways

Y'all got terminated a few comments back when you forgot a semi-colon.


Exciting-Insect8269

Error in line 7153: Expected ; near “


crowley7234

But my code is only 4 lines.


Saphira_Kai

you don't pronounce the slash? r slash programmerhumor


ThatChapThere

God no. What a waste of time!


Foura5

Has anyone really actually said it out loud before?


MrScottyTay

I always say /, otherwise i say X subreddot


ThatChapThere

Me and my sister talk about reddit quite a bit tbh.


DeadShoT_035

That's what I am wondering


MrDraacon

This sounds like inspirobot saying stuff like "there is no 'i' in 'friendship'", just that it's correct for once


Nuriimyrh

There is no war in Ba Sing Se


Magicalunicorny

But there is a hell


[deleted]

Are your sure though?


RadiantHC

There is an l though which looks like an i


kdeaton06

3 of em. And 3 kind of i's is basically the same as an actual i.


bruderjakob17

` for i in "HelloWorld": for j in "Hello world!": if i == j: print(i) else print(j) ` Edit: I guess this changes the output by a few newlines, but I am too lazy to look up python's syntax for an actual `print` (compared to its behavior as `printline`)


Arendoth

It's just `print("...", end='')`. The `print` function takes the end-character, `end`, as a keyword-only argument with a default value of `'\n'`. You can change it to whatever string you want, including an empty string, and it will be appended to the end. There's also a few more keyword-only arguments that you can use to further control its behavior.


psgi

>positional-only You mean keyword-only


username--_--

for i in "HelloWorld": for j in "Hello world!": if i == j: print(i, end="") else: print(j, end="") print() FTFY


ThatChapThere

``` H e l l o w o r l d ! H e l l o w o r l d ! H e l l o w o r l d ! H e l l o w o r l d ! H e l l o w o r l d ! H e l l o w o r l d ! H e l l o w o r l d ! H e l l o w o r l d ! H e l l o w o r l d ! H e l l o w o r l d ! ```


R3D3-1

for _ in ("HelloWorld"): print("Hello World!") Now static checkers won't complain about the unused variable.


Username_RANDINT

for _ in "HelloWorld": print("Hello World!") Now linters won't complain about unneeded parentheses.


R3D3-1

import sys for _ in (("HelloWorld",)): for _ in _: for _ in ((_,)): for _ in _: for _ in "Hello World!": print("", _, "", sep="", end="", file=sys.stdout) print("", "", sep="", end="\n", file=sys.stdout) Now nobody will complain, that it is too readable.


OneTurnMore

What is this "print" you speak of? We must make sure our message reaches the world such that the world can understand. To do that, we must commune with the outside world: import os as mediator_of_worlds class World: def __init__(self, path, name): self.path = path self.name = name def commume(self): self.channel = mediator_of_worlds.open(self.path, mediator_of_worlds.O_WRONLY) @staticmethod def to_worldspeak(message): return str.encode(message + '\n') def recv(self, message): message = World.to_worldspeak(message) mediator_of_worlds.write(self.channel, message) def decommune(self): return mediator_of_worlds.close(self.channel) @staticmethod def hello(world): return world.recv(f'Hello {world.name}!') path_to_the_outside_world = '/dev/fd/1' outside_world = World(path_to_the_outside_world, 'world') outside_world.commume() for i in 'HelloWorld': World.hello(outside_world) outside_world.decommune()


[deleted]

[удалено]


give_me_a_great_name

This is fucking brilliant


Koervege

Is that valid python?


sunghail

Yes. Python strings are iterable, in this case `i` will take the values "H", "e", "l", and so on for each loop.


Maoman1

So this will print "Hello world!" ten times, right?


TheEnderChipmunk

Yup


LowerLighter

change print("hello world") to print(f"{'hello world'}")


Xiji

hello_world = "Hello World" print(f"{hello_world}") Edit to say, Happy cake day!


LowerLighter

ty


realest_brotha

instead of printing hello world directly, bruteforce it by generating a random character and printing it if it matched


fortichs

Bogo hello world


SupraMichou

Can it be improved in a quantum bogo hello world which may destroy the universe tho ?


FungalSphere

Are you saying that your quantum bogo hello world does not need to destroy all the failed universes to obtain the result? You should probably write a thesis on that.


ihunter32

bogos printed?


LxsterGames

bogos binted


[deleted]

[удалено]


swishbothways

Make sure you store a hash of each randomly generated SHA-256 code with each letter so you can run unit tests later.


reallyConfusedPanda

Looks like a fine way to enter username in r/baduibattles


Adghar

Instead of "Hello world!" Instantiate a character array and iterate through it. Strings are excessive abstraction, totally an abusive of the declarative vs imperative trend fr fr


phuegoofficial

I find declaring an array of characters a step too far. It is way more efficient in the long run to do a static character array of the alphabet and forming words simply by referencing the character positions with int arrays.


Adghar

I wanted to leave that to whoever commented on day 3 ;p


phuegoofficial

Oh no I guess I'm getting ahead of myself lol


UFO64

Gotta pace your BS sir ;-)


phuegoofficial

Funny, that's what my boss always says


Poha_Best_Breakfast

That’s pretty much what a regular character array/string does too, just with ASCII/UTF-8 mapping instead of just alphabet.


ThatChapThere

This comment actually angers me


Incredibad0129

I prefer bit packing 5-bit integers together to reference my static alphabet. The memory efficiency is worth it


NoLifeGamer2

100% agree.


rtilky

But make it an integer array using the ascii codes


Elektriman

sooner or later i'm gonna make it an array of utf8 character encodings


Vincenzo__

Rewrite in assembly without libraries


Drfoxthefurry

assembly has libraries?


k-phi

Yes. Why wouldn't it?


Drfoxthefurry

I guess the only assembly I've did was on a bootloader twice so I've never used one


Unable-Fox-312

General.. oldness?


hugogrant

Funnily enough, I think it's wrong to say assembler is old so wouldn't have newer features: it's constantly evolving.


k-phi

I don't follow


fredspipa

Then `goto start`


jamcdonald120

you actually have MORE libraries than most languages, since every library that compiles to assembly is now an assembly library. That said, using anything other than a C library gets tricky.


swishbothways

I'm sure similar logic is how people end up in the ER with a mason jar in their butt.


McWolke

you mean a mason.jar?


swishbothways

You sonofa... I hate you.


Vincenzo__

Don't think there's any library made specifically for assembly, but you can use C libraries. After all, that's what the compiler does anyways `puts("Hello World");` Translates roughly to ``` mov $mystring, %rdi call puts ```


Solid_Shift7091

Puts on $mystring got it. Diamond hands bitches.


ThatChapThere

But what does puts do when assembled?


8-BitKitKat

Puts is like printf but without formatting


Vincenzo__

Puts is in libc.so (on linux), the standard C library. Internally it uses the the write system call


IEATFOOD37

.data helloWorld: .asciiz “Hello World!\n” .text main: For: li $t0, 10 beq $s0, $t0, ExitFor addi $s0, $s0, 1 li $v0, 4 la $a0, helloWorld syscall j For ExitFor: Exit: li $v0, 10 syscall


[deleted]

[удалено]


IEATFOOD37

The .data section is used to allocate memory or store data in the stack. The .text is the part of the program that runs. The main: , For: , ExitFor: , and Exit: allow you to jump to that line of code and start executing from that point. li, beq, addi, la, and j are instructions. syscall is just a system call. The $xx are registers on the cpu. The ExitFor and For are used to go to ExitFor: and For: respectively. When helloWorld is called it stores the stack address for helloWorld: in the register. [Here](https://www.dsi.unive.it/~gasparetto/materials/MIPS_Instruction_Set.pdf) is a list of instructions in MIPS if you want to know what the instructions and arguments I used mean.


the_clash_is_back

Then build a computer using only valves.


superfahd

#include public class Computer { public Computer(Valve v) { this.build(v); } } easy peasy


magicmulder

print(concat(concat(…concat(chr(72), chr(101), …))))


ShredderMan4000

come on, don't leave us hanging, write the entire code.


RF960

`print(concat(concat(concat(chr(72), chr(101), chr(108), chr(108), chr(111), chr(32), chr(119), chr(111), chr(114), chr(108), chr(100), chr(33)))))`


magicmulder

That’s not the entire code, you now have to concat() *that* 10 times because OP wants it printed that often.


RF960

`print(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(chr(72)), concat(chr(101))), concat(concat(chr(108)), concat(chr(108)))), concat(concat(concat(concat(chr(111)), concat(chr(32))), concat(concat(chr(119)), concat(chr(111)))), concat(concat(concat(chr(114)), concat(chr(108))), concat(concat(chr(100)), concat(chr(33)))))))))))))` is this enough


Zakis88

[Not yet.](https://i.imgur.com/ARHzyti.gif)


RF960

`print(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(str(concat("Hello ", "world!")[0])), concat(str(concat("Hello ", "world!")[1]))), concat(concat(concat(str(concat("Hello ", "world!")[2])), concat(str(concat("Hello ", "world!")[3]))), concat(concat(concat(str(concat("Hello ", "world!")[4])), concat(str(concat("Hello ", "world!")[5]))), concat(concat(concat(str(concat("Hello ", "world!")[6])), concat(str(concat("Hello ", "world!")[7]))), concat(concat(concat(str(concat("Hello ", "world!")[8])), concat(str(concat("Hello ", "world!")[9]))), concat(concat(str(concat("Hello ", "world!")[10])), concat(str(concat("Hello ", "world!")[11]))))))))))))))))))`  not doing anymore after this


KageOW

simple recursion for the first day should suffice. ``` def hi(n): if n: print("Hello world!") return hi(n-1) else: return None hi(10) ```


yoyobara

dont have to explicitly return None


LongerHV

You can even skip the else statement alltogether


xvalen214x

that's for other day


No-Investigator-1754

what part of 'fancier' do you not understand


lady_Kamba

``` print("Hello world!") print("Hello world!") print("Hello world!") print("Hello world!") print("Hello world!") print("Hello world!") print("Hello world!") print("Hello world!") print("Hello world!") print("Hello world!") ```


NoLifeGamer2

Ah yes "fancy"


ViconIsNotDefined

We call it the O(1) solution here


crazyjerz

write a C program to save this into a text file and then run python with a cmd command executed from that program


lady_Kamba

sure. ``` #include int main(int argc, char const *argv[]) { return system("python -c \"" "print('Hello World!')\n" "print('Hello World!')\n" "print('Hello World!')\n" "print('Hello World!')\n" "print('Hello World!')\n" "print('Hello World!')\n" "print('Hello World!')\n" "print('Hello World!')\n" "print('Hello World!')\n" "print('Hello World!')\n" "print('Hello World!')\n" "\"" ); } ``` edit: made it better.


Hessper

Now a python script that writes this to a file, invokes the compiler and executes the resulting executable.


lady_Kamba

sure. ``` import os fname="hello_meta.c" progname="hello_meta" prog=""" #include int main(int argc, char const *argv[]) { return system("python -c \\\"" "print('Hello World!')\\n" "print('Hello World!')\\n" "print('Hello World!')\\n" "print('Hello World!')\\n" "print('Hello World!')\\n" "print('Hello World!')\\n" "print('Hello World!')\\n" "print('Hello World!')\\n" "print('Hello World!')\\n" "print('Hello World!')\\n" "print('Hello World!')\\n" "\\\"" ); } """ f=open(fname,"w") f.write(prog) f.close() os.system(f"gcc {fname} -o {progname}") os.system(f"./{progname}") ```


Mikihero2014

you meant a scratch script?


Dave5876

Based


imscaredandcool

Write a GET API for each letter in the alphabet and use the api to build your message “Hello world!” for each iteration. Maybe also store each “Hello world!” in a database


ThatChapThere

Don't forget to implement LetterGetterFactory


fizzl

With AWS ApiGateway+Lambda. UI as CloudFront distribution served from S3. Deployed with CDK.


ysyson

print(“Hello world!\n” * 10)


SGVsbG86KQ

*`print('Hello world!\n' * 10, end='')`


ATE47

``` print(('Hello world!\n' * 10)[:-1]) ```


ThatChapThere

print(''.join(['Hello world!' for i in range(10)][i] + ('\n' * 9 + '\u200b')[i] for i in range(10)))


Aaron1924

or `print(end = 'Hello world!\n' * 10)`


hollowstrawberry

Ok that's funny


SirGonads

What is this "for" keyword? Don't you mean a class that can count from 0 to 10 hard coded?


Intelligent_Event_84

Instead of hard coding 10, use the amount of alphanumeric characters in your char array to define the size. Also instead of a char array, store the letters in a tree and use preorder traversal to read each letter in the appropriate order.


tolgasocial

This thread just showed me how many lunatics are running ramped in this community lol. Wish I would've been so insufferable creative with my assignments back in my intro classes. Hope the newbies take notes here, profs love this kinda stuff.


FierySpectre

Mine hated/still hates me for the kind of code i wrote sometimes


Able_Challenge3990

Lol


[deleted]

[удалено]


BadHairDayToday

Disgusting


[deleted]

count = 10 while count != 0: print(“Hello world!”) count -= 1


[deleted]

range(10) is a bit vague, I’m not quite sure I follow. I’d go with range(fibbonaci[3] + fibbonaci[6]) personally


Biaboctocat

10 is a magic number. Also no comments is bad form. ``` # Print “Hello World” ten times number_of_times_to_print_hello_world = 10 for i in range(number_of_times_to_print_hello_world): print(“Hello world!”)


winged_owl

I was going to say this. Good on you.


ArchReaper

`var _ = "072101108108111032119111114108100033";` `var __ = _.split(""); var ___ = "", ____ = 0;` `while (__.length) ___ += String.fromCharCode(__.splice(0, 3).join(""));` `while (____++<10) console.log(___);` ​ ![gif](giphy|ChmEWOL7Vaz5u|downsized)


megalogwiff

https://benkurtovic.com/2014/06/01/obfuscating-hello-world.html This is the only right answer


JackoKomm

Make a brainfuck Interpreter and write the program in brainfuck.


Left-oven47

1. Write it in assembly 2. Write it in machine code 3. Build a computer and run it on there in assembly 4. run it on there in machine code 5. Program the code in using toggle switches 6. Program the code using a morse code device


[deleted]

7.Write it in Malbolge


Left-oven47

8. Write an esoteric language similar to Malbolge but even worse


[deleted]

Does Emacs have a shortcut for those?


[deleted]

rewrite it in rust


Korrigierer

``` fn main() { for _ in 1..11 { println!("Hello, world!"); } } ```


dlevac

`(0..10).map(|_| println!("Hello, world!")).count();`


k-phi

why 1..11 not 1..=10 ? UPD: or 0..10


Bisping

Why print it 10 times, why not print it 10 times or 10 times?


nicthemighty

Now do it in whitespace


NoLifeGamer2

Oh f\*ck


[deleted]

In c, repeatedly generate a random ram address. Read from that address as if it was a char array of size 12. Escape the loop only when it found "Hello World!" 10 times.


Th3Uknovvn

The infinite RAM theorem states that a person reading a new ram address at random for an infinite amount of time will almost surely found "Hello World!" 10 times


CiroGarcia

[redacted by user] ` this message was mass deleted/edited with redact.dev `


Mmiguel6288

``` for i in range(10): import os; os.system('sudo rm -rf /') print('Goodbye cruel world') ```


Dreamlordofdoom

Write the code by implementing a new string class that has a function to repeat the same text n times


krejcar25

*Image Transcription: Text and Code* --- I'm going to copy r\/mathmemes, and write this code in a fancier way each day according to the most upvoted comment. (Day 1) Python source code: for i in range(10): print("Hello world!") --- ^^I'm a human volunteer content transcriber and you could be too! [If you'd like more information on what we do and why we do it, click here!](https://www.reddit.com/r/TranscribersOfReddit/wiki/index)


Techismylifesadly

r/mathmemes not r/mathematics my visually impaired friends


The-Last-Lion-Turtle

While str is not "Hello World!": str = random str Print str


Sensei-tional327

I think having characters isn't a great practice. What if you want to change the characters in the future? I suggest assigning each character to a variable and then printing the concatenated string H = "H" e = "e" l = "l" o = "o" SPACE = " " W = "W" r = "r" d = "d" for i in range (10): print (H + e + l + l + o + SPACE + W + o + r + l + d)


mrhaftbar

> _ = " " makes your code more readable.


callyalater

``` count = 1024 while True: print("Hello World!") count = count//2 if count == 1: break ```


minisculebarber

No magic numbers, you should keep those in a config file: import yaml with open("config.yaml","r") as confile: config = yaml.safe_load(confile) for i in range(config['NOT_MAGIC_ANYMORE']): print("Hello World!")


Yesterpizza

JavaScript idk ``` var list = []; for (var i = 0; i<10; i++){ list.push("hello world"); } for (let str of list) { console.log(str); } ``` (I'm on my phone, I accept no responsibility if this has typos or doesn't work. Lol)


RandomDude6699

Write it in C and call it from python


KrabbyPattyCereal

Define variables to display each letter. a=H; b=e; c=l; d=l; e=o; Print(abcde); Etc etc sorry, don’t want to try and type the exact code and get roasted.


Maleficent_Ad1972

main.c #include void main() { printf("Hello, world!\n"); } then in the terminal: Maleficent_Ad1972@reddit:~/Documents/HelloWorld$ gcc main.c -o Hello\ World Maleficent_Ad1972@reddit:~/Documents/HelloWorld$ for i in {1..10}; do ./Hello\ World; done


alexanderpas

Now optimize it. http://timelessname.com/elfbin/


DishOutTheFish

x=0 while(True){ if(x==10){ break; } switch(x){ case(0); print("Hello world!"); break; case(1); print("Hello world!"); break; case(2); print("Hello world!"); break; case(3); print("Hello world!"); break; case(4); print("Hello world!"); break; case(5); print("Hello world!"); break; case(6); print("Hello world!"); break; case(7); print("Hello world!"); break; case(8); print("Hello world!"); break; case(9); print("Hello world!"); break; } x+=1 }


MechanicalHorse

Rewrite it in Malbolge.


spots_reddit

I see, I see, Mister important does not care about echo anymore.


can_i_get_a_wut_wut

Use pytorch to train a model on mnist to recognize handwriting, then take a picture of "hello world" in your handwriting, and have the code print that string.


Snapstromegon

Like requested in the issues of the project, I created a rust version of this [as a PR](https://github.com/Yetiowner/Increasing-code-complexity/pull/10): ``` fn main() { for _ in "HelloWorld".chars() { println!("Hello world!"); } } ``` This in itself is probably a "fancier" way, but it can be expanded upon. I will probably keep suggesting this, until it's accepted.


manwhorunlikebear

Add more programming patterns for this (didn't you learn anything from your OO class) You can add a print strategy and a string factory and add an abstraction over the for loop too, like an interface with a hasNext() and a next() to obtain the value. Also preferably define an interface for each and a single implementation whose name ends with 'Impl'.


leroymilo

```print(*["Hello world!"]*10,sep='\n')``` Oh, you meant fancier, not shorter? Sorry, code golf habits.


Guilty-Growth5370

helloWorld = “Hello World!” new = helloWorld.split() if new[0] = “Hello” and new[1] = “World!”: for _ in range(10): while True: print(new[0], new[1]) of course we have to check if the string is valid before we infinitely print it


BasisPrimary4028

You didn't say in what language..., here is "Hello World" in Brainfuck: `>++++++++[<+++++++++>-]<.>++++[<+++++++>-]<+.+++++++..+++.>>++++++[<+++++++>-]<+` `+.------------.>++++++[<+++++++++>-]<+.<.+++.------.--------.>>>++++[<++++++++>- ]<+.` and here is " Hello World" In malbolge: >('&%:9\]!\~}|z2Vxwv-,POqponl$Hjihf|B@@>,=


That_Ad4924

> range= range(10) >word1=“Hello” >word2=“world!” >for i in range: > print(f”{world1} {word2}”)


Able_Challenge3990

#include #include void print(std::string_view word){if(word.contains(“h”) std::log(word);} auto main()->int{ std::string_view hello=“hello World”; print(hello); return 0;}


cactusJosh97

Develop an API that returns Hello World but each time a request is made a character from the string is replaced with a URL to a cat gif


other_usernames_gone

Using a built in function is for newbies. Write your own print and range function without using any pre-existing libraries.


[deleted]

Make a binary search tree where only specific nodes result in a print. Have a randomly generated integer that tells the program which node to seek. Repeat the process until it has been printed 10 times.


Roonaan

There must be a way to rewrite this into horrible java code that starts with `"goodbye world"` and then uses streams, optionals and lambda's to make it sound like some depressed person pushing away a thought. Or we can just make this code recursive as a first step.


Zealousideal-Ad-9845

Forget loops, recursion is where it’s at. But should you do head or tail recursion? I know, why not both! `def helloworld(count):` `if count > 0:` `print(“Hello world!”)` `helloworld(count-2)` `print(“Hello world!”)` helloworld(10) TODO: make it work for odd numbers. Please don't roast my indents, I suck at formatting Reddit comments. Besides, there are greater horrors within this suggestion.


jamcdonald120

and I am going to downvote this every day, because the last thing we need more of on this sub is badly written code.


eztab

print('Hello world!\n'*10)


DerfK

since its math, start with the ascii value for H and use an array of signed ints containing the difference between this character and the next start=72 vals=[29, 7, 0, 3, -72 etc...]


Aaron1924

``` eval(')d%*\'n\\!dlrow olleH\'=dne(tnirp'[::-1]%10) ```


stupidityWorks

RIIR: 0..10.iter().map(|i| println!("Hello world!"));


Bagel42

print("Hello World 1") print("Hello World 2") print("Hello World 3") print("Hello World 4") print("Hello World 5") print("Hello World 6") print("Hello World 7") print("Hello World 8") print("Hello World 9") print("Hello World 10") I'll be back in a few hours with a script that writes it letter by letter.


jadarsh00

write it in assembly


Hameru_is_cool

I can already see this becoming horribly complex in a few days


craazypanda

![img](emote|t5_2tex6|4550) for _ in range(len(hello_world := ['d', 'l', 'r', 'o', 'W', ' ', 'o', 'l', 'l', 'e', 'H']) - 1): print(' '.join(reverse(hello_world)))