1
\$\begingroup\$

Write a program which, when every nth character is skipped, it prints n. For example, if every 2nd character is skipped, it prints 2.

Example

n=0

foobar

Output:

0

n=1

foa

Output:

1

n=2

fobr

Output:

2

Rules

  • If n=0 (no characters are skipped), 0 must be returned.
  • Must print to STDOUT.
  • Standard loopholes are forbidden.
  • The first character is never skipped.
  • Obviously, it doesn't need to work for more characters than the code has (e.g. if your code is 11 characters long, it doesn't need to work for every 11th character)

Scoring

This is code golf, so the shortest code in bytes wins.

\$\endgroup\$

closed as unclear what you're asking by AdmBorkBork, caird coinheringaahing, xnor, Arnauld, HyperNeutrino Oct 16 at 14:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 5
    \$\begingroup\$ I'm sure I've seen a challenge like this before, but I have to question the "code golf" aspect: Fewer characters (say, a 2 byte program) would never need to output 3 because there would be no 3rd character. I'm pretty sure the older challenge was to output as many different results as when programs got longer there were more collisions to deal with. Shorter just gives an advantage to languages that can output 0 with 0 or 1 bytes (and is not challenging). \$\endgroup\$ – Draco18s Oct 15 at 17:47
  • 5
    \$\begingroup\$ How is n=1 "fobr"? If I understand the challenge it should be "foa" because you remove each character in parenthesis: f(o)o(b)a(r) \$\endgroup\$ – DJMcMayhem Oct 15 at 17:50
  • 2
    \$\begingroup\$ Ooooh, this is a radiation-hardening type problem. I thought it was printing every n characters of the input or something. \$\endgroup\$ – Veskah Oct 15 at 17:51
  • 2
    \$\begingroup\$ Welcome to Code Golf SE! We have a sandbox where you can post a potential challenge and get meaningful feedback before posting it to Main, which can help clear up questions such as the ones currently in the comments. \$\endgroup\$ – AdmBorkBork Oct 15 at 18:01
  • 1
    \$\begingroup\$ I'm trying to understand this challenge a bit better.Are you portraying that foobar is the theoretical source code, and skipping every character of the original source code, foobar, resulting in foa, would print a different result? \$\endgroup\$ – booshlinux Oct 15 at 22:23
10
\$\begingroup\$

Polyglot, 1 byte

0

Try it in Retina

Try it in Jelly

Try it in 05AB1E

Try it in Husk

Try it in ///

Try it in GolfScript

Try it in BrainGolf

Try it in Pyth

Try it in Japt

Try it in ink

Try it in PHP

Try it in Brachylog

Try it in MATL

Try it in Keg

Try it in Carrot

\$\endgroup\$
  • 1
    \$\begingroup\$ You can add Japt to the list. \$\endgroup\$ – Shaggy Oct 15 at 21:35
  • 1
    \$\begingroup\$ You can also add Keg to this \$\endgroup\$ – EdgyNerd Oct 16 at 7:25
  • \$\begingroup\$ TODO: I should add Carrot to this list. (But I can't verify that this works.) \$\endgroup\$ – A _ Oct 16 at 14:30
  • \$\begingroup\$ Definitely not Lua, Turing Machine Code, or Emoji \$\endgroup\$ – ouflak Oct 16 at 14:36
  • \$\begingroup\$ @A_, Carrot works too. \$\endgroup\$ – ouflak Oct 16 at 14:58

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