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.
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 output0
with 0 or 1 bytes (and is not challenging). – Draco18s no longer trusts SE – 2019-10-15T17:47:34.1405How 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.8172Ooooh, 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.6131I'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 infoa
, would print a different result? – booshlinux – 2019-10-15T22:23:34.057Seems 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