| Bytes | Lang | Time | Link |
|---|---|---|---|
| 022 | JavaScript V8 | 250626T065917Z | Steve Be |
| 144 | ObjectiveC macOS | 250618T193519Z | macOSist |
| 101 | Swift 6 macOS | 250606T012127Z | macOSist |
| nan | Commodore 64 Assembler | 250606T111657Z | Jani Joe |
| 044 | JavaScript | 180624T171744Z | guest271 |
| 059 | Ruby | 161216T032311Z | anna328p |
JavaScript (V8), 22 bytes
_=>a=(this.a||11)-1||z
This works in TIO but doesn't work in Node or browser environments - dereferencing a non-existent variable.
JavaScript (V8), 24 bytes
_=>a=(this.a||11)-1||a``
Crashes with Uncaught TypeError TypeError: a is not a function
Lots of alternatives for that last bit: a(), _._ etc.
Objective-C (macOS, Cocoa APIs only), 151 144 bytes
#import<ARKit/data.h>
int main(){id d=[NSUserDefaults new];int c=[d floatForKey:@""];NSLog(@"%d",c=c?c-1:10,c||d[0]);[d setFloat:c forKey:@""];}
To reset, run defaults delete a.out "" in a shell (where a.out is the executable filename).
Execution
$ /usr/bin/clang -framework Foundation main.m
…
2 warnings generated.
$ ./a.out
2025-06-18 14:24:47.059 a.out[9516:347682] 10
$ ./a.out
2025-06-18 14:25:00.957 a.out[9520:347951] 9
$ ./a.out
2025-06-18 14:25:13.050 a.out[9524:348099] 8
$ # …
$ ./a.out
2025-06-18 14:25:27.861 a.out[9552:348360] 1
$ ./a.out
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSUserDefaults objectAtIndexedSubscript:]: unrecognized selector sent to instance 0x102820f10'
…
Abort trap: 6
Swift 6 (macOS), 151 146 101 bytes
import AVKit
let d=UserDefaults(),c=d.object(forKey:"")as?Int ?? 10
print(c*c/c)
d.set(c-1,forKey:"")
The AVKit framework re-exports Foundation, so we can import it instead of Foundation to save 5 bytes.
To reset, run defaults delete swift-frontend "" in a shell.
Execution
$ swift CrashOff.swift
10
$ swift CrashOff.swift
9
$ # ...
$ swift CrashOff.swift
1
$ swift CrashOff.swift
Swift/IntegerTypes.swift:9012: Fatal error: Division by zero
...
Commodore 64 Assembler, 9 Bytes (6502/KickAssembler)
Turns out the solution I came up with is pretty much exactly like insert_name_here's 9 byte solution for Apple II+: https://codegolf.stackexchange.com/a/103322/128511 The only differences being the memory address of the ROM routine for printing out the number, and where to branch to halt/crash when the count reaches zero. I suppose this makes a lot of sense, as both machines run on 6502, and Applesoft BASIC and Commodore BASIC are both just variations of Microsoft BASIC. I wasn't aware of the similarities in their BASICs until now. Live and learn. 😁 Anyway, on to the answer.
Code
* = $b1
dec $b6
beq $76
ldx #11
jmp $bdcf
Explanation
* = $b1puts the code on zero page in an area which isn't used at the time when the program is loaded & run. This allows us to save a byte in the first command. The code can be run from BASIC with the command SYS 177.dec $b6decrements the number onldx #11line by one. As mentioned above, as code is located on zero page we save a byte here (dec [8bit address]instead ofdec [16bit address]).- When the decrement results to the value being zero,
beq $76branches to address $76, which is in the middle of KERNAL's CHRGET routine, and happens to contain a byte value $02, also called a JAM or KIL command. When the CPU executes this command it locks up and thus halts the system. ldx #numberloads the decrementing number into X register. If we get onto this line, our countdown hasn't reached zero yet.jmp $bdcfjumps into the ROM routine for printing a decimal value for a 16bit number. Usually one would have the low byte in X and high byte in A when the routine gets called from address $bdcd, and in the beginning of the routine A is stored to memory location $62 and X to $63. However if we skip the first two bytes of the routine the value in A is ignored and whatever happens to be in $62 is used instead. It just so happens that $62 is conveniently always zero after running the SYS command to start up our program, thus we don't need to explicitly set it to zero. This saves us a byte. Otherwise we would have had to addtxato the beginning of our program to clear A (X is always zero after SYS).
JavaScript, 44 bytes
function* f(n=11){for(;--n;yield n);throw''}
p=f()
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
console.log(p.next().value)
Ruby, 94 87 84 61 59 bytes
j=File.open(?a,"a+");1/(i=j.readlines.size-14);p -i;j.puts
Please leave suggestions below.
Thanks @ConorO'Brien for the ideas (some shamelessly ripped off from his answer).