Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Your task is to print/display (although displaying the required characters with means other than printing is also okay), the letter "A" alone, without anything else, except any form of trailing newlines if you cannot avoid them.

Both the lowercase and uppercase versions are acceptable (that is, unicode U+0061 or unicode U+0041), and if your code is, for example. supporting only the uppercase version but cannot print the lowercase one, that's fine.

However, you must not use any of the below characters in your code:

  • A, whether uppercase or lowercase.

  • U, whether lowercase or uppercase.

  • X, whether uppercase or lowercase.

  • +

  • &

  • #

  • 6

  • 5

  • 4

  • 1

  • 9

  • 7

  • 0

You are allowed to use any characters that you like in your code, with the exception of the above list of characters.

Cheating, and loopholes, etc, are not allowed.

You can use any character encoding that you like, but the above disallowed characters are always disallowed, regardless of the character encoding that you use.

Your goal is to do the task given in the fewest amount of bytes that is possible.


Validity Checker

This Stack Snippet checks to make sure your code doesn't use the restricted characters.

var t = prompt("Input your code.");

if (/[AaUuXx+&#0145679]/.test(t)) {
  alert("Contains a disallowed character!");
} else {
  alert("No disallowed characters");
}

This Stack Snippet that makes sure you don't have a disallowed character is also available on JSFiddle.

Leaderboard

var QUESTION_ID=90349,OVERRIDE_USER=58717;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

share|improve this question
1  
Capital A or lowercase a? Or either? – Conor O'Brien 2 days ago
    
With the latest edit of the post, you code can support one of them only, if you want. It doesn't have to support both the uppercase and lowercase versions. – ColdGolf 2 days ago
7  
You say print. Can we also return the character from a function? – Dennis 2 days ago
1  
@ColdGolf You seem to be saying "yes" to functions, but functions don't display, they usually return. – xnor 2 days ago
    
Is ending up with a variable that contains just a also good enough ? – Ton Hospel 2 days ago

71 Answers 71

up vote 17 down vote accepted

Pyth, 2 bytes

hG

Test it in the Pyth Compiler.

How it works

 G  Yield the lowercase alphabet.
h   Extract the first character.
share|improve this answer
1  
Awesome! 2 Bytes. Wow. – ColdGolf 2 days ago

Python 2, 14 bytes

print`3<3`[~3]

Makes the string False, then takes the 4th letter from the end.

share|improve this answer
3  
That's a really cool solution. Also, couldn't you do [2] instead of [~3]? – DJMcMayhem 2 days ago
3  
@DJMcMayhem It's 0-indexed unfortunately, it would need [1]. – xnor 2 days ago

05AB1E, 3 2 bytes

Th

Explanation

T   # push 10
 h  # convert to hex

Try it online

Saved 1 byte thanks to Adnan

share|improve this answer
2  
Th for two bytes :) – Adnan 2 days ago
    
@Adnan Oh of course. Hex :) – Emigna 2 days ago
1  
Amazing. Well done! – ColdGolf 2 days ago

Hexagony, 4 bytes

Ayyy lmao? Quite golfy for a non-golfing language haha. Code:

B(;@

Try it online!

A more readable form:

 B (
; @ .
 . .

This puts the ASCII value of the letter B, which is 66, on the current memory edge. It substracts it by one using ( and prints it with ;. After that, the program is terminated using @.

Obligatory path image:

enter image description here

share|improve this answer

brainfuck, 16 bytes

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

This is based on Esolang's brainfuck algorithm for 159.

Try it online!

share|improve this answer
    
This.... this is wizardry. – Conor O'Brien 2 days ago
    
This solution uses the cell at index -1, which isn't supported across all brainfuck interpreters and would result in a crash. You can run it here to see fatiherikli.github.io/brainfuck-visualizer/… – Cody 2 days ago
19  
@Cody On PPCG, languages are defined by their implementation. As long as there is one interpreter that behaves as desired, it is a valid solution. – Dennis 2 days ago

PHP, 9 6 bytes

<?=O^_^Q;

For 9 bytes: Inspired by @Ton Hospel's answer. Plus, it has the added benefit of looking a bit like a Kaomoji. :-)

The 6 bytes improved version:

<?=~¾;

whereas ¾ has the hex code of 0xbe.

share|improve this answer
    
An alternative version is f^E^b. – Ismael Miguel 2 days ago
    
Yes, the 9-byte solutions are abundant. I started with y^'8' and x^'9', unfortunately numbers have to be cast to string or it will XOR the resulting type will be an integer. – YetiCGN 2 days ago
2  
+1 for the face ^_^ – Cyoce yesterday
    
The 6 Byte version doesn't print A. It prints =A. – UTF-8 23 hours ago
    
@UTF-8: How so? I tested it with PHP 5.6.12 as well as PHP 7.0.3, it only outputs "A". The <?= is the shorthand for <?php echo, then there's a bitwise negation operator and the character 0xBE, followed by the necessary semicolon. Where should = come from? Can you show me how to reproduce what you're getting? – YetiCGN 13 hours ago

CJam, 3 bytes

'@)

Try it online!

How it works

'@   Push the character '@' on the stack.
  )  Increment its code point, yielding 'A'.
share|improve this answer
1  
Amazing solution. I tried to disallow using "U+xxxx" representations or hex representations, but you still did it! – ColdGolf 2 days ago
1  
@ColdGolf, the "U+xxxx" representation is hexadecimal – Solomon Ucko 10 hours ago

Actually, 2 bytes

úF

Try it online!

Explanation:

úF
ú   lowercase English alphabet
 F  first element
share|improve this answer

JavaScript (ES6), 17 16 14 bytes

Saved two bytes thanks to Neil!

_=>` ${-_}`[2]

Returns the second character of NaN, which is a.

This is the shortest I could come up with for A, 43 42 bytes:

_=>`${[][`constr${`${!_}`[2]}ctor`]}`[-~8]

Who says being an obfuscator doesn't help with code golf? Not I!

Explanations

The first one, in depth.

_=>` ${-_}`[2]

-_ is NaN, because _ is undefined. To get this as a string, one would need one of the following:

-_+""
`${-_}`
(-_).toString()

The last is too long, and the first uses +. So we use the second one. Now, the a is at index 1. This isn't any good, because 1 is forbidden. However, being a template string, we can put a space in there to make it at index 2, thus leaving us with ` ${-_}`.


The second one, in depth.

_=>`${[][`constr${`${!_}`[2]}ctor`]}`[-~8]

This one was a doozy.

_=>`                                `[-~8]

This is the 9th character of the inside template string, -~8 being equal to 9. In this case, this template string is just for stringification. This is the inside equation being stringified, in between ${...}:

[][`constr${`${!_}`[2]}ctor`]

Let's expand this a bit:

(new Array())[`constr${`${!_}`[2]}ctor`]

This gets the property `constr${${!""}[2]}ctor` from an empty array. This property is, of course, a template string, but it has some text around it. It's roughly equivalent to:

"constr" + `${!_}`[2] + "ctor"

The inside is in turn equivalent to:

(!_).toString()[2]

!_ is true (because _ is undefined, and !undefined === true), and stringified is "true". We get the second character of it, u; we have to get it this way to avoid explicitly putting u in our code.

So, this inside bit is equivalent to:

"constr" + "u" + "ctor" === "constructor"

So we are getting the constructor of the Array, the Array function. I couldn't put this down explicitly because it contains the forbidden A. Now, stringifying the Array function yields "function Array() { [native code] }".

Back to the original code:

_=>`${[][`constr${`${!_}`[2]}ctor`]}`[-~8]

This is equivalent to, as we've seen:

_=>Array.toString()[-~8]

Equivalent to:

_=>Array.toString()[9]

Finally equivalent to:

_=>"A"
share|improve this answer
    
If your answer is not technically a form of "printing", it's still okay, the post was edited to reflect this. However, thanks for pointing out this to me, sorry for the error! – ColdGolf 2 days ago
    
@ColdGolf It's alright. – Conor O'Brien 2 days ago
    
-_ saves you two bytes. – Neil 2 days ago
    
@Neil nice, one, thanks! – Conor O'Brien 2 days ago
1  
@trichoplax I suppose it wouldn't hurt to reveal my methods here ;) I added an explanation for both. – Conor O'Brien yesterday

Jelly, 3 bytes

ØWḢ

Try it online!

How it works

ØWḢ  Main link. No arguments.

ØW   Yield "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_".
  Ḣ  Head; extract the first character.

Jelly, 4 bytes

l-ṾṂ

Try it online!

How it works

l-ṾṂ  Main link. No arguments.

l-    Take the logarithm of 0 with base -1. Yields (nan+infj).
  Ṿ   Uneval; yield the string representation, i.e., "nanıinf".
   Ṃ  Take the minimum, returning 'a'.
share|improve this answer
1  
Too bad the second approach is longer. ._. – Dennis 2 days ago
2  
Thanks for including the second approach. It's beautiful – trichoplax yesterday

MATL, 5 bytes

YNVH)

Try it Online

Explanation

YN      % Creates a NaN value (not a number)
V       % Convert it to a string
H)      % Grab the second letter ('a')
        % Implicitly display the result

My original answer was the straight forward approach using the pre-defined literal lY2 which yields 'A'...'Z' and then selecting the first element, 'A'.

lY2l)
share|improve this answer

Perl, 9 8 bytes

xor is still allowed, but say isn't. So for 9 bytes:

print$/^K

However using output to STDERR gives 8 bytes:

die~"\x9e\xf5"

Replace \x9e and \xf5 by their literal versions. Or generate the executable file using:

perl -e 'printf q(die~"%s"),~"a\n"' > a.pl
share|improve this answer
    
With the latest edit of the post, any method to get the solution that doesn't use the disallowed characters is okay, whether or it it's technically a form of printing. – ColdGolf 2 days ago
    
@ColdGolf: That's not clear to me. Do you mean I can use say (contains a) for printing as long as the construction of the argument doesn't use the forbidden characters ? – Ton Hospel 2 days ago
    
"However, you must not use any of the below characters in your code: * A, whether uppercase or lowercase." From that, I'd print "No using the letter with code point 65";. – Peanut 2 days ago
    
@TonHospel The output must be exactly as described in the post. – ColdGolf 2 days ago
    
@ColdGolf is that meant to answer the question in any way? – hobbs yesterday

><>, 6 bytes

'|;o-$

this creates a string of characters, bounces and creates it again in reverse, flips the top 2 stack items and subtracts: '|' (124) minus ';' (59) is 'A' (65)

Try it online

share|improve this answer
2  
Nice! I got '$-o;| which is almost the same but without the bouncing. (|;o-$' also works.) – randomra yesterday
    
@randomra oh true! that would definitely run faster, so nice job – torcado yesterday

Javascript, 18 bytes 16 bytes 12 bytes 11 bytes

` ${!2}`[2]

Based on modified jsfuck basics (had to figure out how to replace + with -).

Ungolfed?

Well, at least a version with comments (note that this version will probably not run):

` ${      // whitespace to make "a" the third letter
  !2      // returns false
}`        // convert to string "false"
[2]       // index the third letter in " false" (note the whitespace)

Old solution:

`${![]}`[-(-!![])]
share|improve this answer
    
You can replace the parenthesis with a space between the minus signs. – Pietu1998 yesterday
    
@Pietu1998: I noticed that 3 is allowed so replaced the whole thing with boring old 3-2 to get 1 – slebetman yesterday
    
Saved one byte thanks to Conor O'Brien's answer – slebetman yesterday
    
Uh, no offense, but this pretty much is my answer. Except you use false instead of NaN and don't use a function. – Conor O'Brien yesterday

><>, 7 bytes

fd*3,o;

Explanation

f       # 15
  *     # times
 d      # 13
    ,   # divided by
   3    #
     o  # print as char
      ; # end

Try it online

share|improve this answer

Brainfuck, 192 19 bytes

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

Thanks to @NinjaBearMonkey for helping me save hella bytes

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------.

I'm not good at Brainfuck so I'm sure theres a shorter solution, but it works by decrementing below 0, rolling the byte over, and keep going until it gets down to 'A', then it prints.

share|improve this answer
1  
not a serious competitor. If you actually golf it down, the downvoter might invert their vote – Destructible Watermelon 2 days ago
    
Wouldn't it be much shorter to just count up to 65, even with 65 plusses? – NinjaBearMonkey 2 days ago
2  
'+' isn't allowed, so I had to go backwards – Cody 2 days ago
    
Sorry, I didn't see that. There's still far shorter ways to make 191, though. – NinjaBearMonkey 2 days ago
1  
That was the 192 byte solution, I just left it up and did the strikethrough instead of deleting it because I thought it was funny going from 192 to 19 – Cody 2 days ago

JavaScript (ES6), 21 bytes

_=>(8^2).toString(22)

I originally tried converting false to string to do this, but it took me 23 bytes at the time. I've since come up with a shorter way, which is this for 14 bytes:

_=>`!${!2}`[2]

I don't think you can get an uppercase A under the rules, since you need one of String.fromCharCode or .toUpperCase(), both of which contain a.

share|improve this answer
    
I'll edit the post to allow these kind of solutions. – ColdGolf 2 days ago
    
You can get uppercase a using JSF or a derivative using computed properties – Downgoat 2 days ago
1  
@Downgoat Conor O'Brien already showed how. – Neil 2 days ago

Brachylog, 4 bytes

@Ztw

Try it online!

Explanation

@Z      The string "zyxwvutsrqponmlkjihgfedcba"
  tw    Write the last element to STDOUT
share|improve this answer

Haskell, 10 bytes

As a function (or rather a statement as no input is required)

f=pred 'B'

does the trick. Try it on Ideone. A full program is impossible as this would need to contain a main.

share|improve this answer
    
I don't think this is valid. The task requires to "print" or "display" A. Your functions just returns it and the linked program displays it via putChar which uses u. – nimi 2 days ago
    
You're right, however the rules have been updated and now returning from a function seems to be ok. – Laikoni 2 days ago
    
No, the rules still say print and/or display. – nimi 2 days ago
2  
Dennis asked explicitly whether returning from a function instead of printing is ok and OP replied with yes, but the afterwards updated wording of the question still doesn't reflect this. I guess we still have to wait for further clarification. – Laikoni 2 days ago
    
The OP confirmed that A should be printed/displayed and not returned. – nimi yesterday

Ruby, 15 12 bytes

$><<to_s[-3]
share|improve this answer
    
You can save 2 bytes changing $><< to p , makes p to_s[-3] – Ephi 45 mins ago

Labyrinth, 6 5 bytes

833.@

Explanation

833     # push 833 to stack
    .   # print modulo 256 as byte
     @  # exit

Try it online

Saved 1 byte thanks to Martin Ender.

share|improve this answer
1  
Actually making use of that modulo: 833.@ – Martin Ender 20 hours ago
    
@MartinEnder: Brilliant! – Emigna 16 hours ago

Sesos, 3 bytes

The code contains two unprintable characters, so here is a hexdump:

0000000: a85a0d                                            .Z.

Try it online! (Note that this uses the assembly code, which TIO converts to the binary above as an intermediate step. The binary is shown as a debug message.)

It is generated from this assembly program:

add 65
put
share|improve this answer
    
Could you elaborate on the unprintable characters part? – ColdGolf 2 days ago
    
@ColdGolf Binary Sesos isn't a character based language; it stores its source code in form of a little-endian base-256 integer. – Dennis 2 days ago
2  
Hmm... I'd say the assembly code is the source code of that program and it uses "a" and "6", which are forbidden. Otherwise everybody might just compile their program to an x86 binary and voilà, no forbidden characters used! – YetiCGN 2 days ago
4  
@YetiCGN Submitting binary programs is perfectly acceptable. – Dennis yesterday
1  
@YetiCGN TIO doesn't support binaries right now. I've added a note to the link. – NinjaBearMonkey 11 hours ago

Jolf, 3 bytes

Fpl

Try it here!

First (F) of the lowercase alphabet (pl).


Are you tired of verifying your code manually? Use this!


Another one for three bytes:

~TS

This is the hexadecimal char code of a newline (0x0A)

share|improve this answer

Dyalog APL, 15 bytes

{⍵::2⌷⊃⎕DM⋄⍺}⍴⍬

The straightforward options are all banned: both ⎕AV (APL character set vector) and ⎕UCS (Unicode conversion) contain banned characters.

It gives one uppercase A:

      {⍵::2⌷⊃⎕DM⋄⍺}⍴⍬
A

Explanation:

  • {...}⍴⍬: pass 0 (length of empty vector) into the function
  • ⍵::: trap the error with code , which will be 0. A trap on 0 means to trap all errors.
  • 2⌷⊃⎕DM: the 2nd character of the first line of the error message
  • ⋄⍺: try to return the value of the left argument. There isn't one, so this will raise a VALUE ERROR, which the A is then extracted from.
share|improve this answer

Mathematica, 27 bytes

Writes 10 in hexadecimal. Half the length is one function name :(

IntegerString[2(8-3),2^2^2]
share|improve this answer

Brachylog, 7 bytes

@P:33mw

Try it online!

Explanation

@P is the following string:

 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~

(the first character is a space)

And its 33rd element is the required letter A.

@P:33mw
@P        generate the string above
  :33     append the number 33, yielding ["...",33]
     m    pass the array as Input of m, and the
          required character becomes the Output
      w   recycles the right argument of the previous
          predicate as the left argument, and then
          prints to STDOUT
share|improve this answer

Pyke, 2 bytes

Gh

Try it here!

Gh - alphabet[0]
share|improve this answer

reticular, 9 bytes

"C"c2-co;

Try it online!

This is basically C converted from a char to a char code, subtracting two, converting back to a char, printing it with o, then finally terminating it with ;.

share|improve this answer

Bash, 19 17 bytes

Prints lower-case a:

printf \\$[282/2]

(Thanks to Dennis for reminding me of the deprecated syntax)

share|improve this answer

Vim, 16 13 11 keystrokes

Thanks to H Walters for saving two keys

:h%<cr>jvy:q<cr>p
:h%<cr> #open help for percent
jvy     #move down one char (to the letter "a"), visual mode the character, yank
:q<cr>  #exit help for percent
p       #put yanked character
share|improve this answer
    
Very nice approach! – YetiCGN yesterday
    
Save 3 bytes; instead of :h<cr>, try :h%<cr>. That's one extra character, but you wind up on the help for %, with your cursor right over an a. So from here you can replace 33ll with j. – H Walters yesterday
    
Apologies for obvious typo (save 2 bytes) – H Walters yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.