# “Simple” Programming Homework

Your friend has been caught sleeping in class again! As punishment, his computer science teacher has assigned him homework, knowing that he will not be able to solve it due to not having paid any attention.

The assignment seems deceiving simple at first; all that is required is to output the string:

John Doe

Unfortunately, the teacher is intent on making the simple assignment much more difficult. Since your friend was not listening when the teacher explained the concept of strings and numbers, the teacher forbids him from using any number character (0-9) or the quotes (", ', ).

Try to find the shortest code in each language!

Note: it is encouraged to try to solve this problem in languages where string/character literals exist but cannot be used due to the restrictions (most mainstream languages are like this, e.g. C++).

• This is awfully close to a previous poorly received challenge. Mar 2, 2021 at 20:55
• And as we still not know why some serial downvoters had objections on many solutions there, personally I feel no urge to participate in another so similar challenge. Mar 2, 2021 at 20:59
• @manatwork You may find this helpful. Mar 2, 2021 at 21:05
• @WheatWizard, read it last year. Read it again. Still in dark. But never mind. Mar 2, 2021 at 21:17
• Why did you repost your previous question?
– user100690
Mar 3, 2021 at 6:20

# C, 41 bytes

#define p(x)puts(#x)
main(){p(John Doe);}


Try it online!

# converts a token passed to a macro to a string literal.

# PowerShell, 51 bytes

#John Doe
(gc $PsCommandPath)[+$x]-replace(echo \#)


Try it online!

# PowerShell, 59 54 bytes

$x++;$x++
-join((echo John),(echo Doe).PadLeft($x+$x))


Try it online!

# PowerShell, 56 bytes

-join((echo John),[char](++$x-shl$x+++$x+$x),(echo Doe))


Try it online!

# PowerShell, 57 bytes

-join((echo John),[char]([char](echo !)-++$x),(echo Doe))  Try it online! # PowerShell, The Most Trivial Solution™, 10 bytes (I'm sorry, I said I wanted to avoid trivial solutions, but I did not know this was possible, and felt that this method might benefit PS solutions to other challenges) {John Doe}  Try it online! • 19 bytes: Write-Host John Doe Mar 2, 2021 at 21:18 • @Makonede Feel free to post yourself; It's a good example for PowerShell, but I want my answer to stick with non-trivial/built-in solutions to the problem :) Thanks for pointing it out, though! Mar 2, 2021 at 21:22 • Alright, sounds good! Mar 2, 2021 at 21:25 • one more to the collection :) Try it online! Mar 3, 2021 at 11:13 • Mar 3, 2021 at 11:17 # JavaScript (V8), 807776654034 20 bytes _=>/John Doe/.source  Turns out the _=> might be required. History: /John Doe/.source  Oh there's a trivial way to do it. I just wasted an hour :/ 31: (/John Doe/+[]).slice(-~[],~[])  Finally found a way to get rid of that pesky toString :p 37: /John Doe/.toString().slice(-~[],~[])  Why use the function thing at all? 62: (function John_Doe(){}).name.replace(/_/,/ /.toString()[-~[]])  I probably should have thought about using / / sooner... 73: (function John_Doe(){}).name.replace(/_/,{}.toString(x=true)[x-~x-~x-~x])  I wasted twenty minutes trying to do this character by character then remembered this. Golfed three bytes by using -~x, which is the same as +2. • Currently, your code is a snippet. You can make it a function by just prepending _=>: _=>/John Doe/.source Apr 14, 2021 at 19:17 • @Makonede I was under the impression snippets were allowed but I'll mention that in the answer and ask for clarification in a comment. Thanks! Apr 14, 2021 at 19:29 # Vyxal, s, 16 bytes \J\o\h\nð\D\o\eW  Try it Online! ## Explained \J\o\h\n # Push the characters J, o, h and n ð # Push a space \D\o\e # Push the characters D, o and e W # Wrap everything into a list. The s flag joins on newlines  • @Downvoters why are you serial downvoting everything? Just because it's trivial doesn't mean you need to act harshly. Mar 3, 2021 at 7:34 • I also faced the same problem in answering the trivial questions, in most of the cases the downvoter doesn't reply. Anyhow cut your downvote with an upvote. Mar 3, 2021 at 9:42 # Python 3, 55 43 28 bytes Saved 12 bytes thanks to Makonede!!! Saved 15 bytes thanks to ovs!!! print(*dict(John=[],Doe=[]))  Try it online! • Nice, that seems to be the shortest fix here. Also, here's a 43 byte version: John=Doe=[];print(dir()[True],dir()[False]) Mar 2, 2021 at 22:00 • @Makonede Was just fixing that and nice one - thanks! :D Mar 2, 2021 at 22:00 • 28 bytes with print(*dict(John=[],Doe=[])) – ovs Mar 3, 2021 at 6:29 • @ovs Nice one - thanks! :D Mar 3, 2021 at 7:44 • @tsh Both unfortunately for this challenge and fortunately as capital letters come first, Python sorts namespaces - so your suggestion prints out Doe John. Mar 3, 2021 at 12:15 # CW for languages where the program John Doe is valid Feel free to add to this list if you find a solution in another language. NOTE: Text editors have been excluded as there are way too many of them. # /// # Charcoal # GS2 # HTML # Keg # PHP # Quine # Text • I'm not sure, so I won't add it yet, but what about vim -y? Apr 19, 2021 at 5:26 # 05AB1E, 5 bytes ”„ÐÒ«  Try it online! ”„ÐÒ« # full program ”„ÐÒ« # push "John Doe" # implicit output  # Perl 5 -M5.10.0, 15 bytes say q(John Doe)  Try it online! I don't know whether -M5.10.0 is optimal, I just cargo culted it from a random Perl answer. # Java, 166 bytes $->{class John_Doe{}final char o=Byte.MAX_VALUE/Byte.MAX_VALUE,t=o+o,f=t+t+o,T=f+f,u=T*T-f,s=f*(f+o)+t;System.out.print(John_Doe.class.getSimpleName().replace(u,s));}


Try it online!

# Java, 192 bytes

a->{final char O=Byte.MAX_VALUE/Byte.MAX_VALUE,T=O+O,t=T+O,F=t+T,S=F+T,Z=F+F,Y=Z*Z,o=Y+Z+O,J=S*Z+T+T,h=Y+T+T,n=Y+Z,$=Z*t+T,D=F*Z+Z+F+t,e=Y+O;System.out.print(String.valueOf(J)+o+h+n+$+D+o+e);}


This uses Byte.MAX_VALUE/Byte.MAX_VALUE to obtain the number 1 and then uses it to construct the ASCII codes of all the characters in the string. final is needed so that casts from int to char are not necessary.

Try it online!

• The 41 bytes version is not valid as digits are not allowed either. Mar 2, 2021 at 21:43
• @Laikoni Good catch. Mar 2, 2021 at 21:44
• You can use pre-existing public variables to get the space char value (or use a field, which auto initializes itself to 0, and shift its bits around like ++x>>++x>>++x, 1<<2<<3=32). I got it to 134 bytes Mar 8, 2021 at 8:30

# JavaScript, 32 bytes

_=>(/John Doe/+[]).slice(-~_,~_)


When the function is called without arguments, the first argument will be undefined and ~undefined produces -1.

Try it online!

Thanks to tsh for the idea

# JavaScript (V8), 39 bytes

print(...Object.keys({John:[],Doe:[]}))


print uses a space to separate arguments when printing.

Try it online!

• x=>(/Jone Doe/+[]).slice(-~x,~x) 32 bytes
– tsh
Mar 3, 2021 at 2:21
• @tsh Nice one.​ Mar 3, 2021 at 2:23
• Interesting approach with the print and Object.keys, probably the most creative answer so far! I've also found a 17 byte JS solution a few days ago, although it's a snippet (can be made into a function for 20 bytes). Mar 5, 2021 at 0:39

# Windows Batch, 13 bytes

echo John Doe


# Jelly, 8 bytes

“®ƊʠỌḂŒ»


Try it online!

The “ at the beginning isn't defined as a quote in the challenge, so Id say this is valid.

# PowerShell Core, 19 bytes

Write-Host John Doe


Try it online!

Write-Host John Doe  # full program
Write-Host           # output...
John Doe  # literal


# Bubblegum, 10 7 bytes

-3 bytes by @tsh.

´H&ÒF


Try it online! This program gets converted to base 256, then to base 96, and each digit $$\n\$$ gets replaced with the $$\n\$$th printable ASCII character. Hexdump:

00000000: 0bb4 4826 02d2 46  ..H&..F

• 7 bytes: 0bb4482602d246
– tsh
Mar 3, 2021 at 2:13
• The 7 bytes version is not a zip stream, but a base 96 to base 256 encoding.
– tsh
Mar 3, 2021 at 2:29

# Notepad / Gedit, 15 keystrokes

SHIFT+J
o
SHIFT+LEFT ARROW
CTRL+C
RIGHT ARROW
h
n

D
CTRL+V
e


# Notepad / Gedit (Boring solution), 8 keystrokes

J
o
h
n

D
o
e

• If capitals count as one keystroke, shouldn't SHIFT+J be J? Mar 3, 2021 at 18:54

# brainfuck, 91 bytes

-[------->+<]>+.[-->+++<]>.-------.++++++.-[->+++++<]>-.++[->++<]>.[--->+<]>+++.----------.


Try it online!

# Julia, 38 bytes

print(:John,Char(ceil(π*π*π)),:Doe)


Try it online!

# Java (JDK), 134 bytes

class John{public static void main(String[]z){System.out.print(John.class.getName()+(char)Float.SIZE+Doe.class.getName());}}enum Doe{}


# Java (OpenJDK 8), 131 bytes

interface John{static void main(String[]z){System.out.print(John.class.getName()+(char)Float.SIZE+Doe.class.getName());}}enum Doe{}


This is an everything java solution - count in the whole file, header and footer. No tio.run link because it depends on the class name, which must be John in this case. In Java 8+ you can make it an interface and omit public in the main method for -3.

Float.SIZE and Integer.SIZE return 32, the char code for a space. In this case, getName(), getTypeName(), getSimpleName(), and getCanonicalName() will all return just the desired name part of the class/enum. You can make John an enum for -1, but it would require an extra ; at the start to declare the enum objects, +1, making it equal length.

You can run this to verify whether it prints the correct String (and that the space character is an actual space, because doing (char)0, for example, will leave a blank spot without it technically being a space):

interface John { // or class
public static void main(String[]z) {
System.out.print((John.class.getName() + (char) Float.SIZE + Doe.class.getName())
.equals("John Doe"));
}
}
enum Doe{}


# Pxem, 10 bytes of file name + 0 bytes of content = 10 bytes

• Filename: John Doe.p
• Content is empty

What a low effort.

{i}dds{i}c{iiii}dddc{d}iiiciiiiiic{{d}ii}iic{iii}iiiiiic{iiii}iiic{d}c


Try it online!

It somehow beats Java!

# Vyxal, 8 bytes

«:L∞I\«ǐ


Try it Online!

Explanation:

«:L∞I\«   # Base-256 compressed "john doe"
ǐ  # Convert To Title Case
# Implicit output


Vyxal doesn't support capital letters in compressed strings, which is why the ǐ command is needed.

# PHP, 8 bytes

John Doe


Try it online!

John Doe  # full program
John Doe  # no leading <?, so outputs source


# Python 2, 56 14+8=22 bytes

print __file__


Must be saved in a file called John Doe in the root directory. However, the path may not even contain a single / for this to work. Therefore, this file's full path should be only John Doe, and not /John Doe or C:/John Doe. Theoretically possible but not sure how in practice.

NB: Adding the lengths of the file name and the code was somehow the shortest approach I could find to this challenge (in Python).

# Bash, 13 bytes

echo John Doe


Try it online!

echo John Doe  # full program
echo           # output...
John Doe  # literal
`
• Combine your Batch and this answer, they are polygots Mar 3, 2021 at 9:16
• I know, but they're different languages. Mar 3, 2021 at 18:52