g | x | w | all
Bytes Lang Time Link
015UiuaSBCS240729T061920ZEurope20
012Labyrinth240730T010212ZBubbler
022JavaScript ES6201103T224046ZArnauld
031Wolfram Language Mathematica220513T204526ZRomanp
007Vyxal220427T030753ZnaffetS
337brainfuck220430T001545Znph
077Emmental220426T223147ZOhentis
00805AB1E201206T193552ZMakonede
042APOL211210T163759ZGinger
017Scala211208T211948Zcubic le
031Python 3211208T173232ZExalted
038batch211208T141310ZT3RR0R
025TIBasic211208T002457ZYouserna
016GAWK201206T223038Zcnamejj
012K oK201103T215016Zcoltim
111WebAssembly Text Format201111T053719ZScotty J
008x86 machine code201207T144749Zanatolyg
041C gcc201103T231229ZNoodle9
020JavaScript ES6201106T201554ZSamathin
021C gcc201105T150204ZG. Sliep
034C gcc201105T042027ZErikF
012Perl 5201104T142001ZDominic
044R201103T220145ZGiuseppe
026R201104T111823ZDominic
018Ruby n201104T083557Zpxeger
044Python 3201103T232129Zaidan062
012Canvas201104T134420ZRazetime
033R201103T225334ZRobin Ry
018Python 3.8 prerelease PYTHONHASHSEED=2537201104T084022Zpxeger
006Jelly201104T024411ZSisyphus
022Python 2201103T220042ZSisyphus
009Charcoal201103T221601ZNeil
008Japt !201103T220204ZShaggy
009Pyth201103T233634ZScott
00705AB1E201103T231011Zovs
007Jelly201103T222343Zlynn
028Haskell201103T222151Zlynn
010Jelly201103T213219Zcaird co
007Retina 0.8.2201103T220959ZNeil
01605AB1E201103T213454Zlyxal

UiuaSBCS, 16 15 bytes

∈"albedo"⊢⇌↯¤9

Try it here!

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%#&!@

Attempt This Online!

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

Try it online!


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)

Try it online!


JavaScript (ES6), 25 bytes

The case doesn't matter. Returns a Boolean value.

s=>parseInt(s,35)%385%3>1

Try it online!

Wolfram Language (Mathematica), 31 bytes

StringPosition[#,"ro"|"p"|"c"]&

Try it online!

Boring, but valid.

Vyxal, 7 bytes

C₈β⁺µ%∷

Try it Online!

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.

Try it online!

Emmental, 77 bytes

;#35^#49#!;#35#53#57v^:#65!A82!A79!A89!A71!A73!A86!A75!;#44v#49#45#63#66!#,?.

Try it online!

05AB1E, 14 8 bytes

-6 bytes thanks to @ovs.

'•³€å¤-à

Try it online!

'•³€å¤-à  # 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

APOL, 42 bytes

Uses Neil's answer's formula

v(0 i);!(&(|(⌕(⁰ \d) ⌕(⁰ \e)) !(⌕(⁰ \p))))

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.

Try it online!

Python 3, 38 31 bytes

-7 thanks to DLosc

lambda s:s[-2]in'egou'>'a'<s[1]

Try it online!

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/

Try it online!

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#

Try it online!

Assumes input in lower case; based off of a flipped version of @Lynn's Haskell answer.

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;}

Try it online!

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)

Try it online!

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)

Try it online!

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.

Look at the Regex here (Regex101.com)

C (gcc), 22 21 bytes

f(int*s){s=*s/203&1;}

Try it online!

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);}

Try it online!

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);}

Try it online!

Perl 5, 13 12 bytes

Edit: -1 byte by returning null string as falsy, thanks to Nahuel Fouilleul

$_=!/ro|p|c/

Try it online!

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)]

Try it online!

-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(,''))

Try it online!

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

Try it online!

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%

Try it online!

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')

Try it online!

Canvas, 12 bytes

{c]∑“N*.[„;%

Try it here!

same method as pxeger's answer.

R, 41 33 bytes

sd(utf8ToInt(scan(,"")))%%.195<.1

Try it online!

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

Try it online!

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.

Jelly, 6 bytes

,2ḥ93Ḃ

Try it online!

Uses the Jelly hashing function. 5 might be possible.

Python 2, 22 bytes

lambda s:hash(s)%683%2

Try it online!

-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

Japt -!, 13 9 8 bytes

g8 k`þ

Try it

Pyth, 9 bytes

%%Cz283 2

Try it online!

Answering my own question now that others have me beat... (FYI I solved this after posting)

Explanation:

  1. Converts to int with base 256
  2. Modulo that by 283
  3. 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“\Ṙ»

Try it online!

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

Try it online!

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€µṪ<Ẹ

Try it online!

Takes input in lowercase. Adaption of Neil's method

Golfs:

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.

05AB1E, 16 bytes

.•4W'bÓ´€‚Γ•I2£å

Try it online!

This uses the fact that there is a fixed set of possible inputs.