88
\$\begingroup\$

Your task is to display the letter "A" alone, without anything else, except any form of trailing newlines if you cannot avoid them, doing so in a program and/or snippet. Code that returns (instead of printing) is allowed.

Both the lowercase and uppercase versions of the letter "A" are acceptable (that is, unicode U+0061 or unicode U+0041. Other character encodings that aren't Unicode are allowed, but either way, the resulting output of your code must be the latin letter "A", and not any lookalikes or homoglyphs)

You must not use any of the below characters in your code, regardless of the character encoding that you pick:

  • "A", whether uppercase or lowercase.

  • "U", whether lowercase or uppercase.

  • X, whether uppercase or lowercase.

  • +

  • &

  • #

  • 0

  • 1

  • 4

  • 5

  • 6

  • 7

  • 9

Cheating, loopholes, etc, are not allowed.

Since this is , the shortest solution, in bytes, that follows all the rules, is the winner.


Validity Checker

This Stack Snippet checks to make sure your code doesn't use the restricted characters. It might not work properly for some character encodings.

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>

\$\endgroup\$
10
  • 7
    \$\begingroup\$ @ColdGolf You seem to be saying "yes" to functions, but functions don't display, they usually return. \$\endgroup\$
    – xnor
    Commented Aug 19, 2016 at 23:06
  • 2
    \$\begingroup\$ Is ending up with a variable that contains just a also good enough ? \$\endgroup\$
    – Ton Hospel
    Commented Aug 19, 2016 at 23:17
  • 1
    \$\begingroup\$ That's not what I meant. The supposed code doing a variable assignment would not contain any of the forbidden characters. I'm just trying to understand what is covered by "display by means other than printing". If "return from a function" is OK, what about "assign to a variable" ? \$\endgroup\$
    – Ton Hospel
    Commented Aug 20, 2016 at 0:05
  • 1
    \$\begingroup\$ Why those particular characters? \$\endgroup\$ Commented Aug 22, 2016 at 1:32
  • 7
    \$\begingroup\$ @immibis A for obvious reasons. U for Unicode escape strings (\u0041 is A), X for hex escape strings (\x41), + for Unicode ordinals (U+0041), & for HTML entities, # for I actually don't know, 65 is the decimal ordinal of A, 41 is the hex ordinal of A, 97 is the decimal ordinal of a, and 0 for a few of the previous reasons. \$\endgroup\$
    – user45941
    Commented Aug 22, 2016 at 6:26

229 Answers 229

1
2 3 4 5
8
180
\$\begingroup\$

Python 2, 14 bytes

print`3<3`[~3]

The expression 3<3 gives the Boolean False, and the backticks give its string representation 'False'. From here, it remains to extract the letter a. Python is 0-indexed, so the a is at index 1, which is a banned character. It can be expressed as 3-2, but there's a shorter way. Python allows indexing from the back, with index -1 for the last entry, -2 for the one before it, and so on. We want index -4, but 4 is also a banned number. But, we can express it as ~3 using the bit-complement ~, which gives -n-1 for ~n.

\$\endgroup\$
10
  • 11
    \$\begingroup\$ That's a really cool solution. Also, couldn't you do [2] instead of [~3]? \$\endgroup\$
    – DJMcMayhem
    Commented Aug 19, 2016 at 22:11
  • 8
    \$\begingroup\$ @DJMcMayhem It's 0-indexed unfortunately, it would need [1]. \$\endgroup\$
    – xnor
    Commented Aug 19, 2016 at 22:12
  • 5
    \$\begingroup\$ ... why are 1 and 4 'banned' numbers?? \$\endgroup\$ Commented Aug 23, 2016 at 21:22
  • 7
    \$\begingroup\$ The challenge's rules say so. \$\endgroup\$
    – xnor
    Commented Aug 23, 2016 at 23:46
  • 25
    \$\begingroup\$ I'm now even considering using "~0" being read as "zero indexed first element from the back". I wonder why we would use "-1" notation in Python.... \$\endgroup\$ Commented Aug 24, 2016 at 8:36
103
\$\begingroup\$

Pluso, 1 byte

o

Pluso Esolangs Page.

Pluso contains a single accumulator, that starts with the value 1. It uses two commands, p which increments the accumulator (mod 27), and o which prints the current value as an uppercase ASCII character, A-Z or space (where 1-26 represents A-Z respectively, and 0 represents space).

As the accumulator starts at 1, the command o with no prior p will output A.

\$\endgroup\$
5
  • 20
    \$\begingroup\$ Welcome to PPCG! I would recommend putting the explanation in your answer, in case the link dies for whatever reason. \$\endgroup\$ Commented Aug 22, 2016 at 7:48
  • \$\begingroup\$ Explanation added. Waiting for moderator approval. \$\endgroup\$
    – KPM
    Commented Aug 23, 2016 at 20:22
  • 3
    \$\begingroup\$ Thanks for the recommendation (and the welcome), I have updated my answer to include a brief explanation. \$\endgroup\$
    – cdw
    Commented Aug 24, 2016 at 3:02
  • 1
    \$\begingroup\$ I just upvoted to put you at 666 rep. Sorry about that. \$\endgroup\$
    – praosylen
    Commented Aug 25, 2017 at 1:05
  • 9
    \$\begingroup\$ Doesn't this fail the "is an esolang" test because it can't do primality checking? \$\endgroup\$ Commented Oct 12, 2017 at 18:52
68
\$\begingroup\$

Pyth, 2 bytes

hG

Test it in the Pyth Compiler.

How it works

 G  Yield the lowercase alphabet.
h   Extract the first character.
\$\endgroup\$
2
  • 1
    \$\begingroup\$ The pyth compiler doesn't seem to be working at all at the moment, might want to change it to a try it online link \$\endgroup\$
    – EdgyNerd
    Commented Dec 29, 2019 at 15:48
  • \$\begingroup\$ @EdgyNerd I find it a bit ironic that you sent this comment to Dennis, the creator of the Try it Online site \$\endgroup\$ Commented Jan 30 at 3:40
55
\$\begingroup\$

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:

<?=~¾;

wherein ¾ has the hex code of 0xBE (it is important to save the file in Latin-1 encoding, not UTF-8!).

\$\endgroup\$
11
  • \$\begingroup\$ An alternative version is f^E^b. \$\endgroup\$ Commented Aug 20, 2016 at 0:53
  • \$\begingroup\$ 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. \$\endgroup\$
    – YetiCGN
    Commented Aug 20, 2016 at 7:39
  • 33
    \$\begingroup\$ +1 for the face ^_^ \$\endgroup\$
    – Cyoce
    Commented Aug 21, 2016 at 6:46
  • \$\begingroup\$ The 6 Byte version doesn't print A. It prints =A. \$\endgroup\$
    – UTF-8
    Commented Aug 21, 2016 at 9:56
  • 1
    \$\begingroup\$ I know the answer to this riddle now: In UTF-8 the "fraction three quarters" codepoint is encoded as two bytes: 0xC2 0xBE, 0xBE being the same as in ISO-8859-1. I noticed that when I saved this to a file on my linux box, which I access via SSH with UTF-8, of course, that the file is 7 bytes. So, save the script with Latin-1 encoding and it will be 6 bytes and not output the = character. \$\endgroup\$
    – YetiCGN
    Commented Aug 22, 2016 at 18:38
46
\$\begingroup\$

05AB1E, 3 2 bytes

Th

Explanation

T   # push 10
 h  # convert to hex

Try it online

Saved 1 byte thanks to Adnan

\$\endgroup\$
2
  • 6
    \$\begingroup\$ Th for two bytes :) \$\endgroup\$
    – Adnan
    Commented Aug 19, 2016 at 22:15
  • 1
    \$\begingroup\$ @Adnan Oh of course. Hex :) \$\endgroup\$
    – Emigna
    Commented Aug 19, 2016 at 22:29
35
\$\begingroup\$

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"
\$\endgroup\$
11
  • 1
    \$\begingroup\$ @ColdGolf It's alright. \$\endgroup\$ Commented Aug 19, 2016 at 23:07
  • 2
    \$\begingroup\$ Would it be against the principles of an obfuscator to add an explanation...? I'm curious about how this works. \$\endgroup\$ Commented Aug 20, 2016 at 17:47
  • 2
    \$\begingroup\$ @trichoplax I suppose it wouldn't hurt to reveal my methods here ;) I added an explanation for both. \$\endgroup\$ Commented Aug 20, 2016 at 19:48
  • 1
    \$\begingroup\$ @OldBunny2800 No. a is a forbidden character, and is in toUpperCase. \$\endgroup\$ Commented Aug 21, 2016 at 18:26
  • 3
    \$\begingroup\$ I thought this was Perl at first. \$\endgroup\$
    – Οurous
    Commented Aug 22, 2016 at 22:51
33
\$\begingroup\$

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

\$\endgroup\$
1
  • 13
    \$\begingroup\$ "more readable" + hexagony = ??? \$\endgroup\$ Commented Sep 14, 2016 at 18:54
33
\$\begingroup\$

brainfuck, 16 bytes

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

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

Try it online!

\$\endgroup\$
6
  • 3
    \$\begingroup\$ This.... this is wizardry. \$\endgroup\$ Commented Aug 19, 2016 at 22:38
  • 3
    \$\begingroup\$ 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/… \$\endgroup\$
    – Cody
    Commented Aug 19, 2016 at 22:55
  • 40
    \$\begingroup\$ @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. \$\endgroup\$
    – Dennis
    Commented Aug 19, 2016 at 22:59
  • 3
    \$\begingroup\$ How hard was it for you to avoid the forbidden characters? \$\endgroup\$ Commented Aug 23, 2016 at 20:15
  • 2
    \$\begingroup\$ @HagenvonEitzen I had to dig a bit to find an algorithm that could avoid +. (the shortest way to print A would be >+[+[<]>>+<+]>.), but thanks to list of constants on Esolang, not too hard. \$\endgroup\$
    – Dennis
    Commented Aug 23, 2016 at 20:25
21
\$\begingroup\$

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'.
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Too bad the second approach is longer. ._. \$\endgroup\$
    – Dennis
    Commented Aug 19, 2016 at 22:26
  • 6
    \$\begingroup\$ Thanks for including the second approach. It's beautiful \$\endgroup\$ Commented Aug 20, 2016 at 17:53
18
\$\begingroup\$

CJam, 3 bytes

'@)

Try it online!

How it works

'@   Push the character '@' on the stack.
  )  Increment its code point, yielding 'A'.
\$\endgroup\$
0
18
\$\begingroup\$

Actually, 2 bytes

úF

Try it online!

Explanation:

úF
ú   lowercase English alphabet
 F  first element
\$\endgroup\$
2
  • \$\begingroup\$ are you the author? I haven't seen this language before. \$\endgroup\$
    – loa_in_
    Commented Aug 23, 2016 at 12:52
  • \$\begingroup\$ I've seen it pop up a couple times in challenges now. I think it has the most clever name of any of the golfing languages on the site :-) I've been watching Suits lately and I find it to be very Harvey. \$\endgroup\$
    – corsiKa
    Commented Aug 24, 2016 at 14:52
14
\$\begingroup\$

Ruby, 15 12 bytes

$><<to_s[-3]

Attempt This Online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ You can save 2 bytes changing $><< to p , makes p to_s[-3] \$\endgroup\$
    – Ephi
    Commented Aug 22, 2016 at 8:56
  • \$\begingroup\$ @Ephi p calls inspect on its arguments, so the output will be quoted, which would disqualify it. \$\endgroup\$
    – Jordan
    Commented Aug 22, 2016 at 12:56
  • \$\begingroup\$ I missed that part of the challenge, I'll let those comments as I think it's an interesting information :) \$\endgroup\$
    – Ephi
    Commented Aug 22, 2016 at 13:06
13
\$\begingroup\$

Bubblegum, 1 byte

"

or

B

Everyone seemed to forget it existed...

\$\endgroup\$
4
  • \$\begingroup\$ Never used Bubblegum before, so perhaps excuse my ignorance, but where can I find the docs for Bubblegum? Also, I tried bubblegum.tryitonline.net with both your answers, but it doesn't seem to output anything. \$\endgroup\$ Commented Aug 22, 2016 at 12:38
  • 1
    \$\begingroup\$ @KevinCruijssen Doc: esolangs.org/wiki/Bubblegum TIO seemed to accept only the hexdump of the source code, so try it like this: bubblegum.tryitonline.net/… \$\endgroup\$
    – jimmy23013
    Commented Aug 22, 2016 at 12:44
  • \$\begingroup\$ Ah, that's my problem; not using the hexdump. Thanks and +1 for being the shortest with a single-byte answer (tied with Pluso). \$\endgroup\$ Commented Aug 22, 2016 at 12:56
  • \$\begingroup\$ @KevinCruijssen There is a 1 byte Pluso answer. It has some problems with a strange site rule, though. \$\endgroup\$
    – jimmy23013
    Commented Aug 22, 2016 at 12:59
12
\$\begingroup\$

Java, 55 bytes

void f(){System.err.write('c'-2);System.err.println();}

Since the code has to print it, one of the two built-in writers are required. System.out is, well, out, because it contains u. System.err works, however.

The next hurdle is Java's handling of char and int. Since it is not allowed to cast to char because it contains a, and because 'c' - 2 gets promoted to int, another mechanism is required. System.err is a PrintWriter, which has a write(char) method but not write(int). Putting 'c' - 2 in there forces it to char without a cast.

Finally, every time I ran the program the buffer for System.err would not flush like it is supposed to, and the program printed nothing. So I had to flush it manually. However, System.err.flush() is not allowed, so I called println() which implicitly flushes the underlying stream.

\$\endgroup\$
12
\$\begingroup\$

Vim, 2 Keystrokes

vim -u NONE then run the following (-u NONE turns off customization)

i<up>

When vim is run in compatible mode the arrow keys are don't get interpreted properly. <up> gets interpreted <esc>OA which leave the following in insert mode. Which would leave (with a couple of trailing newlines)

A

i starts insert mode.
<up> exits insert mode, opens a line above and enters A into the buffer

Example of people encountering this in the wild. https://stackoverflow.com/questions/6987317/while-moving-the-cursor-across-a-vim-process-open-in-a-tmux-session-every-now-a/6988748#6988748

\$\endgroup\$
1
  • \$\begingroup\$ I laughed as I read it. This is good work. Great weaponization of something I know, but wouldn't have thought of. \$\endgroup\$
    – udioica
    Commented Oct 13, 2016 at 15:50
11
\$\begingroup\$

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
\$\endgroup\$
3
  • \$\begingroup\$ @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 ? \$\endgroup\$
    – Ton Hospel
    Commented Aug 19, 2016 at 23:13
  • \$\begingroup\$ "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";. \$\endgroup\$ Commented Aug 19, 2016 at 23:22
  • \$\begingroup\$ @ColdGolf is that meant to answer the question in any way? \$\endgroup\$
    – hobbs
    Commented Aug 20, 2016 at 22:55
10
\$\begingroup\$

><>, 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

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Nice! I got '$-o;| which is almost the same but without the bouncing. (|;o-$' also works.) \$\endgroup\$
    – randomra
    Commented Aug 20, 2016 at 20:32
  • 1
    \$\begingroup\$ @randomra oh true! that would definitely run faster, so nice job \$\endgroup\$
    – torcado
    Commented Aug 21, 2016 at 5:24
10
\$\begingroup\$

><>, 7 4 bytes

Saved 3 bytes thanks to Teal pelican

"-o.

Try it online!

Explanation

"-o."   # pushes the string "-o."
-       # subtracts the charcode of o from the charcode of . (dot), 111-46=65
o       # prints as character
.       # tries to pop 2 coordinates to jump to, but as nothing is left on the stack
        # the program ends in an error
\$\endgroup\$
5
  • \$\begingroup\$ I would have done "B"1-o; \$\endgroup\$
    – DanTheMan
    Commented Aug 22, 2016 at 18:36
  • \$\begingroup\$ @DanTheMan That should have been the more obvious solution. I wonder why I didn't think of that :P \$\endgroup\$
    – Emigna
    Commented Aug 22, 2016 at 18:46
  • \$\begingroup\$ @DanTheMan :- Going off what Dan posted you can reduce this down further to; "1-o;B or even better "+o;& as either case is allowed making this 5 bytes :) - you can even make it 4 bytes with an error; "-o. \$\endgroup\$ Commented Jul 18, 2017 at 15:06
  • \$\begingroup\$ @Tealpelican: That's brilliant! Using strings are often shortest in challenges like these, but I didn't even consider that :) \$\endgroup\$
    – Emigna
    Commented Jul 18, 2017 at 15:29
  • \$\begingroup\$ Once I saw Dan's comment it reminded me of an older challenge quite like this so just used the same concept :) \$\endgroup\$ Commented Jul 18, 2017 at 15:46
9
\$\begingroup\$

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)
\$\endgroup\$
0
9
\$\begingroup\$

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:

`${![]}`[-(-!![])]
\$\endgroup\$
4
  • \$\begingroup\$ You can replace the parenthesis with a space between the minus signs. \$\endgroup\$ Commented Aug 20, 2016 at 13:44
  • \$\begingroup\$ @Pietu1998: I noticed that 3 is allowed so replaced the whole thing with boring old 3-2 to get 1 \$\endgroup\$
    – slebetman
    Commented Aug 20, 2016 at 14:53
  • \$\begingroup\$ Saved one byte thanks to Conor O'Brien's answer \$\endgroup\$
    – slebetman
    Commented Aug 20, 2016 at 15:03
  • 3
    \$\begingroup\$ Uh, no offense, but this pretty much is my answer. Except you use false instead of NaN and don't use a function. \$\endgroup\$ Commented Aug 21, 2016 at 6:28
9
\$\begingroup\$

Vim, 16 13 11 10 keystrokes

Thanks to H Walters for saving two keys

Thanks to DJMcMayhem for saving another!

:h%<cr>jvyZZp
:h%<cr> #open help for percent
jvy     #move down one char (to the letter "a"), visual mode the character, yank
ZZ      #exit help for percent
p       #put yanked character
\$\endgroup\$
4
  • \$\begingroup\$ Very nice approach! \$\endgroup\$
    – YetiCGN
    Commented Aug 20, 2016 at 12:19
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – H Walters
    Commented Aug 21, 2016 at 2:30
  • \$\begingroup\$ Apologies for obvious typo (save 2 bytes) \$\endgroup\$
    – H Walters
    Commented Aug 21, 2016 at 3:06
  • \$\begingroup\$ You can use ZZ instead of :q<cr> to save another one. \$\endgroup\$
    – DJMcMayhem
    Commented Aug 25, 2016 at 21:12
8
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ You can get uppercase a using JSF or a derivative using computed properties \$\endgroup\$
    – Downgoat
    Commented Aug 20, 2016 at 2:41
  • 1
    \$\begingroup\$ @Downgoat Conor O'Brien already showed how. \$\endgroup\$
    – Neil
    Commented Aug 20, 2016 at 9:31
8
\$\begingroup\$

R, 27 12 bytes

EDIT : New version, from an excellent idea from @Jarko Dubbeldam

LETTERS[T*T]

Quite a funny challenge !

Basically, this takes the 26th element of the reversed vector containing the uppercase letters (LETTERS, which is a R's built-in vector)

Previous versions (same number of bytes) :

L=LETTERS;rev(L)[length(L)]
rev((L=LETTERS))[length(L)]
\$\endgroup\$
3
  • 1
    \$\begingroup\$ A bit late, but you can save quite a bit with LETTERS[T*T]. T evaluates to 1 when doing numerical operations. \$\endgroup\$
    – JAD
    Commented Jan 1, 2017 at 17:30
  • \$\begingroup\$ I found a shorter solution! \$\endgroup\$
    – Giuseppe
    Commented Jul 18, 2017 at 15:52
  • \$\begingroup\$ This isn't technically a solution --- it prints '[1] "a"' , rather than just 'a' \$\endgroup\$
    – JDL
    Commented Aug 28, 2017 at 22:07
8
\$\begingroup\$

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.

\$\endgroup\$
8
  • 1
    \$\begingroup\$ not a serious competitor. If you actually golf it down, the downvoter might invert their vote \$\endgroup\$ Commented Aug 19, 2016 at 22:30
  • \$\begingroup\$ Wouldn't it be much shorter to just count up to 65, even with 65 plusses? \$\endgroup\$ Commented Aug 19, 2016 at 22:33
  • 2
    \$\begingroup\$ '+' isn't allowed, so I had to go backwards \$\endgroup\$
    – Cody
    Commented Aug 19, 2016 at 22:34
  • \$\begingroup\$ Sorry, I didn't see that. There's still far shorter ways to make 191, though. \$\endgroup\$ Commented Aug 19, 2016 at 22:36
  • 2
    \$\begingroup\$ 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 \$\endgroup\$
    – Cody
    Commented Aug 19, 2016 at 23:30
7
\$\begingroup\$

Lua, 36 bytes

This one took me a while since MANY of the standard Lua functions are taken away from the rules (all of math, string.char, string.match, pairs, even next)

This takes advantage of the fact that Lua has a global _VERSION that usually starts with "Lua" (e.g., Lua 5.1, or similar for other versions), so unless this is run on a non-mainstream interpreter, the third character will be an 'a'

print(({_VERSION:find("..(.)")})[3])

The {...}[3] is to group the results of find which also includes the indices where it matched, and then return the third item which is the matched character (the a)

\$\endgroup\$
1
  • 2
    \$\begingroup\$ print(({type{}:find".(.)"})[3]) 31 bytes \$\endgroup\$ Commented Aug 27, 2016 at 13:14
7
\$\begingroup\$

Vim, 6 bytes

grNg??

Challenge doesn't block N, and Vim has a ROT-13 feature. FDinoff's answer is probably cooler, but this is ASCII and works everywhere.

\$\endgroup\$
7
\$\begingroup\$

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.

\$\endgroup\$
5
  • \$\begingroup\$ 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. \$\endgroup\$
    – nimi
    Commented Aug 19, 2016 at 22:43
  • 1
    \$\begingroup\$ You're right, however the rules have been updated and now returning from a function seems to be ok. \$\endgroup\$
    – Laikoni
    Commented Aug 19, 2016 at 23:02
  • \$\begingroup\$ No, the rules still say print and/or display. \$\endgroup\$
    – nimi
    Commented Aug 19, 2016 at 23:05
  • 2
    \$\begingroup\$ 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. \$\endgroup\$
    – Laikoni
    Commented Aug 19, 2016 at 23:33
  • 1
    \$\begingroup\$ The OP confirmed that A should be printed/displayed and not returned. \$\endgroup\$
    – nimi
    Commented Aug 20, 2016 at 18:49
6
\$\begingroup\$

C, (19?) 24 bytes

Thanks to Dennis:

f(){printf("%c",88-23);}

same length:

f(){printf("%c",'C'-2);}

which enables also lowercase:

f(){printf("%c",'c'-2);}

There is a 19 bytes solution as a function modifying its parameter, which has a flaw:

g(int*p){*p='C'-2;}

//Usage:

main(){
  int c; //cannot be char
  g(&c);
  printf("%c\n",c);
}

If c was declared char, g modifies the whole int so it smashes the stack which causes other values to be modified or the programm to abort with an error message. The only way to circumvent is to declare int c; in main and print with "%c", but that feels like a loophole.

older solutions

f(){printf("%c",'B'-2/2);} //26 bytes
f(i){i='B';printf("%c",--i);} //29 bytes
f(){int*i="B";int j[]={*i-(2/2),2-2};printf("%s",j);} //53 bytes

Just a function, since main is forbidden.

\$\endgroup\$
7
  • 3
    \$\begingroup\$ 88-23 should save a few bytes. \$\endgroup\$
    – Dennis
    Commented Aug 19, 2016 at 22:43
  • \$\begingroup\$ For lower case a, you can use (333-33)/3-3. It's not as short as 'c'-2, but it's 3er. 33*3-2 is also possible. \$\endgroup\$
    – rici
    Commented Aug 20, 2016 at 19:42
  • \$\begingroup\$ If you use write() instead of printf you can make it a program; specify the build steps to ensure you don't link against any libc at all; if there is no _start the first symbol is jumped to and _exit is allowed so it's safe. At least one version of gcc will optimize write() into the direct syscall with no function call at all. \$\endgroup\$
    – Joshua
    Commented Aug 24, 2016 at 22:58
  • \$\begingroup\$ Depending on your IDE you can do something like this: printf("%c",~'ɦ');, though the "A" will have an accent mark added heh \$\endgroup\$ Commented Jan 24, 2017 at 9:48
  • \$\begingroup\$ @AlbertRenshaw ɦ is a 2-byte-character \$\endgroup\$
    – Karl Napf
    Commented Jan 25, 2017 at 19:49
6
\$\begingroup\$

Brachylog, 4 bytes

@Ztw

Try it online!

Explanation

@Z      The string "zyxwvutsrqponmlkjihgfedcba"
  tw    Write the last element to STDOUT
\$\endgroup\$
6
\$\begingroup\$

Cubix, 5 bytes

o'@)^

Try in the online interpreter!

Cubix is a language where (as the name implies) everything is executed on the faces of a cube. This code maps to the following cube:

  o
' @ ) ^
  .

The basic idea of this answer is to get a nearby character and increment it to what we need. In Cubix, @ is the exit command needed to terminate the program, but also conveniently right under 'A' in the ASCII table. This means we can use the character once to mean two different things, saving bytes - here's the order in which the code is run:

  • '@ pushes the character code 64 to the stack.
  • ) increments the top of stack, yielding the desired character.
  • ^ sends the instruction pointer north, wrapping around to...
  • o outputs the top of stack, A.
  • @ terminates the program.
\$\endgroup\$
1
  • 3
    \$\begingroup\$ Ha, awesome double use of @ :-) \$\endgroup\$ Commented Jan 18, 2017 at 15:11
1
2 3 4 5
8

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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