Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Meta

Post History

60%
+1 −0
Meta Answers that work only once

If the challenge author does not specify otherwise, should an answer be required to work repeatedly? That is, is an answer allowed to be written in a way that saves bytes by only working the first ...

0 answers  ·  posted 2d ago by trichoplax‭

Question discussion
#1: Initial revision by user avatar trichoplax‭ · 2025-05-27T15:52:52Z (2 days ago)
Answers that work only once
If the challenge author does not specify otherwise, should an answer be required to work repeatedly? That is, is an answer allowed to be written in a way that saves bytes by only working the first time it is called?

## Example
I wondered this after realising that an [existing JavaScript answer](https://codegolf.codidact.com/posts/293750/294028#answer-294028) could be shortened but that it would then only work the first time it is called.

Code at the time of writing:
```js
n=>{for(l='';n;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}
```

Potential shorter version, which does not work a second time:
```js
n=>{for(;n;l="0123456789ABCDEF"[n%16]+l,n>>=4);return l}
```

This saves 4 bytes by not initialising `l`. JavaScript works fine with an uninitialised `l`, but the value of `l` persists after the function returns, so that `l` is still holding the previous output next time the function is called, resulting in incorrect output on all subsequent calls.