g | x | w | all
Bytes Lang Time Link
068Swift 6251005T170155ZmacOSist
053Tcl180929T004056Zsergiol
099><>180928T234418ZPidgeyUs
nanBatch180924T155547Zuser8307
065Pascal FPC180924T214536ZAlexRace
061JavaScript ES7180924T072309ZArnauld
026Perl 6180925T051118ZJo King
040Scala180925T122008Ztrolley8
047C# Visual C# Interactive Compiler180925T112707Zauhmaan
037Python 2180924T065746ZTFeld
043PHP180925T025126Zuser3604
008Jelly180925T013004Zais523
025V180924T215357Zბიმო
012Jelly180924T205344ZMr. Xcod
117TSQL180924T200914ZBradC
045Lua180924T164755ZMarcio M
031Perl 5180924T194035ZXcali
022Bash + jot180924T171521ZDigital
011MATL180924T170902ZLuis Men
062PHP180924T145448ZIsmael M
042Common Lisp180924T162049ZRenzo
020APL Dyalog Unicode180924T151332ZJ. Sall&
041Haskell180924T151428Znimi
015MATL180924T082612ZSanchise
026PowerShell180924T145911ZAdmBorkB
019K oK180924T124201Zmkst
075C# .NET Core180924T121319Zpocki_c
084Java 10180924T100909ZKevin Cr
053Groovy180924T101550Zarchange
014Japt180924T093126ZShaggy
031Ruby180924T095017ZG B
087Batch180924T093400ZNeil
025R180924T083424ZJ.Doe
01005AB1E180924T073321ZKevin Cr

Swift 6, 68 bytes

(0...2<<23).map{print("#"+("000000"+String($0,radix:16)).suffix(6))}

Try it on SwiftFiddle!

Tcl, 53 bytes

time {puts #[format %06X [expr [incr i]-1]]} 16777216

Try it online!

Times out on TIO, but runs fine on my machine!

><>, 99 bytes

I added an extra space here to fix the layout, because of the က character, which is 4096 or sqrt(2^24) which is used in the main loop invariant.

!/ i&"ÿĀ"::*3ep4ep5ep\1+:&:5eg%n$o:4eg,:1%-5eg%n$o3eg,:1%-5eg%noo:*&:&(?;!
 >"က"a"),,(bgr"oooo&\

The idea is pretty simple: use the register as a counter n and output rgb(n%255, (n/255)%255, (n/255^2)%255).

Pretty sure some bytes can be golfed off, but it's a start.

Try it online!

Batch, 69 + 4 = 73

g.cmd, 69

for /L %%A in (0,1,16777215)do cmd/kexit %%A&set #%%A=#!=exitcode:~2!

Saves the hexadecimal value with form #RRGGBB into an 'Array'.

g.cmd is to be called using cmd /V/Q/K g.cmd. This is where the + 4 comes from, /V/Q, counting as 4 additional characters compared to just cmd /K g.cmd. This sets up an environment that has the 'Array' in memory. It also takes forever to run, so use very low values to try or break execution using Ctrl+C


Breakdown

Invokation

g.cmd

for /L %%A IN (0,1,16777215) DO (
    cmd /k exit %%A
    set #%%A=#!=exitcode:~2!
)

This bit uses a trick documented here to convert a normal number to a hexadecimal, then saves that value into an 'Array'.


I've been calling that storing structure an 'Array' but that is not actually right as true Arrays do not exist in Batch. BUT you can name variables so that they have arraylike names, like so:

set elem[1]=First element
set elem[2]=Second one

or, like in this case:

set #1=First element
set #2=Second one

You can still access them via !#%position%!

Pascal (FPC), 67 65 bytes

Saved 2 bytes thanks to @tsh

var i:int32;begin for i:=1to 1<<24do writeln('#',hexStr(i,6))end.

Try it online!

Writes on standard output. It can be stored in an array using procedure, but it will be longer.

JavaScript (ES7), 65 62 61 bytes

Saved 3 4 bytes thanks to @tsh

Returns an array of #RRGGBB strings.

_=>[...Array(n=8**8)].map(_=>'#'+(n++).toString(16).slice(1))

Try it online! (truncated output)

Perl 6, 26 bytes

{map *.fmt("#%06X"),^8**8}

Try it online!

Uses the same format as everyone else. Times out on TIO.

Or, in rgb format:

31 bytes

{map {"rgb($_)"},[X] ^256 xx 3}

Try it online!

Scala, 40 bytes

(1 to 1<<24).map(x=>println(f"#$x%06x"))

Try it online!

C# (Visual C# Interactive Compiler), 47 bytes

Enumerable.Range(0,1<<24).Select(q=>$"#{q:X6}")

Try it online!

Python 2, 77 40 39 37 bytes

print['#%06X'%c for c in range(8**8)]

Try it online!

-1 byte thanks to Digital Trauma

-2 bytes thanks to dylnan

PHP, 43 bytes

<?php for(;$i<1<<24;printf("#%06X ",$i++));

Try it online!

Jelly, 8 bytes

ØHṗ6”#;Ɱ

Try it online! (note: uses 2 rather than 6 as 6 times out on TIO)

Function submission (because Jelly full programs will, by default, print lists of strings with no delimiters between them, making it hard to see the boundaries). The TIO link contains a wrapper to print a list of strings using newlines to separate them.

Explanation

ØHṗ6”#;Ɱ
ØH         All hex digits (“0123456789ABCDEF”)
  ṗ6       Find all strings of 6 of them (order relevant, repeats allowed)
    ”#;    Prepend “#”
       Ɱ     to each of the resulting strings

V, 25 bytes

8É00lrx16777215ñÄ<C-a>ñ0<C-v>Gls#

Try it online! (replaced 16777215 by 31)

Explanation

8É0                                " insert 8 zeroes
   0l                              " move cursor to the second character
     rx                            " replace by x
       16777215ñ      ñ            " 16777215 times do ..
                Ä                  " .. duplicate line
                 <C-a>             " .. increment (leading 0x makes sure it uses hexadecimals)
                       0<C-v>      " move cursor to beginning of line and start selection
                             Gl    " select the column with 0x
                               s#  " replace by #

Jelly, 12 bytes

⁴ṖṃØHœċ6ṭ€”#

Try it online!

T-SQL, 122 117 bytes

Returns a 16,777,216-row table of #RRGGBB strings. The line break is for readability only:

WITH t AS(SELECT 0n UNION ALL SELECT n+1FROM t WHERE n<16777215)
SELECT'#'+FORMAT(n,'X6')FROM t option(maxrecursion 0)

Uses a recursive CTE for a number table from 0 to 2^24-1, then uses the built-in FORMAT command (available in SQL 2012 or later) to turn it into a 6-digit hex string. Attach the # to the front, and we're done.

Edit 1: Removed POWER() function, the number was shorter :P

Lua, 47 45 bytes

for i=1,8^8 do s='#%06X'print(s:format(i))end

Try it online!

Perl 5, 31 bytes

printf"#%06X
",$_ for 0..8**8-1

Try it online!

Bash + jot, 22

jot -w\#%06X $[8**8] 0

Try it online!

MATL, 11 bytes

'#'5Y26Z^Yc

Try it online! (with only three hex digits instead of six)

Explanation

'#'   % Push this character
5Y2   % Push '01234567890ABCDEF'
6     % Push 6
Z^    % Cartesian power. Gives a (16^6)×6 char matrix
Yc    % String concatenation. '#' is implicitly replicated
      % Implicitly display

PHP, 68 62 bytes

This is supposed to be placed inside a file, the array is returned in the end, to be usable.

<?foreach(range(0,1<<24)as$i)$a[]=sprintf('#%06x',$i);return$a;

To have access to the array, simply give the result of the include (e.g.: $a = include 'xyz.php';) to a variable.


Thanks to @manatwork for saving me 6 bytes and fix a goof.

Common Lisp, 42 bytes

(dotimes(i 16777216)(format t"#~6,'0x "i))

Try it online!

APL (Dyalog Unicode), 47 43 20 bytes

'#',(⎕D,⎕A)[↑,⍳6⍴16]

Try it online!

Given enough time/memory, this anonymous function will output all \$2^{24}-1\$ color codes. To see this, you can swap the 6⍴ for a 4⍴ in the code, and you'll see it output every code with up to 4 digits.

Thanks to @Dzaima and @ngn for the 23 bytes.

Uses ⎕IO←0.

How:

'#',(⎕D,⎕A)[↑,⍳6⍴16] ⍝ Main function
               ⍳6⍴16  ⍝ Generate every possible 6 digit hex number in a matrix format
              ,       ⍝ Ravel the matrix (from a 16x16x16x16x16x16 matrix to a 16^6x2 list)
             ↑        ⍝ Mix; (turns the list into a 16^6x2 matrix)
    (⎕D,⎕A)[       ] ⍝ Use that matrix to index the vector of the digits 0-9 concatenated with the alphabet.
'#',                  ⍝ Then prepend a '#' to each.

Haskell, 41 bytes

l="ABCDEF"
mapM id$"#":(['0'..'9']++l<$l)

Try it online!

MATL, 17 15 bytes

10W:q'#%06X,'YD

Try it online!

The TIO version displays the first 2^10 only as not to time out. I included the final iteration in the footer to show that it indeed terminates at #FFFFFF. Saved one byte by changing to fprintf instead of manually assembling the string. Outputs a comma-separated list.

Explanation

24W:q            % Range from 0 to 2^24-1
     '#%06X,'    % fprintf format spec (# followed by hexadecimal, zero-padded, fixed-width, followed by newline)
             YD  % Call fprintf. Internally loops over range.

PowerShell, 28 26 bytes

1..16mb|%{"#{0:x6}"-f--$_}

Try it online!

Loops from 1 to 16mb (16777216). Each iteration, we use the -format operator acting on the current number pre-decremented --$_ against the string "#{0:x6}". Here, we're specifying hex values, padded to 6 digits, with a hash # in front. On TIO, limited to 60 seconds / 128KiB of output. Change the 1 to (16mb-5) to see how it ends.

K (oK), 19 bytes

Solution:

$(3#256)\'!16777216

Try it online! (limited to first 500 numbers)

Explanation:

Dump out rgb strings. Convert each number between 0 and 16777216 to base 256, then convert to strings...

$(3#256)\'!16777216 / the solution
          !16777216 / range 0..16777215
 (     )\'          / split each both
  3#256             / 256 256 256
$                   / string

C# (.NET Core), 75 bytes

()=>{int i=1<<24;var a=new string[i];for(;i-->0;)a[i]=$"#{i:X6}";return a;}

Try it online!

Port of JAVA 10 version with C# interpolated string format

Java 10, 87 84 bytes

v->{int i=1<<24;var r=new String[i];for(;i-->0;)r[i]="".format("#%06X",i);return r;}

-3 bytes thanks to @archangel.mjj.

Try it online (limited to the first 4,096 items).

Explanation:

v->{                       // Method with empty unused parameter & String-array return-type
  int i=1<<24;             //  Integer `i`, starting at 16,777,216
  var r=new String[i];     //  Result String-array of that size
  for(;i-->0;)             //  Loop `i` in the range (16777216, 0]
    r[i]=                  //   Set the `i`'th item in the array to:
      "".format("#%06X",i);//   `i` converted to a hexadecimal value (of size 6)
  return r;}               //  Return the result-array

Groovy, 53 bytes

c={a=[];(1<<24).times{a.add "".format("#%06x",it)};a}

Function definition. c() returns an ArrayList (I assume that's fine, even through the question asks for an array).

Ungolfed, with implicit types:

ArrayList<String> c = {
    ArrayList<String> a = []
    (1 << 24).times { 
        a.add("".format("#%06x", it)) // add the hex-formatted number to the list.
    }
    return a
}

Try it online!

Japt, 14 bytes

Outputs as #rrggbb.

G²³ÇsG ùT6 i'#

Try it (Limited to the first 4096 elements)


Explanation

G                  :16
 ²                 :Squared
  ³                :Cubed
   Ç               :Map the range [0,result)
    sG             :  Convert to base-16 string
       ù           :  Left pad
        T          :   With 0
         6         :   To length 6
           i'#     :  Prepend "#"

Ruby, 31 bytes

$><<("#%06x\n"*d=2**24)%[*0..d]

Try it online!

Batch, 87 bytes

@set s= in (0,1,255)do @
@for /l %%r%s%for /l %%g%s%for /l %%b%s%echo rgb(%%r,%%g,%%b)

Outputs in CSS format. The variable substitution happens before the for statement is parsed so the the actual code is as follows:

@for /l %%r in (0,1,255)do @for /l %%g in (0,1,255)do @for /l %%b in (0,1,255)do @echo rgb(%%r,%%g,%%b)

R, 25 bytes

sprintf("#%06X",1:2^24-1)

Try it online!

05AB1E, 15 14 10 bytes

15Ýh6ãJ'#ì

Try it online.

Explanation:

15Ý           # Create a list in the range [0, 15]
   h          # Convert each to a hexadecimal value
    6ã        # Create each possible sextuple combination of the list
      J       # Join them together to a single string
       '#ì    # And prepend a "#" before each of them