| Bytes | Lang | Time | Link |
|---|---|---|---|
| 006 | Vyxal 3 | 250613T134510Z | Themooni |
| 028 | JavaScript ES6 | 190924T182422Z | Naruyoko |
| 017 | Runic Enchantments | 190709T212715Z | Draco18s |
| 004 | Lenguage | 170827T152618Z | The Fift |
| 052 | Smalltalk | 140216T180821Z | blabla99 |
| 548 | x86 assembly 32bit Linux | 110310T164443Z | J B |
| 026 | GolfScript | 110309T220726Z | aaaaaaaa |
| 066 | Ruby 1.9 | 110309T194049Z | Ventero |
| 009 | Whaddaya know | 110309T225733Z | J B |
Vyxal 3, 6 bytes
"℗i"℗i
"℗i"℗i
"℗i" # literal string
℗ # "quine cheese": quotify string and prepend it to itself
# the top of stack is now a quine.
i # index implicit input into that string.
# indexing wraps and works on negatives
# implicit output
💎
Created with the help of Luminespire.
<script type="vyxal3">
"℗i"℗i
</script>
<script>
args=[["2"],["-2"],["63"],["-1000"]]
</script>
<script src="https://themoonisacheese.github.io/snippeterpreter/snippet.js" type="module"/>
JavaScript (ES6), 28 bytes
f=n=>("f="+f).substr(n%28,1)
A modified quine.
A value larger than 28 is handled by %28, a value less than 0 is handled by .substr().
Runic Enchantments, 17 bytes
"3X4+kSq:l͍iS%%@
Just uses standard quine to generate the program string, then uses string-based modulo operator1 to get the character at a given index (which natively support negative and positive indicies, behavior influenced by Python).
- The
,"divide" command cuts the string up into chunks (logical enough inverse of*duplicating the stringxtimes),+concatenates, and-removesxcharacters from the end (a logical enough inverse of+). So the%command takes the role ofcharAt(x): the only basic string operation remaining (after stack-like operations being handled by the same commands that deal with the stack; eg.lis the size of the stack sol͍is the length of a string).
Lenguage, 4 bytes
Source code consists of 4 null bytes. Regardless of the input, the output should thus be a null byte, which is accomplished by one . instruction.
Smalltalk, 94 90 59 52
for example, in the Object class, compile:
q:n|s|s:=thisContext method source.^s at:n\\s size+1
then send q:<n> to any object; here an integer:
verification:
1 q:0 -> q
1 q:1 -> :
1 q:2 -> n
...
1 q:-1 -> )
1 q:-2 -> )
1 q:-3 -> 1
or better:
(0 to:100) collect:[:n|1 q:n]as:String
-> ')q:n|s m|s:=thisContext method source.m:=s size.^s at:(n>=0ifTrue:n-1\\m+1ifFalse:m-(0-n\\m))q:n|s m|'
(-1 downTo:-500)collect:[:n|1 q:n]as:String
-> ')m\\n-0(-m:eslaFfi1+m\\1-n:eurTfi0=>n(:ta s^.ezis s=:m.ecruos dohtem txetnoCsiht=:s|m s|n:q))m\\n-0('
explanation for non-Smalltalkers:
thisContext is the current stack frame, which can be asked for its method, which can be asked for its source.
x86 assembly (32-bit Linux, AT&T syntax): 548
No newline at end of file:
pushl 8(%esp)
call atoi
mov $274,%ebx
cmp $0,%eax
jg a
dec %eax
a:cdq
idiv %ebx
cmp $0,%edx
jge p
add %ebx,%edx
p:add $s,%edx
cmp $s+273,%edx
jl l
push $34
mov %esp,%edx
l:mov $4,%eax
mov $1,%ebx
mov %edx,%ecx
mov $1,%edx
int $128
mov $0,%ebx
mov $1,%eax
int $128
s:.ascii "pushl 8(%esp)
call atoi
mov $274,%ebx
cmp $0,%eax
jg a
dec %eax
a:cdq
idiv %ebx
cmp $0,%edx
jge p
add %ebx,%edx
p:add $s,%edx
cmp $s+273,%edx
jl l
push $34
mov %esp,%edx
l:mov $4,%eax
mov $1,%ebx
mov %edx,%ecx
mov $1,%edx
int $128
mov $0,%ebx
mov $1,%eax
int $128
s:.ascii "
I compiled it with gcc -nostartfiles -m32 qc1.S -o qc1
Verification, positive numbers:
$ for i in $(seq 548 1095); do ./qc1 $i; done | cmp - qc1.S && echo Good
Good
Verification, negative numbers:
$ for i in $(seq -1095 -548); do ./qc1 $i; done | cmp - qc1.S && echo Good
Good
Edit got it right about the weird numbering scheme. I think. It didn't change the length.
GolfScript 26 characters
{':f`f'+1/\~.1<- 26%=}:f`f
Quines were more fun before the invention of dynamic languages.
Edit: For the whiners, here is a "real" GolfScript quine, no ` and ~ only used for parsing the input.
Handicapped GolfScript 44 characters
'"\x27"\+1/\~.1<- 22%='"\x27"\+1/\~.1<- 22%=
Notice how nicely it is the same string repeated twice, so the string literal just need a ' hacked in front of it and it's ready for use.
Ruby 1.9, 66 characters
z=gets.to_i;s="z=gets.to_i;s=%p;$><<(s%%s)[z%%66]";$><<(s%s)[z%66]
Not much difference to a normal quine, actually.
- Edit: Follows the new specs now.
Whaddaya know, HQ9+ makes its great return!
Q
No need to bother indexing when there's only one character to choose from!