Number of characters skipped determines code printed

2

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.

John L

Posted 2019-10-15T17:43:37.130

Reputation: 21

Question was closed 2019-10-16T14:26:04.483

5I'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). – Draco18s no longer trusts SE – 2019-10-15T17:47:34.140

5How 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) – James – 2019-10-15T17:50:50.817

2Ooooh, this is a radiation-hardening type problem. I thought it was printing every n characters of the input or something. – Veskah – 2019-10-15T17:51:33.150

2

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.

– AdmBorkBork – 2019-10-15T18:01:55.613

1I'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? – booshlinux – 2019-10-15T22:23:34.057

Seems to be a duplicate of https://codegolf.stackexchange.com/questions/36397/run-the-nth-characters-to-get-n?rq=1 except this one lacks a minimum length

– AlienAtSystem – 2019-10-16T08:54:09.540

@AlienAtSystem Those are actually pretty different. This one is remove every $kn+1$th character while that one is keep every $k$th character. – Post Rock Garf Hunter – 2019-10-16T12:46:52.037

1Still, I think a minimum length requirement would improve this challenge as well – AlienAtSystem – 2019-10-16T12:48:46.670

@AlienAtSystem That might be the one I was thinking of. – Draco18s no longer trusts SE – 2019-10-16T14:33:55.543

Answers

10

Post Rock Garf Hunter

Posted 2019-10-15T17:43:37.130

Reputation: 55 382

1You can add Japt to the list. – Shaggy – 2019-10-15T21:35:20.950

1You can also add Keg to this – EdgyNerd – 2019-10-16T07:25:58.470

TODO: I should add Carrot to this list. (But I can't verify that this works.) – None – 2019-10-16T14:30:12.273

Definitely not Lua, Turing Machine Code, or Emoji – ouflak – 2019-10-16T14:36:02.580

@A_, Carrot works too. – ouflak – 2019-10-16T14:58:51.487

You can add m4 too. – manatwork – 2019-10-16T15:10:59.780

You can add Jamal too, though without TIO link.

– manatwork – 2019-10-16T15:16:36.603