| Bytes | Lang | Time | Link |
|---|---|---|---|
| 015 | UiuaSBCS | 240729T061920Z | Europe20 |
| 012 | Labyrinth | 240730T010212Z | Bubbler |
| 022 | JavaScript ES6 | 201103T224046Z | Arnauld |
| 031 | Wolfram Language Mathematica | 220513T204526Z | Romanp |
| 007 | Vyxal | 220427T030753Z | naffetS |
| 337 | brainfuck | 220430T001545Z | nph |
| 077 | Emmental | 220426T223147Z | Ohentis |
| 008 | 05AB1E | 201206T193552Z | Makonede |
| 042 | APOL | 211210T163759Z | Ginger |
| 017 | Scala | 211208T211948Z | cubic le |
| 031 | Python 3 | 211208T173232Z | Exalted |
| 038 | batch | 211208T141310Z | T3RR0R |
| 025 | TIBasic | 211208T002457Z | Youserna |
| 016 | GAWK | 201206T223038Z | cnamejj |
| 012 | K oK | 201103T215016Z | coltim |
| 111 | WebAssembly Text Format | 201111T053719Z | Scotty J |
| 008 | x86 machine code | 201207T144749Z | anatolyg |
| 041 | C gcc | 201103T231229Z | Noodle9 |
| 020 | JavaScript ES6 | 201106T201554Z | Samathin |
| 021 | C gcc | 201105T150204Z | G. Sliep |
| 034 | C gcc | 201105T042027Z | ErikF |
| 012 | Perl 5 | 201104T142001Z | Dominic |
| 044 | R | 201103T220145Z | Giuseppe |
| 026 | R | 201104T111823Z | Dominic |
| 018 | Ruby n | 201104T083557Z | pxeger |
| 044 | Python 3 | 201103T232129Z | aidan062 |
| 012 | Canvas | 201104T134420Z | Razetime |
| 033 | R | 201103T225334Z | Robin Ry |
| 018 | Python 3.8 prerelease PYTHONHASHSEED=2537 | 201104T084022Z | pxeger |
| 006 | Jelly | 201104T024411Z | Sisyphus |
| 022 | Python 2 | 201103T220042Z | Sisyphus |
| 009 | Charcoal | 201103T221601Z | Neil |
| 008 | Japt ! | 201103T220204Z | Shaggy |
| 009 | Pyth | 201103T233634Z | Scott |
| 007 | 05AB1E | 201103T231011Z | ovs |
| 007 | Jelly | 201103T222343Z | lynn |
| 028 | Haskell | 201103T222151Z | lynn |
| 010 | Jelly | 201103T213219Z | caird co |
| 007 | Retina 0.8.2 | 201103T220959Z | Neil |
| 016 | 05AB1E | 201103T213454Z | lyxal |
UiuaSBCS, 16 15 bytes
∈"albedo"⊢⇌↯¤9
Translation of lynn's the ninth element with wrapping is one of "albedo" logic. Without a ⬚ fill value, ↯ reshape wraps. Add ⌵ absolute value at the end for case-insensitivity.
Explanation
∈"albedo"⊢⇌↯¤9
⊢⇌ Is the last element
↯¤9 of the string with the length changed to 9
∈"albedo" one of the letters "albedo"?
Labyrinth, 12 bytes
36
+,57%#&!@
Takes a lowercase word and prints 1 for rainbow colors and 0 for others.
Found by a Python script. The script as-is outputs all possible 2-command combinations that can go on the top row, along with "good" partial results after a modulo. As the target byte count decreases, the candidates can be reduced significantly, ending with this which gives no better option than the program above.
The algorithm looks like this:
x = 36
for c in input:
x += c
x = x * 100 + 36
x %= -157
print(x & 1)
Digit commands in Labyrinth appends itself to the number at the top. , is the character input command, which pushes -1 on EOF. # (stack height) is used to push 1.
JavaScript (ES6), 22 bytes
Suggested by Andrew Bayly
Returns 0 or 8.
s=>parseInt(s,35)/37&8
JavaScript (ES9), 23 bytes
Similar to Neil's Retina answer, but with a negative lookbehind to prevent purple from being matched.
s=>/d|(?<!pl)e/.test(s)
JavaScript (ES6), 25 bytes
The case doesn't matter. Returns a Boolean value.
s=>parseInt(s,35)%385%3>1
Vyxal, 7 bytes
C₈β⁺µ%∷
How?
C₈β⁺µ%∷
C # Character codes of (implicit) input
β # Convert from base...
₈ # ...256
⁺µ # Push 283
% # Modulo
∷ # Parity (a % 2)
brainfuck, 370 337 bytes
,>+>+<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]-[<++>-------]<--[<->[-]]<+<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]-[<-->-----]<+++[<->[-]]<+<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]-[<++>-------]<+[<->[-]]<[[-]<->]<[>+<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]-[<-->-----]<++++[<<<<+>>>>[-]<->]<[>,>-[<-->+++++++++]<[<<<<+>>>>[-]]<-]<-]<<[>>+>+<<<-]>>>[<<<+>>>-]-[<+>-----]<---.
Works by taking input, and returning 0 if it is p, c, or m, if it is b it takes input again to differentiate between blue and brown. Otherwise, it returns 1.
Emmental, 77 bytes
;#35^#49#!;#35#53#57v^:#65!A82!A79!A89!A71!A73!A86!A75!;#44v#49#45#63#66!#,?.
05AB1E, 14 8 bytes
-6 bytes thanks to @ovs.
'•³€å¤-à
'•³€å¤-à # full program
- # subtract...
¤ # last element of...
å # is...
€ # each character of...
# implicit input...
å # in...
'•³ # "deep"...
- # from...
# (implicit) each element of...
å # is...
€ # each character of...
# implicit input...
å # in...
'•³ # "deep"
à # greatest element of list
# implicit output
Scala, 17 bytes
_.product%237<132
Computes the product of the characters' ASCII values modulo 237 and checks whether the result is smaller than 132. Expects its input in title case.
Python 3, 38 31 bytes
-7 thanks to DLosc
lambda s:s[-2]in'egou'>'a'<s[1]
Just tests the second and second-to-last characters. Takes a different approach to aidan0626's submission and doesn't rely on custom hash seeds like pxeger's.
batch 38 bytes
@Echo(%1|findstr/li "e i"|find/v /i"p"
run from cmd.exe, input via parameter 1 is case insensitive.
Pipes input through findstr matching against e or i, pipes matches to find, rejecting any input matching p. outputs the input color if a rainbow color, nothing if the input is not a rainbow color.
Also returns 1 false or 0 true in the errorlevel.
TI-Basic, 25 bytes
inString(Ans,"D") or inString(Ans,"E") and not(inString(Ans,"P
Port of this answer. Takes input in uppercase in Ans. Output is stored in Ans and displayed.
GAWK, 18 16 bytes
(-2 thanks to Dominic van Essen)
2>$0=/[de]/*!/p/
Translation of Neil's has "d" or "e" but not "p" logic. Uses "2>" to make sure the condition is always true for any input, and sets $0 to truthy/falsey so that the default action, which is print $0, will output the result.
K (oK), 23 19 18 12 bytes
^"rwpc"?*|9#
Assumes input in lower case; based off of a flipped version of @Lynn's Haskell answer.
9#repeating-take 9 characters of the input, e.g. "purplepur"*|first-reverse, i.e. last"rwpc"?lookup character in the string "rwpc", returning either the index of the match, or a null if not present^check ifnull, i.e. convert nulls to1and actual indices to0
WebAssembly Text Format, 111 bytes
(func(result i32)i32.const 0 i32.load i32.const 8 i32.load i32.add i32.const 13 i32.rem_s i32.const 7 i32.le_s)
This function operates on an integer memory array, that should start pre-filled with the chosen color (in Title Case) as a list of ascii code points. (strings can't be provided as normal function arguments in webassembly). The function will return 1 if its a rainbow color, or 0 if its not.
The actual logic behind the function is effectively the following: return (mem[0] + mem[8]) % 13 <= 7. (each character of the color takes 4 bytes in the memory array so byte-index 8 refers to a character-index 2). The actual WebAssembly Text Format is designed to feel like a stack machine, so instructions like i32.const 8 puts an 8 onto the stack while i32.add will take two items off the stack, add them, and put the result back on.
The following is a complete WebAssembly file with the above function embedded inside.
(module
(import "api" "mem" (memory 1))
(func(result i32)i32.const 0 i32.load i32.const 8 i32.load i32.add i32.const 13 i32.rem_s i32.const 7 i32.le_s)
(export "check" (func 0))
)
This can be compiled to a WebAssembly binary (a binary wasm file can be generated and downloaded through online wat to wasm conversion tools like this one).
The following javascript runs the compiled binary. It contains the logic to create the memory array, pre-filled with a color. For convenience, it has the binary WebAssembly embedded in it.
// Byte array generated by putting the WAT text into https://mbebenita.github.io/WasmExplorer/
// then downloading the resulting wasm file
// then running [...require('fs').readFileSync('path/to/file.wasm')]
const bytes = new Uint8Array([0,97,115,109,1,0,0,0,1,133,128,128,128,0,1,96,0,1,127,2,140,128,128,128,0,1,3,97,112,105,3,109,101,109,2,0,1,3,130,128,128,128,0,1,0,6,129,128,128,128,0,0,7,137,128,128,128,0,1,5,99,104,101,99,107,0,0,10,153,128,128,128,0,1,147,128,128,128,0,0,65,0,40,2,0,65,8,40,2,0,106,65,13,111,65,7,76,11])
// Alternativly, you can read from the raw wasm file after generating it.
// const bytes = require('fs').readFileSync('./output.wasm')
async function initWaModule() {
const mem = new WebAssembly.Memory({initial:1})
const { instance } = await WebAssembly.instantiate(bytes, { api: {mem}, })
return {
isRainbowColor(color) {
// Insert color param into memory
const i32Array = new Uint32Array(mem.buffer);
i32Array.fill(0)
const colorAsCodePoints = [...color].map(c => c.charCodeAt(0))
i32Array.set(colorAsCodePoints)
// Run webassembly function
return !!instance.exports.check()
}
}
}
const TRUE_COLORS = ['Red', 'Orange', 'Yellow', 'Green', 'Blue', 'Indigo', 'Violet']
const FALSE_COLORS = ['Purple', 'Brown', 'Pink', 'Cyan', 'Maroon']
;(async () => {
const { isRainbowColor } = await initWaModule()
console.log('These should be true')
TRUE_COLORS.forEach(color => console.log(color, isRainbowColor(color)))
console.log('These should be false')
FALSE_COLORS.forEach(color => console.log(color, isRainbowColor(color)))
})()
x86 machine code, 8 bytes
Hexdump:
6b 01 e7 c1 e8 0a d6 c3
Multiplies the 32-bit value at string start by -25, and extracts bit 9 from the result. Returns al = -1 for rainbow colours, and al = 0 for non-standard ones.
Disassembly:
6B 01 E7 imul eax,dword ptr [ecx],0FFFFFFE7h
C1 E8 0A shr eax,0Ah
?? ?? ??
C3 ret
Here, ?? ?? represents the "undocumented" SALC instruction.
C (gcc), 46 42 41 bytes
Saved 4 bytes thanks to gastropner!!!
Saved a byte thanks to Samathingamajig!!!
f(char*s){s=*s-80&&*s-77&&*s-67&s[3]-87;}
Inputs the colour all in caps and return \$1\$ for a colour of the rainbow or \$0\$ otherwise.
JavaScript (ES6), 20 bytes
s=>!/ro|p|c/.test(s)
How it works: Get a truthy value if ro is present, p is present, or c is present, then inverts that value so if they are present, the result is falsey, otherwise the result is truthy
Look at the regex here (Regex101.com)
JavaScript (ES6), 22 bytes
s=>!/p|[^e]n$/.test(s)
How it works: Get a truthy value if it starts with p or ends in n without an e before it. The ! inverts that value so it returns true if no match and false if there is a match. I've tried multiple other regex's that end up being the same length, so i went with this one since it's easy enough to explain.
C (gcc), 22 21 bytes
f(int*s){s=*s/203&1;}
Inspired by ErikF's answer. I wrote a little program to brute-force the constants.
C (gcc), 34 bytes
Function takes a lowercase colour and returns 1 if it is rainbow colour, otherwise 0.
To save space, I hash the first four characters of the colour with modulo 81 (the first number that didn't have collisions and had all printable remainders) and search for that in the list of hashes for the non-rainbow colours. If there is no match, then it is a rainbow colour.
f(int*s){s=!index("D@M1&",*s%81);}
I could save two bytes if returning 0 for a rainbow colour and non-zero for a non-rainbow was allowed:
f(int*s){!index("D@M1&",*s%81);}
Perl 5, 13 12 bytes
Edit: -1 byte by returning null string as falsy, thanks to Nahuel Fouilleul
$_=!/ro|p|c/
Same approach as my R answer (with help from Dom Hastings + Caird Coinheringaahing), but probably better suited to [Perl]...
(Edit: realized that porting Neil's Retina answer is actually shorter at also only now slightly longer at 13 bytes)
R, 60 44 bytes
!scan(,"")%in%colors()[c(547,32,536,68,455)]
-13 thanks to Robin Ryder.
Takes input as all lowercase. Checks to see if the color is not one of the excluded colors.
Outgolfed by Robin Ryder and Dominic van Essen.
R, 35 28 27 26 bytes
Edit: -1 byte thanks to Dom Hastings, and -1 byte thanks to caird coinheringaahing
!grepl("ro|p|c",scan(,''))
Regular-expression check.
'maroon' + 'brown' both contain 'ro', 'purple' and 'pink' both contain 'p', and 'cyan' contains 'c'.
Ruby -n, 18 bytes
p 255969480%$_.sum
Input in Title Case, output is either a truthy integer or falsey zero.
\$255969480\$ is the lowest common multiple of the sums of all of the Title Cased truthy strings, which is also not a multiple of any of the sums of the Title Cased falsey strings. The reason I use Title Case is because the sums share a lot of common factors, reducing the length of the number. This could definitely be ported to various golfing languages to save lots of bytes, which I might do. see below!
05AB1E, 14 10 bytes
ÇO•F;_â•s%
Same method as the above - input in Title Case, output as either 0 for false or a positive integer for true
Python 3, 71 56 44 bytes
-15 bytes thanks to @Scott
-12 bytes thanks to @ovs
lambda s:(s[0]<'c'<'r'==s[1])==(s[0]in'pcm')
R, 41 33 bytes
sd(utf8ToInt(scan(,"")))%%.195<.1
Less elegant than Giuseppe's solution, but 3 11 bytes shorter.
Converts the (lowercase) input to ASCII codepoints, takes the standard deviation of the resulting integers, then takes that modulo 0.195 (found by a grid search). The result is less than 0.1 iff the input is truthy.
Python 3.8 (pre-release) PYTHONHASHSEED=2537, 18 bytes
lambda x:hash(x)%2
I'm pretty sure this is allowed. An environment variable is just like a command-line option, so this is considered a separate programming language to normal Python. Input in lowercase, outputs 1 or 0.
Python 2, 22 bytes
lambda s:hash(s)%683%2
-1 thanks to ovs, who used the extra degree of freedom afforded by the flexible input casing to save a byte.
Charcoal, 10 9 bytes
›⁶³﹪⍘Sβ⁹⁴
Try it online! Link is to verbose version of code. Takes input in lower case. Output is a Charcoal boolean, i.e. - if rainbow, nothing if not. Explanation:
S Input word
⍘ β Decoded as base 26 using lowercase alphabet
﹪ ⁹⁴ Modulo literal 94
›⁶³ Check whether 63 is greater than the result
Implicitly print
Pyth, 9 bytes
%%Cz283 2
Answering my own question now that others have me beat... (FYI I solved this after posting)
Explanation:
- Converts to int with base 256
- Modulo that by 283
- Modulo by 2.
1 if rainbow color, 0 if not.
05AB1E, 7 bytes
Takes input in lower case.
CƵl%3%È
Try it online! or Verify all cases!
C converts the color from binary. This allows digits higher than 1, where upper case characters are 10 to 35 and lower case 36 to 61:
C("red") = "r"*2**2 + "e"*2**1 + "d"*2**0 = 53*4 + 40*2 + 39 = 331
Ƶl is the compressed integer 148, the code computes
is C(color)%148%3 Èven?
Jelly, 8 7 bytes
9ịe“\Ṙ»
Get the ninth character (wrapping) and check if it's in the compressed string “\Ṙ» = “albedo”.
Port of my Haskell answer. caird saved a byte: the coincidence that albedo is an English word actually wins bytes over 9ịe“albedo or 9ịḟ“rwpc, owing to Jelly's compression dictionary.
Haskell, 28 bytes
(`elem`"albedo").(!!8).cycle
If we wrap the input and index at position 8, the rainbow colors all yield a letter among "albedo", but the non-rainbow colors do not (they yield a letter among "rwpc").
redredre d red
orangeor a nge
yellowye l low
greengre e ngr
blueblue b lue
indigoin d igo
violetvi o let
purplepu r ple
brownbro w nbr
pinkpink p ink
cyancyan c yan
maroonma r oon
Jelly, 21 14 12 10 bytes
“dʋ»e€µṪ<Ẹ
Takes input in lowercase. Adaption of Neil's method
Golfs:
- -10 bytes by changing the compressed string
- -5 bytes by adapting coltim's method
- -2 bytes by using Neil's method
How it works
“dʋ»e€µṪ<Ẹ - Main link. Takes S on the left
“dʋ» - Compressed string; Yield "dep"
€ - For each character in "dep":
e - Is it in S?
µ - Use this triplet as the new argument
Ṫ - Take the final element (1 if p is present, else 0)
Ẹ - Are either "d" or "e" in S?
< - The tail is 0 and either "d" or "e" are in S
Retina 0.8.2, 7 bytes
A`p
d|e
Try it online! Link includes test cases. Assumes input in lower case. Outputs non-zero for rainbow colours, zero for the other inputs. Explanation: Simply checks that the colour contains the letters d or e but not p.
64-byte version to check against the 21 specific cases of rainbow colours in three different capitalisations:
T`L`l`^[A-Z]+$|^.
^(red|orange|yellow|green|blue|indigo|violet)$
Try it online! Link includes test cases. Explanation: Either an uppercase input or the leading character is lowercased, after which the exact colours are matched.