97
\$\begingroup\$

As you probably know, there is a war going on in Ukraine. I noticed that it seems nobody has posted a Ukrainian flag challenge yet, so I thought I'd do it myself in support of Ukraine.

The Challenge

Here is the flag: Flag of Ukraine

  • The flag is divided horizontally across the middle into two equally sized stripes.
  • Stripe colors: (0, 87, 183) or #0057B7 (blue, top) and (255, 215, 0) or #FFD700 (yellow, bottom).
  • Colors must be exact if possible, otherwise use the closest available blue and yellow.
  • The image can be saved to a file or piped raw to STDOUT in any common image file format, or it can be displayed in a window.
  • The image must be sized at a 3:2 ratio, and at least 78 by 52 pixels.
  • Alternatively, output a block of text at least 78 characters wide made of non-whitespace characters that depicts the flag, using ANSI color codes to color it. (Use standard blue and yellow.)
  • Built-in flag images, flag-drawing libraries, or horrendously upscaling the Ukrainian flag emoji are prohibited.

This is , so shortest code wins!

\$\endgroup\$
16
  • 1
    \$\begingroup\$ If the ANSI color code option is chosen, what aspect ratio should we assume each character has? \$\endgroup\$ Commented Mar 19, 2022 at 16:38
  • 2
    \$\begingroup\$ @des54321 It must be exact. \$\endgroup\$ Commented Mar 19, 2022 at 18:53
  • 8
    \$\begingroup\$ Unless I'm misunderstanding the QBasic answer already posted, I think that answer has inexact colors due to limitations of the language, but it is certainly likely other ancient languages could also have too-limited color-spaces to display the correct colors \$\endgroup\$ Commented Mar 19, 2022 at 19:42
  • 3
    \$\begingroup\$ Related: codegolf.stackexchange.com/questions/230438/create-a-pride-flag \$\endgroup\$ Commented Mar 20, 2022 at 5:10
  • 2
    \$\begingroup\$ Just pointing out that the yellow in the image above is #fbd02a and the blue is #1a54b2, as opposed to the #ffd700 and #0057b7 specified in the text. \$\endgroup\$ Commented Mar 21, 2022 at 22:48

90 Answers 90

1 2
3
6
\$\begingroup\$

Python + Pygame (122 bytes)

import pygame.display as p
s=p.set_mode((78,52))
s.fill((0,87,183),(0,0,78,26))
s.fill((255,215,0),(0,26,78,26))
p.flip()

Briefly flashes the flag on the screen before exiting.

enter image description here

\$\endgroup\$
6
\$\begingroup\$

PostScript, 55 43 bytes

00000000: 3188 0238 5b2e 3030 3288 0030 202d 2e30  1..8[.002..0 -.0
00000010: 3036 8800 325d 2800 57b7 ffd7 2992 a333  06..2](.W...)..3
00000020: 2063 6f6c 6f72 696d 6167 65               colorimage

Tokenized version of:

1 2 8[.002 0 0 -.006 0 2]<0057b7ffd7>stopped 3 colorimage

The original solution without binary tokens was a bit shorter at 55 bytes:

1 2 8[.002 0 0 -.006 0 2]<0057b7ffd7>false 3 colorimage

These all use a stretched a 1x2 bitmap. To view, run through Ghostscript. output

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Code Golf, and nice first answer! \$\endgroup\$ Commented Apr 11, 2022 at 16:14
6
\$\begingroup\$

C# (.NET Framework), 163 chars

Shorter version of Björn Larsson's answer.

void Draw(){var f=new Bitmap(78,52);for(int y=0;y<52;y++)for(int x=0;x<78;x++)f.SetPixel(x,y,Color.FromArgb(y>25?255:0,y>25?215:87,y>25?0:183));f.Save("f.bmp");}

Effective version with explanation:

using System.Drawing;

namespace Ukraine {
    internal class Program {
        static void Main() {
            // Create a bitmap.
            var f = new Bitmap(78, 52);

            // Iterate over the bitmap's pixels.
            for (int y = 0; y < 52; y++) {
                for (int x = 0; x < 78; x++) {
                    f.SetPixel(                  // Set the pixel...
                        x, y,                    // at the current x and y...
                        Color.FromArgb(
                            y > 25 ? 255 : 0,    // selecting the R value with a ternary expression...
                            y > 25 ? 215 : 87,   // selecting the G value with a ternary expression...
                            y > 25 ? 0 : 183)    // and selecting the B value with a ternary expression.
                        );
                }
            }

            // Save the bitmap.
            f.Save("f.bmp");
        }
    }
}

Produces an image in the exe's folder:

enter image description here

\$\endgroup\$
3
  • \$\begingroup\$ Welcome to Code Golf! One thing to note is that snippets are not allowed by our rules, so you would have to wrap this in a full program (all the Main stuff and whatnot). \$\endgroup\$ Commented Jul 7, 2022 at 16:27
  • 1
    \$\begingroup\$ A function would also be allowed \$\endgroup\$ Commented Jul 7, 2022 at 16:30
  • \$\begingroup\$ @Seggan C# supports top-level code nowadays. \$\endgroup\$ Commented Sep 25, 2022 at 18:37
6
\$\begingroup\$

SVG, 132 bytes

<svg width="300"height="200"><rect width="300"height="100"fill="#0057b7"/><rect y="100"width="300"height="100"fill="#ffd700"/></svg>

\$\endgroup\$
6
\$\begingroup\$

JavaScript (Node.js), 94 bytes

Prints a solid flag (or not quite, depending on your font) in the specified rgb colors.

for(i=1;i<4108;i++)process.stdout.write(i%79?`\x1b[38;2;${i<2054?'0;87;183':'255;215;0'}m█`:`
`)
\$\endgroup\$
6
\$\begingroup\$

WP2, 32 bytes

VWtsR1JpSUFBQUJYUlVKUVZsQTRUQlVBQUFBdlRjQU1BQkNRSkVQYjNUUmgvbWUzLzVuVUgvVUEK

WP2 (WebP2) is an image format based on AVIF. It's state-of-the-art in the field of DCT-based image formats, as far as I'm aware. It's also really good at lossless compression.

Encoded in Base64 RFC4648

\$\endgroup\$
6
\$\begingroup\$

Ruby + paint, 73 bytes

You do need the paint gem installed, from rubygems: gem install paint

Update:

Thanks to manatwork for the much shorter:

require'paint';['#0057b7','#ffd700'].map{|c|5.times{puts Paint[?█*37,c]}}

Original attempt (127 bytes):

require'paint';c=['#0057b7','#ffd700'];(0..1).each do |i|;(0..4).each do;(0..36).each do;print Paint['█',c[i]];end;puts;end;end

console output of Ukrainian flag from code.

\$\endgroup\$
3
  • 2
    \$\begingroup\$ Nice try, but not really matches the goal of code-golf challenges. May I suggest the mostly equivalent require'paint';['#0057b7','#ffd700'].map{|c|5.times{puts Paint[?█*37,c]}}? \$\endgroup\$ Commented Sep 25, 2022 at 12:14
  • \$\begingroup\$ Thanks @manatwork! I haven't used Ruby in a bit, but that's much shorter. \$\endgroup\$ Commented Sep 25, 2022 at 18:26
  • 1
    \$\begingroup\$ You can use a word array to save 2 bytes require'paint';%w(#0057b7 #ffd700).map{|c|5.times{puts Paint[?█*37,c]}} \$\endgroup\$ Commented Oct 4, 2022 at 23:31
6
\$\begingroup\$

Ruby with Shoes, 96 characters

Shoes.app(width:78,height:52){background rgb 0,87,183
stroke fill rgb 255,215,0
rect 0,26,78,52}

Sample output:

flag of Ukraina

\$\endgroup\$
6
\$\begingroup\$

Lua + LÖVE, 154 characters

l=love
g=l.graphics
c=255
l.window.setMode(78,52)function l.draw()g.setBackgroundColor(0,87/c,183/c)g.setColor(1,215/c,0)g.rectangle("fill",0,26,78,52)end

Sample output:

flag of Ukraina

\$\endgroup\$
6
\$\begingroup\$

FLTK, 153 characters

Function{}{}{Fl_Window{}{xywh{9 9 78 52}}{Fl_Box{}{xywh{0 0 78 26}box FLAT_BOX color 0x0057b7ff}Fl_Box{}{xywh{0 26 78 52}box FLAT_BOX color 0xffd700ff}}}

Ungolfed:

Function {} {} {
    Fl_Window {} {
        xywh {9 9 78 52}
    } {
        Fl_Box {} {
            xywh {0 0 78 26}
            box FLAT_BOX
            color 0x0057b7ff
        }
        Fl_Box {} {
            xywh {0 26 78 52}
            box FLAT_BOX
            color 0xffd700ff
        }
    }
}

Sample output:

flag of Ukraina

\$\endgroup\$
6
\$\begingroup\$

C (MSVC) + Win32, 106 bytes

r[4];p(c){FillRect(GetDC(0),r,CreateSolidBrush(c));}main(){*r=600;r[1]=200;p(12344064);r[3]=400;p(55039);}

Draws the flag onto the top window: enter image description here

\$\endgroup\$
6
\$\begingroup\$

Python (Thonny 4.0 REPL), 419 bytes

print("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAARMAAAC3CAMAAAAGjUrGAAAAD1BMVEUAW7v/1QAAVb+ln3n/2QAG3wIgAAAAzUlEQVR4nO3QsQGAMAzAsBT4/2b2eO0onaAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACASx62ednmY5vD5qSclJNyUk7KSTkpJ+WknJSTclJOykk5KSflpJyUk3JSTspJOSkn5aSclJNyUk7KSTkpJ+WknJSTclJOykk5KSflpJyUk3JSTspJOSkn5aSclJNyUk7KSTkpJ+WknJSTclJOykk5KSflpJyUk3JSTspJOSkn5aSclJNyUk7KSTkpJ+WknJSTclJOykk5KSflpH7zk2pa0LCuDAAAAABJRU5ErkJggg==")

Longer than a standard answer but ok. Thonny supports printing images if they’re in base64 form.

enter image description here

\$\endgroup\$
1
  • \$\begingroup\$ Your first answer is valid, if a little long (although I'd change the title to something like "Python 3 (Thonny REPL), 419 bytes"; your second answer isn't valid as it's not actually a program which outputs the image. (And the image isn't correctly formatted anyway.) \$\endgroup\$ Commented Dec 27, 2022 at 17:10
6
\$\begingroup\$

HTML, 200 Bytes

<mark style="background-color:blue"id="a"></mark><mark id="b"></mark><script>document.getElementById("a").innerHTML=document.getElementById("b").innerHTML=(" ".repeat(78)+"<br>").repeat(26)</script>

Those poor Ukrainians... 😔

You should click on the link to render the full page after running the code.

Prints the Ukrainian flag (although it's missing a trident unfortunately) using <mark> tags to render the colours. Uses a script to insert the text. Uses U+2001 EM QUAD as a blank character.

\$\endgroup\$
1
  • \$\begingroup\$ You can use background in place of background-color. \$\endgroup\$ Commented Sep 10, 2023 at 16:57
6
\$\begingroup\$

JavaScript (Node.js), 76 74 bytes

for(i=o=[];i<2400;i++)o+=i%60?[...'🟦🟨'][i/1200|0]:`
`;console.log(o)

Try it online!

flag

\$\endgroup\$
1
  • \$\begingroup\$ 58 \$\endgroup\$ Commented May 15, 2025 at 6:46
6
\$\begingroup\$

Uiua, 36 bytes

&ims÷255⊂∩(↯26↯78)0_87_183 255_215_0

Try it in the pad!

Explanation

0_87_183 255_215_0: Push the RGB values on the stack

∩(…): Apply this function to both values:

  • ↯26↯78: Reshape them so they become stripes

&ims÷255⊂: Join them together and divide by 255, then show as an image

\$\endgroup\$
1
  • \$\begingroup\$ why is this my most upvoted uiua answer? it's by far the most boring one \$\endgroup\$ Commented May 8, 2025 at 18:12
5
\$\begingroup\$

MSWLogo, I'm assuming 173 167 bytes.

to f :a :b :c :y
setpos(list 0 :y)
setpc(list :a :b :c)
repeat 2[fd 26 rt 90 fd 72 rt 90]
setpos(list 1 :y+1)
setfc(list :a :b :c)
fill
end
f 225 215 0 0 f 0 87 153 26

enter image description here

\$\endgroup\$
2
  • \$\begingroup\$ MSWLego? Didn't know they were doing code golf \$\endgroup\$ Commented Mar 21, 2022 at 15:00
  • \$\begingroup\$ @Ginger lol. saw a Scratch answer and I just thought to myself: "Let's do this in Logo" \$\endgroup\$ Commented Mar 22, 2022 at 1:12
5
\$\begingroup\$

Dyalog APL,55 byte

(⊂'P3 78 52 255 ',⍕,⍉2028/(3⍴256)⊤22455 16766720)∘⎕NPUT

Write a plain text PPM image to provided filename.

Sample

$ cat out.ppm
P3 78 52 255 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87
183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87
...
183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87 183 0 87
183 0 87 183 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0
255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0
255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0 255 215 0
...

\$\endgroup\$
5
\$\begingroup\$

Haskell, 83 81 69 bytes

My first haskell submission.

This code defines a function that prints the flag to stdout using ansi escape codes.

n?s=[1..n]>>s
putStr$"43">>= \c->13?(78?("\27[4"++c:"m \27[m")++"\n")

enter image description here

\$\endgroup\$
5
\$\begingroup\$

PHP Imagick (209 chars)

Draw and output the image to the browser (Imagick is a native PHP extension).
No line break are needed for execution :

header('Content-Type:image/png');
$d=new\ImagickDraw();
$d->setFillColor('#0057B7');
$d->rectangle(0,0,990,330);
$i=new\Imagick();
$i->newImage(990,660,'#FFD700');
$i->setImageFormat('png');
$i->drawImage($d);
echo$i;

Programming Golf Ukrainian Flag with PHP Imagick

\$\endgroup\$
5
\$\begingroup\$

Python 3, 330 273 bytes

The following piece of code shows the Ukrainian flag in coloured text when executed in the Windows Command Prompt

import sys
from termcolor import *
import os
os.system("")
t=colored("#","blue",attrs=["reverse","blink"])
for x in range(26):
    for x in range(78):
        print(end=t)
    print()
t=colored("#","yellow",attrs=["reverse","blink"])
for x in range(26):
    for x in range(78):
        print(end=t)
    print()

Try It Online is not available, for the reason it wouldn't display the colours.

\$\endgroup\$
2
  • \$\begingroup\$ Can golf this down to 273 bytes by trimming indent whitespace, using an import*, print(end=t) instead of print(t,end=""), and some smarter iterators because you arent using the value x in the for loops \$\endgroup\$ Commented Mar 25, 2022 at 17:47
  • \$\begingroup\$ When running on linux you can safely remove the os.system("") line \$\endgroup\$ Commented Jun 21, 2022 at 10:39
5
\$\begingroup\$

Perl 5, 36 bytes

$#a=78;print".[${_}m@a
"x13for 44,43

Try it online!

Outputs using ANSI escape sequences.

\$\endgroup\$
4
  • \$\begingroup\$ For some reason, the link seems to show an 'L'-shaped flag with a long extension at the bottom right. Is this just a side-effect of the 'code sandbox'? \$\endgroup\$ Commented May 11, 2022 at 12:58
  • \$\begingroup\$ @DominicvanEssen Yeah, it's a side effect of ANSI escape codes being used in a window that's not long enough for the content, the same happens in a local terminal if you're most of the way down. It's annoying. I did briefly look at auto-sizing STDOUT for code-sandbox, but it would need to be resized before the content makes it there... \$\endgroup\$ Commented May 11, 2022 at 14:44
  • \$\begingroup\$ @DominicvanEssen Thanks for the nudge, I've just made a fix so that the xterm window will resize on input (not sure how quickly the cache is invalidated on GitHub pages, but thanks again for the prompt!) \$\endgroup\$ Commented May 11, 2022 at 19:53
  • \$\begingroup\$ Works perfectly now. Nice one. \$\endgroup\$ Commented May 11, 2022 at 20:50
5
\$\begingroup\$

Chipmunk BASIC, 116 bytes

Chipmunk Basic v368b2.02 on MacOS. This fun wee lang adjusts RGB values by a factor0.392157.

graphics 0
graphics color 0,34,72
graphics fillrect 0,0,132,44
graphics color 100,84,0
graphics fillrect 0,44,132,88
\$\endgroup\$
5
\$\begingroup\$

PNG, 96 bytes

After reading this article and becoming more familiar than I would ever want to with these docs, I've created a PNG solution. It's definitely not optimal. I haven't quite figured out the compression entirely yet. Anyway, here it is:

00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452  .PNG........IHDR
00000010: 0000 004e 0000 0034 0103 0000 001e dd9c  ...N...4........
00000020: f900 0000 0650 4c54 4500 57b7 ffd7 00df  .....PLTE.W.....
00000030: 10bb 0200 0000 1549 4441 5478 da63 6018  .......IDATx.c`.
00000040: 0578 c07f 18f8 33ca c460 0200 8b3d 02be  .x....3..`...=..
00000050: 44c1 a979 0000 0000 4945 4e44 ae42 6082  D..y....IEND.B`.

ukraine flag png image

I'd recommend downloading it and checking it out on this useful page which shows the structure: https://evanhahn.gitlab.io/png-explorer/

It's also linked from the first article.

In summary, it contains these chunks. You can see them in the ASCII decoding of the bytes.

  • PNG A signature chunk saying it's a PNG file
  • IHDR A header chunk with the width, height and colour type, and some other stuff. This image is "index color", meaning it has a palette of colours which it picks from for each pixel.
  • PLTE A palette chunk containing the two colours. You can see these in the bytes near the end of the third line as 4500 57b7 ffd7 00df, which is the two hex colours next to each other.
  • IDAT The image data chunk itself (this is a scanline for each row, which is either zeros or ones depending if it's blue or yellow). It is compressed losslessly.
  • IEND An "end" chunk

Some optimisations to be had:

  • The end chunk seems to be able to be removed, although this is in violation of the spec. Saves 12 bytes.
  • The article also links to this website which allows you to generate a single colour image. It somehow has better compression and I couldn't get my zlib to do it. It saves about 4 bytes.

So it's probably possible to get down to 80 bytes quite easily. Beyond that:

  • You could probably use the background colour and omit half the scanlines. Again, this would probably be in violation of the spec. It also may actually use more bytes.
  • You may be able to use pixel aspect ratio to use less pixels

Here's the awful code I threw together to create it: https://pastebin.com/tjdrQ4md

\$\endgroup\$
4
\$\begingroup\$

SVG - Scalable Vector Graphics. 151 bytes

<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 3 2"><path d="M0 0H3V1H0ZM0 1H3V2H0Z" fill="#005BBB"/><path d="M0 1H3V2H0Z" fill="#FFD500"/></svg>

Try it online

\$\endgroup\$
4
\$\begingroup\$

Python 3, 152 bytes

A repurposing of my answer to the Pride flag challenge, with some small improvements to the visuals.

from curses import*
s=initscr();start_color();y=1
for x in[12,11,0]:w=newwin(13,78,~-y*13,0);init_pair(y,1,x);w.bkgd(' ',color_pair(y));w.refresh();y+=1

The flag of Ukraine, in a terminal window

\$\endgroup\$
4
\$\begingroup\$

Actionscript 3, 94 89 bytes

Here comes our national flag in Actionscript and this is my first submission in this language, since my usual languages have been already taken. The code throws an error, but it will compile a SWF (a "swiff") anyway. I took the inspiration from a similar answer to another challenge.

  • spared 5 bytes by replacing hexadecimal 0xe0057B7 for 22455 and 0xeffd700 for 16766720.
var g=graphics,f=g.beginFill,r=g.drawRect
f(22455);r(0,0,99,33)
f(16766720);r(0,33,99,33)

Flag 66 x 99 px

Glory to Ukraine!

\$\endgroup\$
2
  • 5
    \$\begingroup\$ Glory to Ukraine indeed! 🇺🇦 \$\endgroup\$ Commented Apr 17, 2024 at 11:47
  • 5
    \$\begingroup\$ @The Empty String Photographer the usual response is "Heroiam Slava!" / "Glory to the heroes!" \$\endgroup\$ Commented Apr 17, 2024 at 12:06
3
\$\begingroup\$

Vyxal Ḣs, 33 bytes

»ƛ∨ɖoʀĊ∩»H½4εfƛ`<¦₴ «⟇=øḢ-÷¥:#Π>.

Try it Online! The aspect ratio is a little weird and subject to Vyxal's default window sizing, but this is pretty much 3:2. You can fiddle with the 4 to change the height.

enter image description here

»...»H½                       # Compressed integer converted to hexadecimal and cut in half - FFD700 and 0057B7
       4εf                    # Repeat each four times
          ƛ                   # Format each into 
           `<¦₴ «⟇=øḢ-÷¥:#Π>. # Compressed string "<div style=background-color:#%>."
                              # (s flag) concatenate
                              # (Ḣ flag) render as HTML
\$\endgroup\$
2
\$\begingroup\$

HTML, 71 bytes

<svg viewBox=0,0,1.5,1 style=background:gold><line stroke=#0057b7 x2=3>
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Small glitch, the colors are reversed. Blue should be on top. \$\endgroup\$ Commented May 29, 2025 at 11:40
  • \$\begingroup\$ @manatwork Fixed, thanks for pointing that out \$\endgroup\$ Commented May 30, 2025 at 4:52
1
\$\begingroup\$

JSL (JMP Scripting Language), 110 bytes

NewWindow("",Graph(FillColor({1,43/51,0});Rect(0,33,99,66,1);FillColor({0,29/85,183/255});Rect(0,66,99,99,1)))

enter image description here

\$\endgroup\$
1
\$\begingroup\$

DrawShield Blazon, 81 bytes

drawn using flat appearance using flag shape with aspect ratio 2:3 per fess az or

As far as I know, there's no way to specify RGB colours on DrawShield.

az is a shortcut for azure.

Try this online

\$\endgroup\$
1 2
3

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.