| Bytes | Lang | Time | Link |
|---|---|---|---|
| 014 | Dyalog APL | 250926T062318Z | Aaron |
| 228 | JavaScript | 161214T061345Z | jrich |
| 032 | Klein 000 | 210806T153536Z | Wheat Wi |
| 026 | Gol><> | 210806T145702Z | Wheat Wi |
| 009 | Vyxal | 210728T231118Z | a stone |
| 026 | Zsh | 210602T194915Z | pxeger |
| 034 | Befunge 98 | 161214T033945Z | MercyBea |
| nan | JavaScript + HTML + Stack Snippets | 161215T104238Z | user2428 |
| 034 | A Pear Tree | 161214T200336Z | user6213 |
| 034 | ><> | 161214T004140Z | MercyBea |
| 051 | ><> | 161213T224118Z | mbomb007 |
| 051 | Befunge93 | 161214T003432Z | James Ho |
| 018 | Actually | 161213T231231Z | Cobi |
| 012 | 05AB1E | 161213T230701Z | Adnan |
| 016 | Pyth | 161213T222906Z | Maltysen |
| 037 | Befunge98 | 161213T222241Z | Martin E |
Dyalog APL, 14 bytes
∪∪∊∊⍳⍳404⌈⌈404
Well I'm curious if this counts since I can't actually run it, but proved it out with a smaller number.
404⌈⌈404 If any digit is removed this becomes "max of rounded-up right", which 404 will be the answer.
If either ⌈ is removed, it just becomes "max of"
⍳⍳ Generates range of 1..404, then do it again
This makes a massive array with an exceedingly high rank
But if either is removed, it just makes the 1..404
∊∊ Flatten and then flatten. Only need one, so if both survive, the second is a no-op
If both index-generators ran, this will have many repeated elements as they were generated over and over again, and flatten would be placing them one after another
∪∪ Get unique elements of unique elements. Again, only need one; if there's two its effectively a no-op
If we have the extra long list of indices, then, when uniquified, this will only result in 1..404 afterall
JavaScript, 228 bytes
etInterval=stInterval=seInterval=setnterval=setIterval=setInerval=setIntrval=setInteval=setInteral=setIntervl=setInterva=top=>4
setInterval
`405>(i=this.i?i:1)?alert(i++):0`///`
setInterval
`405>(i=this.i?i:1)?alert(i++):0`///`
Explanation
Evaluating code in a setInterval allows the program to continue even if there is an error. We make sure that the code passed will error out if any single character is removed. Template string syntax can be abused to call setInterval with a constant string without parentheses. Luckily, even if the template string is on the next line it still parses as a function call with such syntax.
The first issue we run into is that setInterval is a function, and thus if a character is removed and the program tries to call setInteval instead, it errors out. Of course, since there are two indentical invocations of the setInterval, we don't have to worry about it actually functioning correctly as long as we avoid the error. So, the first line defines every possible "misspelling" of setInterval to a valid function.
The first line works by assigning all of these "misspellings" to the function top=>4. Note the ES6 syntax, this simply takes a paramater named "top" and returns 4. Why "top"? Well, the first line must never throw an error even if a character is removed. If an = is removed to make top>4, this boolean expression will be valid since top is predefined in browsers, simply yielding false. If the 4 is removed, the function body simply becomes the first setInterval segment, and the second runs unharmed.
Now, all that is left to worry about is if a ` is removed.
If removed from the beginning, setInterval simply does nothing, evaluating to itself as its own expression. Then, the rest of the second line simply runs a single iteration of the loop, letting the other setInterval fragment finish the job. If removed from the end, the remaining backtick is picked up from the end of the comment.
The newlines are placed so that removal one will not affect program behavior, but they prevent errors in the case of some character removals such as the leading backtick.
Klein 000, 32 bytes
<<@?+-*4"e":+1:/
<@?+-*4"e":+1:/
Klein XXX, 54 bytes
>>> \\
..\:+1:@?+-*4"e"<
\..:+1:@?+-*4"e"<
Shamelessly reusing strategies from my fault tolerant "Hello world" solution.
Gol><>, 26 bytes
<<;|N:PF*4e`/
<;|N:PF*4e`/
This is pretty simple, but there wasn't a Gol><> answer yet, and it scores pretty well.
Vyxal, 11 9 bytes
-2 thanks to A username
⁺ed404∴ɾƛ
⁺ed404∴ɾƛ
⁺e # Push 202
d # Double ^ to get 404
404 # Push 404 again
∴ # Take the maximum
# If bytes are removed from either of the 404s, this ensures the intact one is pushed
# If ∴ is removed, 404 is still at the top of the stack so it doesn't matter
ɾ # range(1, n+1)
ƛ # Map
# If it's a number (ɾ removed), range(1, n+1) is used
# Otherwise (it's a range), nothing happens here
Zsh, 26 bytes
>404
>404
seq ???||seq *
Explanation:
>404: create the file404. This command is repeated twice because if one has had a byte removed, we need the other to still work. Ordinarily with>you wouldn't need the newline between them, but in the case the second>is removed,>404404wouldn't create404???: find a 3-character file name in the current directory (this will always find404because of the redundancy above)seq: count up to that||: if that fails (happens ifseqor???is mangled):*: find a filenameseq: count up to it
The second newline before the first
seqis necessary because otherwise>404seqwould create two files, and thenseq *would try to range between404and404seq, which isn't a numberThe second space in
seq ???is necessary becauseseq???would fail to match, and for some reason the bit after the||doesn't get executed either (it's possibly a bug in zsh)If any of the two
|s are missing, the firstseqis piped to the second; the second ignores its input, but still outputs as normal.
Befunge 98, 34 bytes
<<.:@k`*4e':+1[
2.:@k`*4e':+1<^^j
This works very similarly to my ><> answer, but instead of the mirror /, I use the turn left operation [ and then reverse the IP direction, which is functionally equivalent to a mirror in this case.
The original code
<< Reverses code direction, sending IP to right
[ Turns the IP left, into the ^, which reverses it.
It then hits this again, turning left to go West. (No-op)
:+1 Adds 1 to the sum
*4e' Pushes 404
@k` Ends the program if (sum > 404)
.: Prints the sum
The deletion
If something in the second line is deleted, it will shift over, and not affect the top at all.
If anything in the first line is deleted, the [ will send the IP into the <, which starts an identical loop (with the exception of 2j^^ which avoids the ^s used in tandem with the [)
Because there are 2 new lines, it makes no difference to the code if one is deleted (thanks to @masterX244 for this!)
JavaScript + HTML + Stack Snippets, 167 158 154 bytes
Abusing the fact that JavaScript in Stack Snippets gets placed in a web page inside a <script> element.
or(x="",i=405,d=document;--i;)d[i]||(x=d[i]=i+' '+x);d.write(x)</script></script><script>for(x="",i=405,d=document;--i;)d[i]||(x=d[i]=i+' '+x);d.write(x)
A Pear Tree, 34 bytes
The program contains control characters, so here's an xxd dump:
00000000: 7072 696e 7420 312e 2e34 3034 2327 108a print 1..404#'..
00000010: af70 7269 6e74 2031 2e2e 3430 3423 2710 .print 1..404#'.
00000020: 8aaf ..
A Pear Tree is basically a Perl derivative, with some "interesting" features. I threw it together as a joke (so that I could say that my polyglot printed a partridge in A Pear Tree; in fact, almost all programs do). However, it's Turing-complete, and actually kind-of good at this sort of challenge.
The feature that we mostly care about here is that A Pear Tree will only run a program if some substring of the code has a CRC-32 of 00000000. The code gets rotated to put the substring in question at the start. As it happens, the two (identical) halves of the code each have the CRC-32 in question (due to that suspicious-looking binary comment at the end), so if you delete a character from the source (breaking the CRC), the other half gets rotated to the start and the # sign near the end will comment the damaged half out, in addition to the binary junk.
Another feature makes the program slightly smaller: although A Pear Tree is mostly interpreted as Perl, it has some minor changes to make it work more like Python. One that's relevant here is that unlike Perl's print statement (which just runs the numbers together), A Pear Tree's print statement separates arguments with spaces and prints a final newline. That gives us nicely space-separated output, meaning that we don't have to waste bytes on formatting. (Note that you'll have to give the program no input; if the language receives input, it assumes by default that it's supposed to do something with it.)
Of course, this can't compete with actual golfing languages (nor would I expect it to), but I thought people might find it interesting.
><>, 42 38 34 bytes
Thanks to @Martin Ender and @Teal Pelican for shaving off 8 bytes!
<<;?=*4o" e"lnll/
;?=*4o" e"lnll<
Similar to mbomb007's answer, but only uses 2 lines.
Instead of counting up from 1 to 404 using a single memory value, I continuously pushed the length of the stack. This made it so that I didn't need to put anything on the stack before the loop started, making things a lot easier.
The original code
The <s turn the IP around, and the / is a no-op, as the IP wraps around and continues along it's normal path. Thus, the relevant code is:
lnll Prints the size of the stack + 1 and pushes the stack size twice
o" e" Prints a space and pushes 101
*4 Multiplies to get 404
;?= If the number we just printed was 404, end the program
And this repeats.
The deletion
The big key here is the mirror /. It doesn't do anything if the second line is modified - only wraps back around to itself and is essentially a no-op. But if a character from the first line is removed, the line will shift down, so that the mirror hits the arrow <, leading into an identical, unmodified loop.
The only other significant deletion would be the \n character. This is also accounted for, as it produces this code:
<<;?=*4o" e"lnll/ ;?)*4o" e"lnll<
Now, we have just appended a copy of the original loop ;?=*4o" e"lnll to itself. As this is a loop, it makes no difference to the execution, and runs as if nothing had changed.
><>, 103 60 51 bytes
vv
;?=*4o" e"n:ll<<
;?=*4o" e"n:ll<<
Uses the same tactic as this program. If a character is deleted in the first line, the 2nd line will still be run. If a character in the 2nd line is deleted, the v will move execution to the 3rd line, since the 2nd line is a character shorter. A deletion in the 3rd line has no effect on program control, as it is only execution after a deletion in line 2.
The program will also work in the event that a line break is deleted:
Case 1:
The 2nd line will be run.
vv;?=*4o" e"n:ll<<
;?=*4o" e"n:ll<<
Case 2:
Both lines become one line with twice the instructions.
vv
;?=*4o" e"n:ll<<;?=*4o" e"n:ll<<
Explanation:
The core of the program is the following. Note that a 1 is pushed on the stack already by the first line.
ll:n Push length of the stack twice, duplicate, print as number
"e "o Push 101, 32, output 32 as space
4* 101 * 4 is 404
=?; Pop twice, if equal, halt
(Execution wraps around)
Befunge-93, 54 51 bytes
Thanks to Mistah Figgins for saving me 3 bytes.
111111111111111vv
+1_@#-*4"e":.:<<
+1_@#-*4"e":.:<<
This is essentially the same trick as was used in the Fault-Tolerant Hello World challenge. The first line starts by making sure there is a 1 on the top of the stack for the start of the sequence, and then one of the v arrows at the end of the line redirects the code path to the start of the main routine on line 2, executing from right to left.
Removing a character from the first line will just shift the v arrows across by one, but that still allows the code to redirect to the second line successfully. Removing a character from the second line causes the < arrow at the end of the line to shift out of the path of the v above it, so the code path will be redirected to the backup routine on line 3.
Removing the first line break does no harm, because that just moves the third line into place to replace the second line. And removing anything after the end of the second line will have no effect, because that's just the backup code.
Actually, 18 bytes
:404::404kMkMMRRSS
Actually is a stack based golfing language.
Explanation of the commands involved (as they work in the above context):
Numbers are indicated by round brackets () and lists by square brackets []
: - pushes the longest string of characters in '0123456789+-.ij' as a numeric
k - pop all the elements on the stack into a list [l] and push [l]
M - pop [l], push max([l])
pop (a), push (a)
R - pop [l], push reverse([l])
pop (a), push range([1,a])
S - pop [a], push sorted([a])
05AB1E, 12 bytes
Code:
XX440044ÔÔŸŸ
Normal code explanation:
X # Pushes the number 1.
X # Pushes the number 1 again.
440044 # Pushes the number 440044.
Ô # Connected uniquify.
Ô # Connected uniquify.
Ÿ # Inclusive range of the top two elements.
Ÿ # Inclusive range on the array, which leaves it intact.
This leads to the following golfed code: X404Ÿ, which is what we want to achieve.
The number 404 is generated by any of these variants:
440044ÔÔ
40044ÔÔ
44044ÔÔ
44004ÔÔ
440044Ô
The inclusive range works as following on two numbers:
`1 5Ÿ` -> [1, 2, 3, 4, 5]
[1, 5]Ÿ -> [1, 2, 3, 4, 5]
[1, 2, 3, 4, 5]Ÿ -> [1, 2, 3, 4, 5]
Which always makes the second Ÿ a no-op.
Uses the CP-1252 encoding. Try it online!
Pyth - 16 bytes
The basic idea behind this is that when you take a digit off of 404, it only makes the number smaller, so we just have to get the maximum of two 404's to ensure we have the right number. Obviously, there are a bunch more redundancies.
SSsetSS[404 404
Explanation:
SS First one does 1-index range, second one sorts, which is no-op
s If the e is there, this is no-op, if only t is there, it sums a one element list, which is the item
et e picks last element in list, and if e is gone, then t gets you the list without the first element which is good enough when combined with s
SS Sorting twice is no-op
[ Start list, this can't be two element because if we get rid of initial 4, the 0 becomes third element which neeeds to be captured
404 One of the 404's
<space><space>404 Need two spaces for redundancy, because 404404 *is* bigger than 404
Befunge-98, 37 bytes
20020xx##;;11++::''ee44**``kk@@::..;;
Explanation
Making radiation-hardened code in Befunge-98 isn't too bad, because you can set the "delta" (i.e. the step size of the instruction pointer) manually with x. So if set the delta to (2,0), from then on every other character is skipped and we can simply double up all commands. The tricky thing is getting 2 0 on top of the stack in a reliable way. We'll actually need 0 2 0 for the rest the program to work correctly, but we'll that for free. Here is how we do this:
20020xx
Note that each digit pushes itself, so in the full program, there will be a start 2 0 which we'll simply ignore.
Consequently, dropping either the first or second character from the program is irrelevant because we won't use those digits anyway. Likewise, removing the third character is identical to removing the second, so we don't need to worry about that either.
Let's consider what happens in the other two cases. Dropping the fourth character:
2000xx
Note the delta is set to (0,0). But this doesn't move the instruction pointer at all, so the same x is executed again immediately and this time pops the (2,0) and all is well (there are implicit zeros at the bottom of the stack for our later purposes).
Let's drop the fifth character instead:
2002xx
Now the delta gets set to (0,2). However, there is still no horizontal movement, so the IP wraps immediately back to x and again, the correct delta gets set.
From this point onward we can basically ignore the character duplication as well as this initial part because it will always be skipped:
...#;1+:'e4*`k@:.;
The ; is a sort of comment command which skips everything until the next ; is encountered. However, we jump over the first ; with # so only the part between the ; will be executed from that point onward.
1+ Increment the top of the stack.
: Duplicate it.
'e Push 101.
4* Multiply by 4 to get 404.
` Greater-than check. Pushes 1 once the top
reaches 405, otherwise 0.
k@ Terminate the program that many times.
:. Print a copy of the top of the stack (and a space).