21
\$\begingroup\$

We've got quite a few national flag challenges already: AU CH FI FR GB GB IS KR NP US... Here's another, somewhat more advanced one:

Return or print the decorative pattern from Belarus's national flag as a matrix of two distinct values for red and white.

rushnyk

If your language doesn't support matrices, use a list of lists or the closest equivalent. Extra whitespace is allowed on all sides. The matrix can be transposed. The elements can have a consistent separator, and so can the rows, e.g. output can be JSON. You must use the 2012 version of the ornament pattern, not the 1951 or 1995 versions. This is , so the shortest answer per language wins.

Sample output:

....###....#....###....
#..#####...#...#####..#
..###.###.....###.###..
.###...###...###...###.
###..#..###.###..#..###
.###...###...###...###.
..###.###.....###.###..
#..#####...#...#####..#
....###....#....###....
..#..#..#.....#..#..#..
.###...###...###...###.
##.##.##.##.##.##.##.##
.###...###...###...###.
..#..#..#.....#..#..#..
....###....#....###....
#..#####...#...#####..#
..#######.....#######..
.#########...#########.
#######################
####...#########...####
.#####..#######..#####.
..###....#####....###..
#..#....#######....#..#
.......####.####.......
#.....####...####.....#
##...####..#..####...##
###.####.......####.###
.######..#...#..######.
..####...##.##...####..
...###....###....###...
....##.#...#...#.##....
...###....###....###...
..####...##.##...####..
.######..#...#..######.
###.####.......####.###
##...####..#..####...##
#.....####...####.....#
.......####.####.......
#..#....#######....#..#
..###....#####....###..
.#####..#######..#####.
####...#########...####
#######################
.#########...#########.
..#######.....#######..
#..#####...#...#####..#
....###....#....###....
..#..#..#.....#..#..#..
.###...###...###...###.
##.##.##.##.##.##.##.##
.###...###...###...###.
..#..#..#.....#..#..#..
....###....#....###....
#..#####...#...#####..#
..###.###.....###.###..
.###...###...###...###.
###..#..###.###..#..###
.###...###...###...###.
..###.###.....###.###..
#..#####...#...#####..#
....###....#....###....
\$\endgroup\$

8 Answers 8

7
\$\begingroup\$

Stax, 68 bytes

àÑΣ▒i╕7FF3xì¥╫Yb▌t╤y╡µåè0═↕h╗ΔDOü↔`◙■^>♀;∟Γ9→§Æ¼$ß⌡╫èj_┐;ø;¡²Ω☺┘4!P╛

Run and debug it

Outputs vertical version, 1 for white, 0 for red. Naive approach: compress top left quarter, then complete.

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

Python 2, 183 181 bytes

S=[bin(int(''.join(w),36))[2:].rjust(31,'0')for w in zip(*[iter("RBRG5FDLAJ2O77MSE012OBJWJUSWDQ464UKNYZIE8JYGS0JRFOCIJY7U5F983X0LYW20WNTE")]*6)]
for s in S[:0:-1]+S:print s[:0:-1]+s

Try it online!

Outputs transposed version, using 0 and 1 for white and red.

\$\endgroup\$
2
  • \$\begingroup\$ Does this compress the entire string of values for the flag? \$\endgroup\$
    – Razetime
    Commented Aug 22, 2018 at 2:35
  • \$\begingroup\$ @RaghuRanganathan Only a quarter. The for s in S[:0:-1]+S:print s[:0:-1]+s doubles the lines, and print each line doubled \$\endgroup\$
    – TFeld
    Commented Aug 22, 2018 at 6:44
3
\$\begingroup\$

JavaScript (ES6), 164 bytes

Transposed output. Uses 0 for white, 1 for red.

f=(x=y=0)=>y<61?x>22?`
`+f(!++y):(-~'o`xb[FMMf[MM[Fxbo`cCMMZZMMcCo`xb{F}N~~N}}{[wH{?]@NbfvB}H{Wwooa'.charCodeAt((y>30?60-y:y)*2+(X=x>11?22-x:x)/6)>>X%6&1)+f(x+1):''

Try it online! (prettified output)

Using Buffer() in Node.js saves 1 byte.

\$\endgroup\$
3
\$\begingroup\$

SOGL V0.12, 61 56 bytes

 №α⁶U-┼°jōIΤ$ΣΧρ←FVξÆ⅝{VqM┼οYΠ!↕οΩÆ.χg±└¶Σ,Cy′┌“2─±6«n╬,

Try it Here!

\$\endgroup\$
3
\$\begingroup\$

Charcoal, 93 89 81 bytes

”{“↷B⦃¶¹¹|TQ⌊‽÷⪫Mg+℅§ºH·τP≔⁻⊗|Yω¤⁵⊗-κ�κb5Aωγ⎚I0ê﹪oζM⟲ºh⟲⮌#⎇s▶‴ψ◧≔◨◧⁺4U×m∧üF↑⬤”‖O¬

My first charcoal answer! :D

Try it online!

Saved 4 bytes by outputting the design horizontally rather than vertically (fewer newlines).

Thanks to @Neil for saving 8 bytes!

\$\endgroup\$
5
  • \$\begingroup\$ ‖B accepts multiple operands, Some combinations even have a single-byte encoding (¬ and L for example). \$\endgroup\$
    – Neil
    Commented Aug 6, 2018 at 15:24
  • \$\begingroup\$ Also, using spaces instead of .s should save you a few bytes as you don't need spaces at the end of a line. \$\endgroup\$
    – Neil
    Commented Aug 6, 2018 at 15:25
  • \$\begingroup\$ (I don't know which of vertically or horizontally will result in more spaces at the ends of lines). \$\endgroup\$
    – Neil
    Commented Aug 6, 2018 at 15:27
  • \$\begingroup\$ I tried ‖B¬ and it doesn't help because the reflected string literal costs an extra byte, but ‖BL does save a byte because the line-reversed string literal is the same byte count. \$\endgroup\$
    – Neil
    Commented Aug 7, 2018 at 10:53
  • \$\begingroup\$ On the other hand, for vertical output, ‖BL gets me to 83 bytes, and ‖B¬ can be done in 81 bytes: Try it online! \$\endgroup\$
    – Neil
    Commented Aug 7, 2018 at 10:56
2
\$\begingroup\$

Python 2, 153 bytes

00000000: 2363 6f64 696e 673a 4c31 0a66 6f72 2079  #coding:L1.for y
00000010: 2069 6e20 7261 6e67 6528 2d33 302c 3331   in range(-30,31
00000020: 293a 733d 666f 726d 6174 2869 6e74 2827  ):s=format(int('
00000030: 0137 ec80 937f f739 027d 7209 37e7 395c  .7.....9.}r.7.9\
00000040: 30cc ef73 108c 1fff fe41 b14e fb14 1bfe  0..s.....A.N....
00000050: d364 09ce f7ff fc81 18c6 c811 8cec 8111  .d..............
00000060: 272e 656e 636f 6465 2827 6865 7827 295b  '.encode('hex')[
00000070: 6162 7328 7929 3a3a 3331 5d2c 3136 292c  abs(y)::31],16),
00000080: 2730 3132 6227 293b 7072 696e 7420 732b  '012b');print s+
00000090: 735b 2d32 3a3a 2d31 5d                   s[-2::-1]

Try it online!

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

Perl 5, 121 bytes

Uses 1 for white pixels and 0 for red.

$_=unpack"B*",'ñæÄxããÄvñí·Ž2IŽ=·ñæÀxàƒxoá|3†øÞ<òà';say for(@a=map{s/.$//r.reverse}/.{12}/g),pop@a&&reverse@a

This script contains unprintable characters so a reversible hexdump is included in the verification link below.

Try it online!
Verification of code length.

Explanation

The top quarter of the pattern is stored within the binary blob. This just uses Perl's pack function with the original binary string (after replacing . and # with 1 and 0). This allows us to store 8 bits of the pattern in each byte. Once we've unpacked the data, we have the long binary string, which we break down into sections of length 12, concatenate with the reverse (except for the duplicated middle character) and then loop over the list of sections (concatenated with the reverse of the list, except for the duplicated middle element) and output them all using say, which adds in a newline.

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

Deadfish~, 2644 bytes

{iii}iiccccicccdccccicdccccicccdcccc{dd}ddc{ii}iiicdccicccccdcccicdcccicccccdccic{dd}dddc{ii}iiccicccdcicccdcccccicccdcicccdcc{dd}ddc{ii}iicicccdcccicccdcccicccdcccicccdc{dd}ddc{ii}iiicccdccicdccicccdcicccdccicdcciccc{dd}dddc{ii}iicicccdcccicccdcccicccdcccicccdc{dd}ddc{ii}iiccicccdcicccdcccccicccdcicccdcc{dd}ddc{ii}iiicdccicccccdcccicdcccicccccdccic{dd}dddc{ii}iiccccicccdccccicdccccicccdcccc{dd}ddc{ii}iiccicdccicdccicdcccccicdccicdccicdcc{dd}ddc{ii}iicicccdcccicccdcccicccdcccicccdc{dd}ddc{ii}iiiccdciccdciccdciccdciccdciccdciccdcicc{dd}dddc{ii}iicicccdcccicccdcccicccdcccicccdc{dd}ddc{ii}iiccicdccicdccicdcccccicdccicdccicdcc{dd}ddc{ii}iiccccicccdccccicdccccicccdcccc{dd}ddc{ii}iiicdccicccccdcccicdcccicccccdccic{dd}dddc{ii}iiccicccccccdcccccicccccccdcc{dd}ddc{ii}iicicccccccccdcccicccccccccdc{dd}ddc{ii}iii{cc}ccc{dd}dddc{ii}iiiccccdcccicccccccccdcccicccc{dd}dddc{ii}iicicccccdccicccccccdccicccccdc{dd}ddc{ii}iiccicccdccccicccccdccccicccdcc{dd}ddc{ii}iiicdccicdccccicccccccdccccicdccic{dd}dddc{ii}iiccccccciccccdciccccdccccccc{dd}ddc{ii}iiicdccccciccccdccciccccdcccccic{dd}dddc{ii}iiiccdccciccccdccicdcciccccdcccicc{dd}dddc{ii}iiicccdciccccdccccccciccccdciccc{dd}dddc{ii}iiciccccccdccicdcccicdcciccccccdc{dd}ddc{ii}iicciccccdccciccdciccdccciccccdcc{dd}ddc{ii}iicccicccdccccicccdccccicccdccc{dd}ddc{ii}iicccciccdcicdcccicdcccicdciccdcccc{dd}ddc{ii}iicccicccdccccicccdccccicccdccc{dd}ddc{ii}iicciccccdccciccdciccdccciccccdcc{dd}ddc{ii}iiciccccccdccicdcccicdcciccccccdc{dd}ddc{ii}iiicccdciccccdccccccciccccdciccc{dd}dddc{ii}iiiccdccciccccdccicdcciccccdcccicc{dd}dddc{ii}iiicdccccciccccdccciccccdcccccic{dd}dddc{ii}iiccccccciccccdciccccdccccccc{dd}ddc{ii}iiicdccicdccccicccccccdccccicdccic{dd}dddc{ii}iiccicccdccccicccccdccccicccdcc{dd}ddc{ii}iicicccccdccicccccccdccicccccdc{dd}ddc{ii}iiiccccdcccicccccccccdcccicccc{dd}dddc{ii}iii{cc}ccc{dd}dddc{ii}iicicccccccccdcccicccccccccdc{dd}ddc{ii}iiccicccccccdcccccicccccccdcc{dd}ddc{ii}iiicdccicccccdcccicdcccicccccdccic{dd}dddc{ii}iiccccicccdccccicdccccicccdcccc{dd}ddc{ii}iiccicdccicdccicdcccccicdccicdccicdcc{dd}ddc{ii}iicicccdcccicccdcccicccdcccicccdc{dd}ddc{ii}iiiccdciccdciccdciccdciccdciccdciccdcicc{dd}dddc{ii}iicicccdcccicccdcccicccdcccicccdc{dd}ddc{ii}iiccicdccicdccicdcccccicdccicdccicdcc{dd}ddc{ii}iiccccicccdccccicdccccicccdcccc{dd}ddc{ii}iiicdccicccccdcccicdcccicccccdccic{dd}dddc{ii}iiccicccdcicccdcccccicccdcicccdcc{dd}ddc{ii}iicicccdcccicccdcccicccdcccicccdc{dd}ddc{ii}iiicccdccicdccicccdcicccdccicdcciccc{dd}dddc{ii}iicicccdcccicccdcccicccdcccicccdc{dd}ddc{ii}iiccicccdcicccdcccccicccdcicccdcc{dd}ddc{ii}iiicdccicccccdcccicdcccicccccdccic{dd}dddc{ii}iiccccicccdccccicdccccicccdcccc
\$\endgroup\$
2
  • \$\begingroup\$ A code-only answer isn't very interesting... Could you provide an explanation as to how this code produces the output for the challenge? \$\endgroup\$ Commented Mar 22, 2021 at 9:09
  • \$\begingroup\$ Read the wiki. It's not a very interesting language. \$\endgroup\$
    – emanresu A
    Commented Mar 22, 2021 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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