| Bytes | Lang | Time | Link |
|---|---|---|---|
| 068 | Swift 6 | 251005T170155Z | macOSist |
| 053 | Tcl | 180929T004056Z | sergiol |
| 099 | ><> | 180928T234418Z | PidgeyUs |
| nan | Batch | 180924T155547Z | user8307 |
| 065 | Pascal FPC | 180924T214536Z | AlexRace |
| 061 | JavaScript ES7 | 180924T072309Z | Arnauld |
| 026 | Perl 6 | 180925T051118Z | Jo King |
| 040 | Scala | 180925T122008Z | trolley8 |
| 047 | C# Visual C# Interactive Compiler | 180925T112707Z | auhmaan |
| 037 | Python 2 | 180924T065746Z | TFeld |
| 043 | PHP | 180925T025126Z | user3604 |
| 008 | Jelly | 180925T013004Z | ais523 |
| 025 | V | 180924T215357Z | ბიმო |
| 012 | Jelly | 180924T205344Z | Mr. Xcod |
| 117 | TSQL | 180924T200914Z | BradC |
| 045 | Lua | 180924T164755Z | Marcio M |
| 031 | Perl 5 | 180924T194035Z | Xcali |
| 022 | Bash + jot | 180924T171521Z | Digital |
| 011 | MATL | 180924T170902Z | Luis Men |
| 062 | PHP | 180924T145448Z | Ismael M |
| 042 | Common Lisp | 180924T162049Z | Renzo |
| 020 | APL Dyalog Unicode | 180924T151332Z | J. Sall& |
| 041 | Haskell | 180924T151428Z | nimi |
| 015 | MATL | 180924T082612Z | Sanchise |
| 026 | PowerShell | 180924T145911Z | AdmBorkB |
| 019 | K oK | 180924T124201Z | mkst |
| 075 | C# .NET Core | 180924T121319Z | pocki_c |
| 084 | Java 10 | 180924T100909Z | Kevin Cr |
| 053 | Groovy | 180924T101550Z | archange |
| 014 | Japt | 180924T093126Z | Shaggy |
| 031 | Ruby | 180924T095017Z | G B |
| 087 | Batch | 180924T093400Z | Neil |
| 025 | R | 180924T083424Z | J.Doe |
| 010 | 05AB1E | 180924T073321Z | Kevin Cr |
Swift 6, 68 bytes
(0...2<<23).map{print("#"+("000000"+String($0,radix:16)).suffix(6))}
Tcl, 53 bytes
time {puts #[format %06X [expr [incr i]-1]]} 16777216
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.
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
/Venables delayed expansion, but is shorter thansetlocal EnableDelayedExpansion, which is why we need thecmdcall in the first place/Qomits the output and is equivalent to@echo off/Klets you execute an expression (In this caseg.cmd) and does not exit afterwards, so you can check the 'Array' by usingset #
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.
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}
Uses the same format as everyone else. Times out on TIO.
Or, in rgb format:
31 bytes
{map {"rgb($_)"},[X] ^256 xx 3}
C# (Visual C# Interactive Compiler), 47 bytes
Enumerable.Range(0,1<<24).Select(q=>$"#{q:X6}")
Python 2, 77 40 39 37 bytes
print['#%06X'%c for c in range(8**8)]
-1 byte thanks to Digital Trauma
-2 bytes thanks to dylnan
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 #
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
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.
APL (Dyalog Unicode), 47 43 20 bytes
'#',(⎕D,⎕A)[↑,⍳6⍴16]
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.
MATL, 17 15 bytes
10W:q'#%06X,'YD
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--$_}
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;}
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
}
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 "#"
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)
05AB1E, 15 14 10 bytes
15Ýh6ãJ'#ì
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