In the error outputs of some languages such as Java, a pointer is shown to give the programmer an idea of exactly where the error went wrong.

Take this example on Ideone:

Main.java:12: error: ';' expected
    Invalid Java!

Notice the caret shows where the invalid code is?


Your challenge is: given number N and string S, place a pointer on the Nth character in S.


Input: 2, "Lorem ipsum, dollar sit amet."


Lorem ipsum, dollar sit amet.


  • Input is received via STDIN or function parameters
  • Output is printed out to the console or returned
  • Trailing new lines, spaces etc are allowed in the output
  • The pointer character must be a ^ caret and must be on a new line.
  • This is code golf, so the shortest answer wins. Good luck!
  • 16
    \$\begingroup\$ I feel like this is an extremely simple problem, so I am not certain it will be received overly well. You might want to try the sandbox once you have enough rep. \$\endgroup\$ – FryAmTheEggman Jun 10 '15 at 1:08
  • 6
    \$\begingroup\$ I think this could have been made a bit more interesting if the input had multiple lines, so that you had to insert a newline, spaces, and carat at the correct position(s). Honestly, the spec doesn't really say it will be a single line, but I think enforcing that now will invalidate a few answers unfairly, since there's no example that shows this. \$\endgroup\$ – Geobits Jun 10 '15 at 2:04
  • 3
    \$\begingroup\$ Like I said, the cat's probably out of the bag on this one. Rule changes after valid answers are posted usually don't work out well. Live and learn ;) \$\endgroup\$ – Geobits Jun 10 '15 at 3:06
  • 1
    \$\begingroup\$ @SohamChowdhury I'll just pretend that was intentional ;) Do you want me to fix it? \$\endgroup\$ – Matt Young Jun 10 '15 at 9:36
  • 9
    \$\begingroup\$ While this may be very simple, you've certainly done well for a first challenge! You have +16/-0 votes, 1,300 views, and 28 answers (as of this writing) and you've made the Hot Network Questions list. Nice job! \$\endgroup\$ – Alex A. Jun 10 '15 at 14:50

62 Answers 62

1 2 3

Braingolf, 25 bytes [non-competing]

VV"^ "R3-M#

Try it online!


Underload, 23 bytes

)S()(( )S^)!!^(^)S)

Assumes S is a string on the stack. N should be given in unary. It should be a sequence of : in between the ) and ! on the second line. For example:

)S()(( )S^)::::!!^(^)S)

The :::: represents N=4.

  • \$\begingroup\$ Hmm, is that really the tersest way to subtract 1 in Underload? I recognise the general shape, but it's disappointing if there isn't a shorter way. \$\endgroup\$ – user62131 Jun 7 '17 at 9:49
  • \$\begingroup\$ @ais523 Switching to unary input for n works, because : is easily undone using !. \$\endgroup\$ – Esolanging Fruit Jun 11 '17 at 23:31
1 2 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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