106
\$\begingroup\$

There have been many other flag challenges posted but not one for the national flag of France. This week seems like an appropriate time.

Produce this flag in the fewest bytes possible:

French flag

  • The image must be in a ratio of 3:2, with size at least 78 pixels wide and 52 pixels tall.
  • Each stripe takes up one third of the width.
  • The stripe colors from left to right are RGB: (0, 85, 164), (255, 255, 255), (239, 65, 53).
  • The image can be saved to a file or piped raw to STDOUT in any common image file format, or it can be displayed.
  • 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, white, and red.)
  • Built-in flag images/libraries are not allowed.

The shortest code in bytes wins.

Leaderboard

The Stack Snippet at the bottom of this post generates the leaderboard from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes

<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 64140; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 42156; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "https://api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "https://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>

\$\endgroup\$
  • 4
    \$\begingroup\$ Those RGB values don't match your image. From what I see, you've got RGB: (0, 35, 149), (255, 255, 255), (237, 41, 57). \$\endgroup\$ – beaker Nov 18 '15 at 0:18
  • 8
    \$\begingroup\$ Storing the specified palette compactly is probably the trickiest part of this problem in most languages. Given that, it seems rather unfair to graphical solutions to permit ANSI output with a standard palette. Why not permit graphical solutions to use pure (0, 0, 255)/(255, 255, 255)/(255, 0 0) to level the playing field? \$\endgroup\$ – JohnE Nov 18 '15 at 0:19
  • 15
    \$\begingroup\$ Each stripe takes up one third of the width. Might be more interesting to use the Naval variant: by a regulation dated 17 May 1853, the navy went back to using the 30:33:37 proportions, which it now continues to use, as the flapping of the flag makes portions farther from the halyard seem smaller. \$\endgroup\$ – Ben Jackson Nov 18 '15 at 0:19
  • 33
    \$\begingroup\$ echo 🇫🇷 not quite big enough \$\endgroup\$ – Digital Trauma Nov 18 '15 at 4:08
  • 5
    \$\begingroup\$ @JohnE I agree. The rules on colors give the ASCII-art solutions a massive advantage. They also don't make the challenge any more "difficult" (merely adds bytes really) for the languages that can use arbitrary colors and disqualifies several cool languages that can't do arbitrary colors. \$\endgroup\$ – a spaghetto Nov 18 '15 at 22:26

84 Answers 84

3
\$\begingroup\$

PowerShell, 152 bytes

sal w write-host;$v=" "*26;foreach($u in 1..26){;w $v -backgroundcolor blue -NoNewLine;w $v -backgroundcolor white -NoNewLine;w $v -backgroundcolor red}

enter image description here

\$\endgroup\$
  • \$\begingroup\$ Hi, welcome to golf. Be aware there's another powershell contribution, where comments have it down to 97 bytes. \$\endgroup\$ – steve Nov 25 '15 at 10:57
  • \$\begingroup\$ If you were to apply some of the changes in that earlier 97 byte one (the changes are only in the comments and not incorporated into the posting itself) you'd end up with something like sal w write-host;$v=" "*26;1..26|%{w $v -background 1 -NoNewLine;w $v -background 6 -NoNewLine;w $v -background 12} taking yours down from 152 to 115. \$\endgroup\$ – steve Nov 25 '15 at 16:04
3
\$\begingroup\$

LibreLogo, 88 85 bytes

Code:

pc [24]lt 90 fd 26 fc 21924 rectangle[52,26]rt 180 fd 52 fc 0xef4135 rectangle[52,26]

Result:

enter image description here

Explanation:

pc [24]                     ; Pen Color = INVISIBLE
lt 90                       ; Left 90°
fd 26                       ; Forward 26 pt
fc 21924                    ; Fill Color = RGB(0, 85, 164)
rectangle [52, 26]          ; Rectangle 52x26 pt
rt 180                      ; Right 180°
fd 52                       ; Forward 52 pt
fc 0xef4135                 ; Fill Color = RGB(239, 65, 53)
rectangle [52, 26]          ; Rectangle 52x26 pt

Previous Attempts:

pc [24]lt 90 fd 26 fc 0x0055a4 rectangle[52,26]rt 180 fd 52 fc 0xef4135 rectangle[52,26]
\$\endgroup\$
3
\$\begingroup\$

Excel VBA 62 bytes

VBE Immediate Window commands

[a1:d25].interior.colorindex=23:[i1:l25].interior.colorindex=3

French Flag

\$\endgroup\$
  • \$\begingroup\$ This is not quite correct - your colors a a bit off. You can correct them for +2 bytes with [A1:D25].Interior.Color=&HA45500:[I1:L25].Interior.Color=3490286 \$\endgroup\$ – Taylor Scott Aug 12 '17 at 14:56
2
\$\begingroup\$

JavaScript, 141 bytes

a='';for(j=0;j<24;j++){for(i=1;i<80;i++){a+="<d style='color:"+(78/i<1.5?'blue':(78/i<3?'white':'red'))+"'>F</d>"}a+="<br>"}document.write(a)

(click "full page" to see the proper result)

\$\endgroup\$
  • 1
    \$\begingroup\$ 136 bytes: for(j=0,a='';j<24;j++,a+='<br>')for(i=1;i<80;i++)a+='<d style=color:'+(78/i<1.5?'blue':(78/i<3?'#fff':'red'))+'>F</d>';document.write(a) \$\endgroup\$ – Ismael Miguel Nov 21 '15 at 2:50
  • \$\begingroup\$ @Ismael yey, great :) \$\endgroup\$ – nicael Nov 22 '15 at 11:12
2
\$\begingroup\$

Lua + LÖVE, 176 174 bytes

l=love
g=l.graphics
l.window.setMode(78,52)
function l.draw()for k,v in next,{[0]={0,85,164},{255,255,255},{239,65,53}}do
g.setColor(v)g.rectangle("fill",k*26,0,26,52)end
end

Sample output:

Tricolore LÖVE

\$\endgroup\$
2
\$\begingroup\$

ActionScript, 90 bytes

var g=graphics,f=g.beginFill,d=g.drawRect;f(21924);d(0,0,26,52);f(0xef4135);d(52,0,26,52);

Ouput:

output

\$\endgroup\$
2
\$\begingroup\$

Processing, 88 bytes

size(78,52);scale(26,52);stroke(-1);background(#EF4135);fill(#0055A4);rect(-2,-1,3.5,3);
\$\endgroup\$
  • \$\begingroup\$ Wow! Mind explaining how that works? \$\endgroup\$ – Cows quack Dec 2 '16 at 18:15
2
\$\begingroup\$

FLIF, 37 bytes

FLIF is an excellent bitmap format for when you really want to squeeze some bytes away:

4c46 4649 3133 4e00 3400 1e27 2ce3 5d2f
ab15 8fdd c110 4117 8d25 5fa2 c8b6 d02d
fdfe af77 000a

Using viewflif:

France flag in application viewflif

\$\endgroup\$
  • \$\begingroup\$ FLIF is not a programming language \$\endgroup\$ – TuxCrafting Jan 26 '17 at 15:20
  • \$\begingroup\$ @TùxCräftîñg Correct, but the task was: "Produce this flag in the fewest bytes possible". No mention of a programming language (ignoring the leaderboard part). Isn't codegolf often about bending/abusing the rules in your favor anyway? :) \$\endgroup\$ – algmyr Jan 27 '17 at 11:13
  • \$\begingroup\$ Code golf is about abusing the language, not the rules :) \$\endgroup\$ – TuxCrafting Jan 27 '17 at 13:49
2
\$\begingroup\$

Je préfère (en /bin/bash):

for i in {a..z}; do printf '\033[4%-28s' 4m 7m 1m; echo; done

Inspirée d'une autre contribution, mais les caractères ne fonctionnaient pas trop (escape)

Vive la République!

\$\endgroup\$
  • 2
    \$\begingroup\$ Welcome to the site. This is a code-golf competition so the objective is to make your source as small as possible, you could likely eliminate a good deal of the size here by removing whitespace. \$\endgroup\$ – Sriotchilism O'Zaic Jul 16 '17 at 5:17
2
\$\begingroup\$

PaperScript, 83 bytes

R=Path.Rectangle
R(0,0,49,98).fillColor="#0055a4"
R(98,0,49,98).fillColor="#ef4135"

PaperScript is an extension of JavaScript based on the Paper.js vector graphics library. You can run PaperScript code directly, without having to mess with the HTML and CSS, at sketch.paperjs.org.

This code is very straightforward: it draws a rectangle and colors it blue; then it draws another rectangle and colors it red. (The arguments to Path.Rectangle are x, y, width, and height, respectively.) The background is assumed to be white. Try it at Paper.js Sketch!

Output

Displayed at the top left of the canvas:

Le drapeau de la France

\$\endgroup\$
2
\$\begingroup\$

Java (JDK 10), 86 bytes

v->{for(int i=0,x;i<4108;)System.out.printf((x=i++%79/26*3+4)<13?"[3%sm@":"\n",x%9);}

Try it online!

Notes:

  • On TIO, it will print the characters, not the flag. To show the flag, run it in Bash.
  • There is a \u001b character between " and [3%sm@.

Credits:

  • steve for giving the idea of moving the i++to a more appropriate place, sparing one byte.
\$\endgroup\$
  • \$\begingroup\$ Does java permit i++<4108 ? \$\endgroup\$ – steve Aug 7 '18 at 9:48
  • \$\begingroup\$ @steve Yes, of course. But that would require some refactoring of the code to compute the appropriate value to print out. Gonna check that out. \$\endgroup\$ – Olivier Grégoire Aug 7 '18 at 9:49
  • \$\begingroup\$ Figure you might save a byte in the for(). \$\endgroup\$ – steve Aug 7 '18 at 9:50
  • \$\begingroup\$ @steve Thanks! I indeed saved a byte, but not where you thought. You sparked that idea, though! ;) \$\endgroup\$ – Olivier Grégoire Aug 7 '18 at 9:53
1
\$\begingroup\$

HTML, 124 bytes

converted rob values mentioned in the question to the hex ones, that cuts off 13 bytes

<a><b><c><style>*{position:fixed;left:0;right:0;bottom:0;top:0}a{background:#0055A4;width:33%}c{background:#EF4135;left:66%;

Very invalid HTML. Unclosed and non-standard elements (fun fact: I can't remove the last semicolon, doesn't render). If your window isn't resized to the aspect ratio of 3:2, I'd advice you to do it ;)

\$\endgroup\$
  • 1
    \$\begingroup\$ Only text flags are supposed to use blue and red. Graphical outputs should use the exact colors mentioned in the question. \$\endgroup\$ – manatwork Nov 22 '15 at 12:23
  • \$\begingroup\$ @man that's a pity, fixed. \$\endgroup\$ – nicael Nov 22 '15 at 13:41
1
\$\begingroup\$

Tandy Color Computer 2 BASIC, 131 bytes

CLS:B$=CHR$(175):W$=CHR$(207):R$=CHR$(191):L$=B$+B$+B$+B$+B$+B$+W$+W$+W$+W$+W$+W$+R$+R$+R$+R$+R$+R$:?L$:?L$:?L$:?L$:?L$:?L$:?L$:?L$

Ungolfed (somewhat):

10 CLS
20 B$=CHR$(175)
30 W$=CHR$(207)
40 R$=CHR$(191)
50 L$=B$+B$+B$+B$+B$+B$+W$+W$+W$+W$+W$+W$+R$+R$+R$+R$+R$+R$
60 ?L$:?L$:?L$:?L$:?L$:?L$:?L$:?L$

I could save 4 bytes if I removed the clear screen code in the beginning (CLS) but it would like kinda gnarly seeing all the code listed on one line then the flag thereafter... otherwise, this clears the screen, assigns B$ the solid blue character, W$ the solid white character, and R$ the solid red character. Then creates a line (L$) with 6 each blue, white, red characters and writes 8 lines of that out to standard output.

This takes advantage of the upper ASCII codes in the Motorola 6847 VDG (Video Display Generator) chip that the CoCo 1 & 2 relied on; they were block graphic codes in any of 8 colors.

As the standard character size of the CoCo was 8 pixels wide by 12 pixels deep, the only way to get the correct ratio at the minimum size is to use 6 characters per color wide by 8 lines. 6*3*8=144 pixels wide, and 8*12=96 pixels deep. 144/96=1.5x wider than tall, or 3:2 ratio.

This also takes advantage of the '?' character being shorthand for the PRINT statement. If you list the ungolfed version of the program you actually will see 8 instances of 'PRINTL$:' instead of '?L$:' due to the tokenization of the '?' being equal to 'PRINT'. However, to my knowledge you can't list a one-liner (a.k.a. 'immediate mode') BASIC program.

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

Python 3, 54 51 bytes

c="\033[0;4%sm ";print((c%4*30+c%7*30+c%1*30+"\n")*30)

c="\033[0;4%sm"+" "*30;print((c%4+c%7+c%1+"\n")*30)

Output: French flag in Python 3

\$\endgroup\$
  • \$\begingroup\$ I browsed the other answers and found a very similar Python2 one, beating me because of the parenthesis required in 3, and because a simple colored character is printed instead of a full background color. \$\endgroup\$ – AmauryPi Nov 24 '15 at 13:00
  • \$\begingroup\$ Are the RGB values of the red, white, and blue up to specification? \$\endgroup\$ – GamrCorps Nov 24 '15 at 13:39
  • \$\begingroup\$ I'm restricted to the terminal red, white and blue, but in modern terminals you can change these colors to match the specification. I did not mentioned this to focus on the implementation. \$\endgroup\$ – AmauryPi Nov 24 '15 at 16:10
  • \$\begingroup\$ Reduced from 54 to 51 bytes by removing the duplicated *30. \$\endgroup\$ – AmauryPi Nov 24 '15 at 16:19
1
\$\begingroup\$

R, 57 bytes

barplot(c(1,1),,c(1),yaxt='n',col=c("#0055a4","#ef4135"))

enter image description here

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

C++ (Windows), 398 bytes

#include <iostream>
#include <Windows.h>
using namespace std;int main(){HANDLE h=GetStdHandle(STD_OUTPUT_HANDLE);int c=0;for(int i=0;i<52;++i){while(c<78){if(c<26){SetConsoleTextAttribute(h,FOREGROUND_BLUE);cout<<"F";}else if(c<52){SetConsoleTextAttribute(h,FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED);cout<<"F";}else{SetConsoleTextAttribute(h,BACKGROUND_RED);cout<<" ";}++c;}c=0;cout<<endl;}}

My first submission! It's quite long, partly because setting console colour in Windows is long, and partly because I have no idea what I'm doing!

\$\endgroup\$
  • \$\begingroup\$ Using constants is good coding practice. But in code golf challenges we usually just use the given values literally and we pre-calculate values if that helps. For example FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED7. (At least according to CHAR_INFO structure. I have no Windows to try it.) \$\endgroup\$ – manatwork Nov 25 '15 at 14:52
1
\$\begingroup\$

Postscript, 136 bytes

/r{rlineto}def /b{translate newpath 0 0 moveto 0 2 r 1 0 r 0 -2 r closepath setrgbcolor fill}def 90 90 scale 0 .33 .64 1 1 b 1 0 0 2 0 b

enter image description here

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

Python, 67 63 bytes

Straightforward as PPM:

print"P6 78 52 255 "+(26*"\x00U\xff"+78*"\xff"+26*"\xefA5")*52

Usage:

python golf_france.py > france.ppm

Edit1: Binary PPM is shorter, haven't figured out how to use to strange codes directly in the strings.

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

PostScript, 48 bytes

Based on earlier (supposedly dodgy) postscript entry, optimized with a loop and 2-byte synonyms, also includes exact colours.

Hex dump:

00000000: 3020 2e33 3333 202e 3634 3388 0030 881a  0 .333 .643..0..
00000010: 8834 2e39 3337 202e 3235 3520 2e32 3038  .4.937 .255 .208
00000020: 8834 3088 1a88 3432 7b92 9d92 807d 9283  .40...42{....}..
\$\endgroup\$
1
\$\begingroup\$

SmileBASIC, 55 bytes

GCLS-1GFILL.,0,26,52,-16755292GFILL 52,0,78,52,-1097419
\$\endgroup\$
1
\$\begingroup\$

Processing, 128 bytes

void setup(){size(90,60);fill(0,0,255);rect(0,0,30,60);fill(255);rect(30,0,60,60);fill(255,0,0);rect(60,0,90,60);}void draw(){}

enter image description here

\$\endgroup\$
  • \$\begingroup\$ You can do fill(-1) instead of fill(255) to save a byte \$\endgroup\$ – Cows quack Apr 23 '17 at 15:11
  • \$\begingroup\$ You can also remove the draw statement because it is not needed here \$\endgroup\$ – Cows quack Apr 23 '17 at 15:11
  • \$\begingroup\$ You can do background(255,0,0); to omit the fill(255,0,0);rect(60,0,90,60); \$\endgroup\$ – Cows quack Apr 23 '17 at 15:13
1
\$\begingroup\$

Bash, 35 bytes

echo -e "\033[44m \033[m \033[41m "

enter image description here

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

Tcl/Tk, 81 80

gri [can .c -bg #fff]
.c cr r 0 0 26 52 -f #0055A4
.c cr r 52 0 78 52 -f #EF4135

enter image description here

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

ImageScript, 63 bytes (non-competing)

rgb(0,85,164)rect(0,0,200,400)rgb(239,65,53)rect(400,0,200,400)

\$\endgroup\$
  • \$\begingroup\$ Link is down. Is there another resource where I can experiment with this language? \$\endgroup\$ – Grant Miller Apr 24 '17 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.