2
\$\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\$
9
  • 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\$ Oct 15, 2019 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, 2019 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, 2019 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\$ Oct 15, 2019 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, 2019 at 22:23

1 Answer 1

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\$
3
  • \$\begingroup\$ Definitely not Lua, Turing Machine Code, or Emoji \$\endgroup\$
    – ouflak
    Oct 16, 2019 at 14:36
  • \$\begingroup\$ You can add m4 too. \$\endgroup\$
    – manatwork
    Oct 16, 2019 at 15:10
  • \$\begingroup\$ You can add Jamal too, though without TIO link. \$\endgroup\$
    – manatwork
    Oct 16, 2019 at 15:16

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