text:
Automatic price-identification of scrolls in Nethack

OH GODS NO!! You can't leave us here with Doorknob! It'll be nethack everywhere! - 1d ago by Geobits

Well, couldn't disappoint...
Introduction
(you can skip this section if you don't care about exposition and/or if you have Tab Explosion Syndrome)
One of the characteristic mechanics of Nethack (and Rogue, and similar games in the same roguelike genre) is its identification system. At the beginning of the game, only items in your starting inventory are "formally identified." The vast majority of other objects start out unknown; for example, a "shield of reflection" will initially display as a "polished silver shield" before it's identified.
A "polished silver shield" can only be a shield of reflection, but this has interesting consequences in two other cases.

Some items are different from each other, but have the same "appearance." For example, if you find a "gray stone," it could be one of four things: A flint stone (useless), a touchstone (can be useful), a loadstone (which will severely encumber you because it weighs a ton and you can't drop it), or a luckstone (extremely helpful, almost necessary for winning the game).
Many items (scrolls, wands, rings, spellbooks, some armor, etc.) have a randomized appearance. What this means is that there is a set list of possible apperances, say, potions could have; for example, [golden potion, swirly potion, fizzy potion, purple-red potion, etc.]. These appearances are then randomly assigned to what they actually are (potion of healing, potion of paralysis, potion of see invisible, potion of polymorph, etc.).
Which means that a hexagonal amulet could save your life in one game (amulet of life saving), and choke you to death the next (amulet of strangulation).

Naturally, this makes identifying items a critical part of the game. Items can be "formally identified," meaning that they will unambiguously show up as definitely being a certain item (ex. all the jeweled wands you find will show up as wands of create monster); this is done primarily via scrolls or spellbooks of identify. Typically those are in short supply, though, which brings us to...
Informal identification. This means that you're pretty sure (or certain) that a certain unidentified item is of a certain type (or that it can only be one of several types), but you haven't "formally" identified it yet. This can be done via several methods: engrave-testing for wands, sink-testing for rings, or, the most common method...

... price identification! Which is what this challenge is about.
In a nutshell, there are shops located throughout the Dungeons of Doom (yes, the shopkeepers thought it'd be a good idea to set up shop in some underground dungeon; don't ask why). In these shops, you can buy and sell the various items that you come across during your travels. When buying or selling an item, the shopkeeper will first tell you how much he would sell it to you / buy it from you for. Since certain items are guaranteed to have specific prices, you can use this to informally identify a certain type of item.
Some items, such as the scroll of light, are the only items to cost a certain amount, which allows you to unambiguously identify them; however, most items share a price group with other items of the same class, which only lets you narrow down the possibilities (which is still useful). However, the buy/sell prices of an item are affected by a number of variables (such as your Charisma stat). Hence the chart above.
Could you tell I like Nethack?
Input
Input will be provided as a (vanilla, 3.4.3) Nethack game currently being played:
"For you, most gracious sir; only 177 for this scroll labeled VERR YED HORRE."
--More--

        ------------
        |          .                                        ---------
        |          |                         ----------     |    ^  |
        |          .##       ################.        +#   #.       .#
        |          | #                       |       _|#   #---------#
        |          | ###                   ##.<       |#   ####      #
        |          .#########################----------#      #      #
        ------------   ###     #         ############# #      #      #
           #             #  -----------  #             #      #   ####
         ###             ###|         |###             #      #   #----------
         #                 #.         |#             ### #    #   #|.???????|
        ##                  |         |#             #--------#   #|.??@????|
    ----.----###############.         |#             #|      |#   #-@???????|
    |.......+#              |         |#             #.      |#    ----------
    |.......|               |         .#              |      |#
    |......>|               -----------               |      +#
    ---------                                         --------

Wizard the Evoker         St:12 Dx:14 Co:11 In:16 Wi:12 Ch:10  Chaotic
Dlvl:2  $:0  HP:11(11) Pw:0(8) AC:9  Exp:1 T:11

This means that it is guaranteed to have several properties:

It will always be 24 lines long.
Each line will always be 80 characters or less in length.
The second-to-last line will consist of the following "tokens": the player's name and title (in the form of "foo the bar"), the list of attributes (separated by a single space), and the player's alignment (Lawful, Neutral, or Chaotic). Each token will be separated by a variable number of spaces.1
The list of attributes will always be St:* Dx:* Co:* In:* Wi:* Ch:*, where a * character represents an integer from 3 to 25.2 (The point of interest here is the last stat, Charisma, which you need to calculate prices.)
The first line will always consist of a shop-related message (specifically, the message that is displayed when you are buying or selling an item). Furthermore, this item is guaranteed to be a single, unidentified, unnamed scroll. For buying an item, this is:
"For you, {TITLE}; only {PRICE} for this scroll labeled {LABEL}."--More--

and for selling, it is:
{SHK} offers {PRICE} gold pieces for your scroll labeled {LABEL}.  Sell it? [ynaq] (y)

where the "variables" listed in {curly braces} are the following:

{TITLE} is always one of "good", "honored", "most gracious", or "esteemed", concatenated with either "lady" or "sir".
{PRICE} is always an integer.
{LABEL} will always be one of the following (source):
ZELGO MER       JUYED AWK YACC  NR 9             XIXAXA XOXAXA XUXAXA
PRATYAVAYAH     DAIYEN FOOELS   LEP GEX VEN ZEA  PRIRUTSENIE
ELBIB YLOH      VERR YED HORRE  VENZAR BORGAVVE  THARR
YUM YUM         KERNOD WEL      ELAM EBOW        DUAM XNAHT
ANDOVA BEGARIN  KIRJE           VE FORBRYDERNE   HACKEM MUCHE
VELOX NEB       FOOBIE BLETCH   TEMOV            GARVEN DEH
READ ME

{SHK} will always be one of the following (source):
Skibbereen      Ballingeary     Inishbofin      Annootok        Abitibi
Kanturk         Kilgarvan       Kesh            Upernavik       Maganasipi
Rath Luirc      Cahersiveen     Hebiwerie       Angmagssalik    Akureyri
Ennistymon      Glenbeigh       Possogroenoe    Aklavik         Kopasker
Lahinch         Kilmihil        Asidonhopo      Inuvik          Budereyri
Kinnegad        Kiltamagh       Manlobbi        Tuktoyaktuk     Akranes
Lugnaquillia    Droichead Atha  Adjama          Chicoutimi      Bordeyri
Enniscorthy     Inniscrone      Pakka Pakka     Ouiatchouane    Holmavik
Gweebarra       Clonegal        Kabalebo        Chibougamau     Lucrezia
Kittamagh       Lisnaskea       Wonotobo        Matagami        Dirk
Nenagh          Culdaff         Akalapi         Kipawa
Sneem           Dunfanaghy      Sipaliwini      Kinojevis

This message may be split onto another line (but it will never take up more than 2 lines).3
Aside from the first few lines, all bets are off as to what the rest of the screen looks like. Nethack uses the majority of the ASCII character set. The only thing that you can safely assume is that the input will be purely ASCII (however this probably won't matter because you can discard lines 3-22 anyway).

If the input is taken as a function argument, it will be given exactly as shown in the example above (newline separated). If you input via STDIN, it will be given as 24 consecutive lines of input (again, as shown above). You may choose whether you want the input to have a trailing newline or not. The input is guaranteed to have no trailing spaces.
Output
Output should be provided as what I should #name the scroll that I just price-ID'd. The naming system I use (and that I have seen others use) is:

If the scroll is unambiguously identified as a certain scroll (identify, light, enchant weapon), #name it that. This is the case for scrolls of the following base prices (you will see how to calculate base price below): 20 -> identify, 50 -> light, 60 -> enchant weapon.
Otherwise, take the first three letters of the scroll's appearance, or the first word if it is less than 3 characters. For example, ZELGO MER becomes ZEL, VE FORBRYDERNE becomes VE, etc. Concatenate with this (a space, and then) the base price of the scroll. For example, ELB 300.
If the base price can be one of two possibilities, I usually keep trying to buy or sell the item until I get an offered price that unambiguously places it into a certain price slot. However, you can't do that in this challenge, so just separate the two possible base prices with a slash (/). For example, HAC 60/80.

Here's the formula for converting the base price of an item into the price you are offered to buy it:

start with the base price of the item
chance of a possible 33% "unidentified surcharge," calculated via price += price / 3
another chance of a 33% "sucker markup" (this isn't random chance actually, but for the purposes of this challenge it is), calculated the same way
a charisma modifier, which is applied as follows:
Ch    3-5     6-7       8-10      11-15  16-17     18        19-25
Mod   +100%   +50%      +33%      +0%    -25%      -33%      -50%
Code  p *= 2  p += p/2  p += p/3  ---    p -= p/4  p -= p/3  p /= 2

And here's the formula for base price -> sell price:

start with the base price of the item
divide this by either 2 or 3 ("normal" or "sucker markup" respectively; again, not random, but it is for the purposes of this challenge)
chance of a further 25% reduction4, calculated via price -= price / 4

The division is integer division, which means the result at each step is rounded down. (Source: wiki, and a bit of source code digging. Reversing these formulas is your job.)
Finally, here's a handy-dandy ASCII chart that shows the possible buy prices (grouped by Charisma stat) and sell prices of a scroll with a certain base price:
Base  Ch<6          6-7          8-10         11-15        16-17        18           19-25        Sell
20    40/52/68      30/39/51     26/34/45     20/26/34     15/20/26     14/18/23     10/13/17     5/6/8/10
50    100/132/176   75/99/132    66/88/117    50/66/88     38/50/66     34/44/59     25/33/44     12/16/19/25
60    120/160/212   90/120/159   80/106/141   60/80/106    45/60/80     40/54/71     30/40/53     15/20/23/30
80    160/212/282   120/159/211  106/141/188  80/106/141   60/80/106    54/71/94     40/53/70     20/26/30/40
100   200/266/354   150/199/265  133/177/236  100/133/177  75/100/133   67/89/118    50/66/88     25/33/38/50
200   400/532/708   300/399/531  266/354/472  200/266/354  150/200/266  134/178/236  100/133/177  50/66/75/100
300   600/800/1066  450/600/799  400/533/710  300/400/533  225/300/400  200/267/356  150/200/266  75/100/113/150

(This is identical to the chart on the wiki except that it lists all possible sell prices, while the wiki chart neglects to include two of the four possible sell prices. No, I didn't manually make that chart; generated with this Ruby script.)
Test cases
Input:
"For you, honored sir; only 80 for this scroll labeled LEP GEX VEN ZEA."
--More--                   #                                          #
                      ----------------                              -----
                      |              |              ------------####+   |
      -----           |              -##############+          .#   |   |
      |   .###########|           >  |#           # |          |  ##.   |
      |   |          #------------.---#           ##.          |  # -----
      -+---          ##################             ----.-------###    #
       ####                     ###                     #       #      #
          #                     #                       #     ###      ###
          ###                 ###                       #     #          #
            #                 #                         #   ###     -----|--
       -----.---            ###                     ----+---#       |...@..|
       |       |            #                       |      |#       |???+??|
       |  <    .#          ##                     ##+      |        |+?????|
       |       |#    ------.-------                 |      |        |??]?@?|
       ---------###  |            |                 |      |        --------
            #     #  |            |                 --------
                  ###|            |                       #
                    #+            |
                     --------------

Wizard the Evoker         St:11 Dx:15 Co:9 In:20 Wi:9 Ch:11  Chaotic
Dlvl:7  $:0  HP:11(11) Pw:1(8) AC:9  Exp:1

Output: LEP 60/80

Input:
"For you, most gracious sir; only 80 for this scroll labeled DAIYEN FOOELS."
--More--                                                             #
                ------------                         -----      -------
 -----          |          |                         |   |      |     |
 |!)%|          |          |     ---------------     |   |     #-     |
 |*[@|          |          .#####|   <         |#####.   |   ###|     |
 |?(?|          ---------.--    #+             |#    |   |   #  |     |
 |[!(|                  ##       |             |#    |   +#### #.     .#
 |.@.|         ##################.             +#    ---.-     #|     |#
 ---|-                ###        ---------------#       ##     #-------#
    ##                #                    ######        #     #       #
     #              ###                         #        #     #       #
     ##             #                           #        #     #       #
  ------        #####                           #        #     #       #
  |    |       -.----                           #        #     #       #
  |    .#####  |^   |                        ####        #     #       #
  |    |    #  |    |          ----          #-----------.---- #       #------
  |    |    ###|    |          |  |          #.      >       | #       #|    |
  ------      #.    |          |  |           |              .##       #|    |
               |    |          ----           |              |         #.    |
               ------                         ----------------          ------

Wizard the Evoker         St:11 Dx:14 Co:16 In:15 Wi:10 Ch:9  Chaotic
Dlvl:6  $:0  HP:11(11) Pw:9(9) AC:9  Exp:1

Output: enchant weapon

Input:
Aklavik offers 113 gold pieces for your scroll labeled GARVEN DEH.  Sell it?
[ynaq] (y)

     -----      ------                                 ---------      -------
     |   |      |    |                         #     ##.       |      |.?)%/|
     |   |    ##.    |                       -----   # |       |      |.@!=*|
     |<  |    # |    |            #        ##.   .#####+    >  |#    #-.*?@[|
     |   .##### |    |      ------------   # | { |#    |^      |#    #|.=%)+|
     ---.-      |    |      |          .#### |   |#    ---------##   #-------
       ##       -.----     #.          |     |   |#          # ###   #
       #         ########  #|          .##   |   |#            ##    #
     ###                #  #------------ #   -----#          ####    #
     #                  #######          ##########################  #
     #                    #   #                            ###----.--#
     #                    ### #                            # #|     |#
   --.----       ########################################### #.     |#
   |     |       #----------.-#                               |     |#
   |     |       #|          |#                               -------
   |     |       #|          .#
   |     |########|          |
   -------        ------------
                   #    #
Wizard the Evoker         St:9 Dx:14 Co:11 In:19 Wi:10 Ch:12  Chaotic
Dlvl:4  $:0  HP:11(11) Pw:5(9) AC:9  Exp:1 Satiated

Output: GAR 300

Input:
"For you, good lady; only 67 for this scroll labeled VE FORBRYDERNE."--More--

                                                 -------
                                               ##|     |
  ------------                                 # |     |
  |+[!/!?%[?)|                               ### |     |          --------
  |[)(!/+]?!@|               #               #   |     |        ##+      |
  |.......@..|            --------------   ###   | <   | ##       |      |
  --------+---           #|            |   #     |     |  #       |    > |
          #            ###|            .####     --.----  ###    #-      |
          #            ###.            |           #        #  ###|      |
          #          #### ---.----------           #        ######.      |
          #          ####    ##                    #         ###  --------
          #        ####       #                    #         #
          #        ####       ########################     ###
        ###      ####                            ----+---- #
        #   #    ####                            |       .##
    ----.------####                              |  ^    |
    |         +####                              |    >  |
    |         |                                  | ^     |
    -----------                                  ---------

Wizard the Evoker         St:18 Dx:18 Co:16 In:20 Wi:20 Ch:18  Chaotic
Dlvl:4  $:150 HP:11(11) Pw:5(7) AC:9  Exp:1

Output: VE 100

Input:
Droichead Atha offers 5 gold pieces for your scroll labeled XIXAXA XOXAXA
XUXAXA.  Sell it? [ynaq] (y)
                                                ------------
                   -----                        |          .#
                   |   .### -----------        #.       {  |#
       -----       |   |  # |         |      ###|          |#
       |   .#     #.   |  # |         |      #  ---------+--#
       |   |    ###-|---    |         .##  ###          ##  #
       |   |    #   # #     |         | #  #            #   #
       |   -#####   #       |         | #### ############   #
       |>  | ##     #       ---------+-  ## -.----------    # ----------
       |   .####    ###             ## #####|          |    # |.*??/?)*|
       -----   #      #             #  #    |          |    # |@*)%!)]%|
               ###    ###         ######    |          |    # |.=)!%*!!|
                 #      #         #  #      |          |    ##+@*[%)(%?|
                 #####################      |          |      |.]?*?)%%|
                    -----+---.----##########.          |      |.%)%!!!%|
                    |            +##        ------------      ----------
                    |    <       |                  #
                    |            |
                    --------------

Wizard the Digger          St:11 Dx:9 Co:14 In:6 Wi:6 Ch:9  Lawful
Dlvl:3  $:0  HP:15(15) Pw:0(1) AC:9  Exp:1

Output: identify
(I had to manually compile Nethack with all the other shopkeeper names removed because I couldn't find a shopkeeper who had a space in his name...)
Rules

This is code-golf, so the shortest code in bytes will ascend win.

1: this isn't necessarily always true during a Nethack game, but we assume this for the sake of simplicity.
2: again, not always true. Strength can be 18/01 through 18/**, but you don't need to handle that.
3: more gross oversimplifications. For example, it is possible for a shopkeeper to call you "scum" or "most renowned and sacred creature," but you don't have to handle any of that.
4: which a smart player gets around by repeatedly offering to sell the item until given the higher price.

Holy wall of text!

@orlp "Also that has got to be one of the longest challenges I've written" :D

"4: which a smart player gets around by repeatedly offering to sell the item until given the higher price" Apparently this is not true now in 3.6.6: The markdown is based on the shopkeeper's (stable) internal monster ID number.

Javascript (ES6), 1610 724 601 612 419 405 390 bytes
a=>(b=a.match(/(\d+) (g|f).+d (\w{0,3})[\s\S]+h:(\d+)/),c=+b[4],d=[20,50,60,80,100,200,300].reduce((d,e)=>(f=e/2,g=~~(e/3),(b[2]=='g'?[g-(g>>2),g,f-(f>>2),f]:[e,e+g,e+g+~~((e+g)/3)].map(h=>c<6?h*2:c<8?h+h>>1:c<11?h+~~(h/3):c<16?h:c<18?h-(h>>2):c<19?h-~~(h/3):h>>1)).includes(+b[1])?[...d,e]:d),[]),i={20:'identify',50:'light',60:'enchant weapon'}[d[0]],j=b[3]+' '+d[0],d[1]?j+'/'+d[1]:i||j)

Large wall of text, meet large wall of code.
Ungolfed
inp => (
    extraction = inp.match(/(\d+) (g|f).+d (\w{0,3})[\s\S]+h:(\d+)/),

    charisma = +extraction[4],

    allowed = [20, 50, 60, 80, 100, 200, 300].reduce((allowed, base) => (
        tmp1 = base / 2,
        tmp2 = ~~(base / 3),
        (extraction[2] == 'g' ?
              [tmp2 - (tmp2 >> 2), tmp2, tmp1 - (tmp1 >> 2), tmp1]
          :
              [base, base + tmp2, base + tmp2 + ~~((base + tmp2) / 3)].map(val =>
                  charisma < 6 ?
                      val * 2
                  : charisma < 8 ?
                      val + val >> 1
                  : charisma < 11 ?
                      val + ~~(val / 3)
                  : charisma < 16 ?
                      val
                  : charisma < 18 ?
                      val - (val >> 2)
                  : charisma < 19 ?
                      val - ~~(val / 3)
                  : val >> 1
          )).includes(+extraction[1]) ? [...allowed, base] : allowed
    ), []),

    name_ = {
        20: 'identify',
        50: 'light',
        60: 'enchant weapon'
    }[allowed[0]],

    tmp3 = extraction[3] + ' ' + allowed[0],

    allowed[1] ?
        tmp3 + '/' + allowed[1]
    :
        name_ || tmp3
)

Example

document.getElementById('input').value = `Droichead Atha offers 5 gold pieces for your scroll labeled XIXAXA XOXAXA
XUXAXA.  Sell it? [ynaq] (y)
                                            ------------
               -----                        |          .#
               |   .### -----------        #.       {  |#
   -----       |   |  # |         |      ###|          |#
   |   .#     #.   |  # |         |      #  ---------+--#
   |   |    ###-|---    |         .##  ###          ##  #
   |   |    #   # #     |         | #  #            #   #
   |   -#####   #       |         | #### ############   #
   |>  | ##     #       ---------+-  ## -.----------    # ----------
   |   .####    ###             ## #####|          |    # |.*??/?)*|
   -----   #      #             #  #    |          |    # |@*)%!)]%|
           ###    ###         ######    |          |    # |.=)!%*!!|
             #      #         #  #      |          |    ##+@*[%)(%?|
             #####################      |          |      |.]?*?)%%|
                -----+---.----##########.          |      |.%)%!!!%|
                |            +##        ------------      ----------
                |    <       |                  #
                |            |
                --------------

Wizard the Digger          St:11 Dx:9 Co:14 In:6 Wi:6 Ch:9  Lawful
Dlvl:3  $:0  HP:15(15) Pw:0(1) AC:9  Exp:1`;

func=a=>(b=a.match(/(\d+) (g|f).+d (\w{0,3})[\s\S]+h:(\d+)/),c=+b[4],d=[20,50,60,80,100,200,300].reduce((d,e)=>(f=e/2,g=~~(e/3),(b[2]=='g'?[g-(g>>2),g,f-(f>>2),f]:[e,e+g,e+g+~~((e+g)/3)].map(h=>c<6?h*2:c<8?h+h>>1:c<11?h+~~(h/3):c<16?h:c<18?h-(h>>2):c<19?h-~~(h/3):h>>1)).includes(+b[1])?[...d,e]:d),[]),i={20:'identify',50:'light',60:'enchant weapon'}[d[0]],j=b[3]+' '+d[0],d.length-1?j+'/'+d[1]:i||j);

function run() {
  try {
    document.getElementById('output').value = func(document.getElementById('input').value);
  } catch (e) {
    document.getElementById('output').value = 'ERROR!';
  }
}
<textarea id="input" placeholder="input" rows="20" cols="70"></textarea>
<br>
<button onclick="run()">Run</button>
<br>
<textarea id="output" placeholder="output" disabled="disabled"></textarea>

That is one big pile of script.

Woah, someone finally answered this? Nice :D

@Doorknob Been wanting to update this for a while, finally got around to it.


text:
Print the American Flag!
Special Independence Day (USA) themed challenge for you today. You must write a program that prints this ascii-art representation of The American Flag.
0
|---------------------------------------------------------
| *   *   *   *   *   * #################################|
|   *   *   *   *   *                                    |
| *   *   *   *   *   *                                  |
|   *   *   *   *   *   #################################|
| *   *   *   *   *   *                                  |
|   *   *   *   *   *                                    |
| *   *   *   *   *   * #################################|
|   *   *   *   *   *                                    |
| *   *   *   *   *   *                                  |
|########################################################|
|                                                        |
|                                                        |
|########################################################|
|                                                        |
|                                                        |
|########################################################|
|                                                        |
|                                                        |
|########################################################|
|---------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Trailing spaces on each line, as well as one trailing newline, are allowed.
Note that this isn't quite the way the flag should look, but it's the closest I could get with ASCII.
As usual, this is code-golf so standard loopholes apply and shortest answer in bytes wins!

Is trailing whitespace allowed?

@Dennis as long as it's not excessive I don't see why not. So one trailing newline is OK.

What about trailing spaces on the individual lines?

@Dennis yeah, that's fine.

I would make this a pop-contest and see who prints the most realistic flag.

@Hosch250 That would end up closed as "art contest"

Oh, I didn't know the rules about that changed since I was here.

@Hosch250 the full correct spec of the flag is at https://en.wikipedia.org/wiki/Flag_of_the_United_States . You can't get more realistic than that. It might be worth asking as a codegolf next 4th of July . As far as I can tell it's never been asked.  http://codegolf.stackexchange.com/q/28784/15599 is the closest I could find. An interesting difference between this challenge and the real flag is that the stars area should reach as far as the bottom of the 7th stripe (red) but I don't think it would have been very visually appealing in ASCII art.

@steveverrill Yes, but we could draw a flag rippling in the breeze, perhaps.

CJam, 184 120 109 101 76 74 69 67 64 62 58 bytes
0'-57*"  #"56f*'|f+7*2>" *  "50*22/W<Sf+..e&~J$]N'|+a37*.+

Try it online in the CJam interpreter.
Idea
The most interesting part of the flag is the stars and stripes pattern.
If we repeat two spaces and a number sign 56 times and append a vertical bar to each, we get
                                                         |
                                                         |
#########################################################|

Repeating this pattern 7 times and discarding the first two lines, we obtain the stripes:
#########################################################|
                                                         |
                                                         |
#########################################################|
                                                         |
                                                         |
#########################################################|
                                                         |
                                                         |
#########################################################|
                                                         |
                                                         |
#########################################################|
                                                         |
                                                         |
#########################################################|
                                                         |
                                                         |
#########################################################|

Now, if we repeat the string " *  " 50 times and split the result into chunks of length 22, we obtain the stars:
 *   *   *   *   *   *
   *   *   *   *   *
 *   *   *   *   *   *
   *   *   *   *   *
 *   *   *   *   *   *
   *   *   *   *   *
 *   *   *   *   *   *
   *   *   *   *   *
 *   *   *   *   *   *

The whitespace is a little off, but we can fix that by eliminating the last chunk and appending a space to the remaining ones.
Now, if we superimpose stripes and stars, we get
 *   *   *   *   *   * #################################|
   *   *   *   *   *                                    |
 *   *   *   *   *   *                                  |
   *   *   *   *   *   #################################|
 *   *   *   *   *   *                                  |
   *   *   *   *   *                                    |
 *   *   *   *   *   * #################################|
   *   *   *   *   *                                    |
 *   *   *   *   *   *                                  |
########################################################|
                                                        |
                                                        |
########################################################|
                                                        |
                                                        |
########################################################|
                                                        |
                                                        |
########################################################|

All that's left to do is adding two lines of 57 dashes, adding a column of 37 vertical bars and putting the cherry on top.
Code
0         e# Push a zero.
'-57*     e# Push a string of 57 dashes.
"  #"56f* e# Repeat each character in the string 56 times.
'|f+      e# Append a vertical bar to each resulting string.
7*        e# Repeat the resulting array of strings 7 times.
2>        e# Discard the first two strings.
" *  "50* e# Repeat the string 50 times.
22/       e# Split the result into chunks of length 22.
W<        e# Discard the last, partial chunk.
Sf*       e# Append a space to each chunk.
..e&      e# Twofold vectorized logical AND.
          e# Since all characters in the strings are truthy, this always selects
          e# the second character, painting the stars over the stripes.
~         e# Dump all resulting strings on the stack.
J$        e# Copy the string of dashes.

]         e# Wrap the entire stack in an array.
N'|+a37*  e# Repeat ["\n|"] 37 times.
.+        e# Perform vectorized concatenation.

For a very short, magic moment I was beating you

It ain't every day you see someone write a CJam program 120 bytes too long.

What I like best is how you found a way to have 6 stars on each line, then naturally get rid of the ones you didn't want.

@steveverrill: I liked that too, but I found something shorter...

Cool! (You did something similar with the honeycomb didn't you?) But now you need to revise the superimposed image in your explanation.

@steveverrill: Oh, thanks! Yes, you're right, I did almost exactly the same with the honeycomb. I actually saw that answer a few hours ago when I posted a long overdue tip on ASCII art with CJam. That's probably why it occurred to me.

Python 2, 113 bytes
for i in range(38):print i and"|"+["-"*57,(" *  "*7)[i%2*2:][:(i<11)*23].ljust(56,"  #"[i%3])+"|"][1<i<21]*(i<22)

String slicing and modulo checks galore.

+1 Very impressive, 7 bytes ahead of my ruby answer. Both you and EDC65 were ahead of Dennis at one time? wow!

A python answer that is competing with a cjam answer. What a time to be alive!

I like how the value i=0 is itself being printed.

Brainf**k, 3355 3113 1598 1178 782 bytes
What is this language?
Here is the hand optimized version featuring 28 loops.  I think I've taken this about as far as it will go.
Here's the run at ideone.com:
+++[>++++<-]>[>+++>+++>+++>++++++++++>+>++++<<<<<<-]>++++++>---->->>>.<--.
<++++.>>---.>+++++++[<........>-]<<.
<.<<<<+++++[>>.<.>..<<-]>>.<.>.<<++++[>>>........<<<-]>>>.>.>.
<.<<<<+++++[>>...<.<-]+++++[>>.......<<-]>>.>>.>.
<.<<<<++++++[>>.<.>..<<-]++++[>>........<<-]>>>>.>.
<.<<...<<+++++[>.>...<<-]++++[>>>........<<<-]>>>.>.>.
<.<<<<++++++[>>.<.>..<<-]++++[>>........<<-]>>>>.>.
<.<<<<+++++[>>...<.<-]+++++[>>.......<<-]>>.>>.>.
<.<<<<+++++[>>.<.>..<<-]>>.<.>.<<++++[>>>........<<<-]>>>.>.>.
<.<<<<+++++[>>...<.<-]+++++[>>.......<<-]>>.>>.>.
<.<<<<++++++[>>.<.>..<<-]++++[>>........<<-]>>>>.>.
>>>+++[<<<
<.>>>+++++++[<<<<........>>>>-]<<<.>.
>>++[<<
<.<<<<+++++++[>>........<<-]>>>>.>.
>>-]<<
>>>-]<<<
<.>>>+++++++[<<<<........>>>>-]<<<.>.
<.>>.>+++++++[<........>-]<<.
>>++++++++[<<<.>.<.>.>>-]

How does this work?
 1: +++[>++++<-]>[>+++>+++>+++>++++++++++>+>++++<<<<<<-]>++++++>---->->>>.<--.
 2: <++++.>>---.>+++++++[<........>-]<<.
 3: <.<<<<+++++[>>.<.>..<<-]>>.<.>.<<++++[>>>........<<<-]>>>.>.>.
 4: <.<<<<+++++[>>...<.<-]+++++[>>.......<<-]>>.>>.>.
 5: <.<<<<++++++[>>.<.>..<<-]++++[>>........<<-]>>>>.>.
 6: <.<<...<<+++++[>.>...<<-]++++[>>>........<<<-]>>>.>.>.
 7: <.<<<<++++++[>>.<.>..<<-]++++[>>........<<-]>>>>.>.
 8: <.<<<<+++++[>>...<.<-]+++++[>>.......<<-]>>.>>.>.
 9: <.<<<<+++++[>>.<.>..<<-]>>.<.>.<<++++[>>>........<<<-]>>>.>.>.
10: <.<<<<+++++[>>...<.<-]+++++[>>.......<<-]>>.>>.>.
11: <.<<<<++++++[>>.<.>..<<-]++++[>>........<<-]>>>>.>.
12: >>>+++[<<<
13: <.>>>+++++++[<<<<........>>>>-]<<<.>.
14: >>++[<<
15: <.<<<<+++++++[>>........<<-]>>>>.>.
16: >>-]<<
17: >>>-]<<<
18: <.>>>+++++++[<<<<........>>>>-]<<<.>.
19: <.>>.>+++++++[<........>-]<<.
20: >>++++++++[<<<.>.<.>.>>-]

This program uses 10 memory locations:
0: loop counter #1
1: loop counter #2
2: "*"  ASCII 42
3: spc  ASCII 32
4: "#"  ASCII 35
5: "|"  ASCII 124
6: "\n" ASCII 10
7: "0"  ASCII 48, "-"  ASCII 45
8: loop counter #3
9: loop counter #4

Line 1

This line sets up the ASCII characters in registers 2 through 7 (mostly).  Some tweaking is done later.
This code first puts 3 in register 0, and then loops 3 times incrementing register 1 four times each loop: +++[>++++<-].  Then end result is that register 0 is 0, and register 1 is 12.
The 12 is used as the loop counter for the next loop.  For 12 times through the loop, registers 2, 3, and 4 are incremented 3 times, register 5 is incremented 10 times, register 6 is incremented 1 time, and register 7 is incremented 4 times.  At the end of this loop, they contain: R2(36), R3(36), R4(36), R5(120), R6(12), R7(48).  After the loop register 2 is incremented 6 times, register 3 is decremented 4 times, and register 4 is decremented once.  At this point, the values are: R2(42), R3(32), R4(35), R5(120), R6(12), R7(48).  All but registers 5 and 6 contain their initial ASCII values.
Next register 7 is output, the "0" at the top of the flag!
Next register 6 is decremented twice to 10 (ASCII newline) and output.  Done with the first line of the flag!

Line 2

First it increments register 5 by 4 which makes it "|" (ASCII 124) and outputs it.
Then it decrements register 7 by three changing it from "0" (ASCII 48) into "-" (ASCII 45) and outputs it.
Next it puts 7 into loop counter 3 (register 8) and loops 7 times, writing out 8 dashes each time for a total of 7*8 = 56 dashes.
Finally it ends by outputting a newline.

Line 3

This line contains two loops.
The first loop writes " *  " 5 times.
Then " * " is written
The second loop loops 4 times writing 8 "#" for a total of 32.
Then "#", "|", and "\n" are written.

Lines 4 - 11

These lines use the same technique as line 3 to write out the stars and stripes of the flag.

Line 12

This line starts a loop that runs 3 times.
The loop ends at line 17.

Line 13

Writes a strip that goes across the flag.
Uses a loop that runs 7 times writing "#" 8 times each time through the loop.

Line 14

The start of a loop that runs 2 times.

Line 15

Writes a strip that goes across the flag.
Uses a loop that runs 7 times writing " " 8 times each time through the loop.

Line 16

End of inner loop that started at line 14.

Line 17

End of outer loop that started at line 13.

Line 18

Draws bottom stripe of flag.

Line 19

Draws bottom border of flag.

Line 20

Draws the flagpole.
Loops 8 times, writing "|" and newline twice each time through the loop.

You actually managed to compress the flag! I hope you'll post an explanation when you're done golfing. I'd very much like to know how this works.

I will post an explanation. I'm still golfing!

JavaScript (ES6), 153 156
Using template string, there is 1 newline that is significant and counted
Test running the snippet below (being EcmaScript 6, Firefox only)

// TEST - Just for testing purpose,redefine console.log

console.log = (...x) => O.innerHTML += x+'\n'

// SOLUTION

o=[0];for(o[r=1]=o[21]='-'[R='repeat'](57);++r<21;o[r]=" *  "[R](7).substr(r%2*2,r<11&&23)+'  #'[r%3][R](r<11?33:56)+'|')o[37]='';console.log(o.join`
|`)

To be even more patriotic, here is the EcmaScript 5 version

// TEST - Just for testing purpose,redfine console.log

console.log = function(x){ O.innerHTML += x+'\n' }

// SOLUTION - 175 bytes

for(o=(A=Array)(38),o[0]=0,r=2;r<21;r++)o[r]=A(8)[J='join'](" *  ").substr((r&1)*2,r<11?23:0)+A(r<11?34:57)[J]('  #'[r%3])+'|';
o[1]=o[r]=A(58)[J]('-'),console.log(o[J]('\n|'))

+1 for calling ES5 more patriotic

///: 225 characters
/D/ddd//d/--------//H/hhh//h/########//S/sss//s/        //A/aaaaa//a/ *  //b/|HHh|
|SSs|
|SSs|
//p/|
|
|
|
/0
|DDd-
|A * Hh#|
|  A Ss |
|A * Ss |
|  A Hh#|
|A * Ss |
|  A Ss |
|A * Hh#|
|  A Ss |
|A * Ss |
bbb|HHh|
|DDd-
pppp

Ruby, 104 102 bytes
Using ideas from ManAtWork's Ruby answer with permission.
puts 0,s=?|+?-*57,(0..18).map{|i|?|+("#  "[i%3]*(i>8?56:33)).rjust(56," *   *"[i%2*2,4])+?|},s,'|
'*16

Ruby, 127 121 112 bytes
Changed quotes to ? used array instead of conditional for stripe colour. used conditional instead of formula for stripe length.
puts 0,s=?|+?-*57
19.times{|i|puts ?|+("#  "[i%3]*(i>8?56:33)).rjust(56,i%2>0?"   *":" *  ")+?|}
puts s,"|\n"*16

The trick here is to draw the stripes (both red/# and white/space) to the correct length, then right justify them, padding with stars. Ruby's rjust allows us to specify the padding string, which alternates between " *  " and "   *".
Original version, 127 bytes
puts 0,s="|"+"-"*57
19.times{|i|puts("|"+((i%3>0?" ":"#")*((i+1)/10*23+33)).rjust(56,i%2>0?"   *":" *  ")+"|")}
puts s,"|\n"*16

Oops, I forgot to reload the page before checking whether a Ruby answer already exists. As my answer is not significantly different, I deleted it. Feel free to use any good part you may find in it.

@manatwork I don't see that you needed to delete it, it was shorter than mine and I'd already upvoted it. There were some Ruby tricks in there I didn't know, I'm new to ruby. I'm down to 104 using the best of both answers, which is the shortest answer in a conventional language.  I don't understand why I can use the map in the middle of the puts  but I can't use it on its own, even if i surround it with brackets: puts((0.18).map{}). If you see any further improvements either let me know, or undelete your own answer and post it there.

I'm impressed that Ruby rjust can take a string and not just a char. Too bad Python can't do that...

SWI-Prolog, 275 bytes
In a language of French origin, which is kind of fitting
a:-put(48),nl,b,c(0).
b:-z,w(-,57).
c(I):-nl,I=36;J is I+1,(I=19,b,c(J);I>19,z,c(J);I>8,z,(I mod 3=:=0,w(#,56);tab(56)),z,c(J);z,(I mod 2=:=0,tab(1),w('*   ',5),put(42),tab(1);w('   *',5),tab(3)),(0=:=I mod 3,w(#,33);tab(33)),z,c(J)).
z:-put(124).
w(A,B):-writef('%r',[A,B]).

See the result here

I hate to break an existing answer, but the first version had 11 stripes instead of 13. I didn't change anything else. You can check the edit history to see what I changed. Sorry about that.

@DJMcMayhem Fixed, only needed to change two numbers and didnt change the length of the answer, so it's all good

C, 235 211 208 205 203 198 197 186 bytes
i;x(){for(puts("0");i<37;i++){char b[58]="";i<21?memset(b,i%20?i%3&1?35:32:45,56),i&&i<10?memcpy(b," *   *   *   *   *   *   "+(i%2?0:2),23):0,b[56]=i%20?124:45:0;printf("|%.57s\n",b);}}

edit: added some of Cool Guy's suggestions and made use of ?: to replace some if statements.
edit: removed overflow \0 prevention and used string length limiter in printf instead.
edit: reworked both memset conditionals.
edit: moved puts("0") inside the for header to remove its semicolon.
edit: slight refactoring to get 11 more bytes.

Good first attempt. But this does not seem to print the | at the start of every line...

Your code in 198 bytes:i;c(){puts("0");for(;i<37;i++){char b[58]="|";if(i<21){memset(b,!((i-1)%3)?35:32,56);if(i<10)memcpy(b," *   *   *   *   *   *   "+((i%2)?0:2),23);b[56]='|';}if(!i||i==20){memset(b,45,57);}puts(b);}}

@Cool Guy: Thanks for the catch. I forgot to move the '|' back to the second printf from the initializer. I tried running your code using GCC under Cygwin, but the formatting is off. Is there anything special I need to do to run it or any flags needed at compile time?

No special flags required. Test it here Golf it more by using 45 instead of '-' and 35 instead of '#' and 32 instead of ' '

@Cool Guy: Good suggestion on the character encoding values. And good catch on the i==0 I overlooked. I think your initial code wasn't working because of the second puts(), but that was partially my fault because by forgetting to change the "|"'s position back, it made it seem like the buffer contained the entire string. The code in the link you provided using the printf at the end does work now.

You're welcome. You might find this helpful. :-)

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Find the Formula
Introduction
What you have to do is, given an an ASCII diagram of a chemical, output the chemical formula.
Rules
Your code must not access the internet and may not use a stored library of molecules. You may have a library of elements.
You must verify all of the elements included in the formula are real, with all elements needed to be required found here:

If there are invalid elements in the formula, you must output: Invalid elements in diagram.
Order the formulae using the Hill system: carbon then hydrogen then the other elements alphabetically.
Any library/text file of elements is not needed to be included in the byte count.
Examples
H2O
H-O-H

or
H   H
 \ /
  O

CO2
O=C=O

H4N
  H
  |
H-N-H
  |
  H

Winning
The winning code is the shortest program in bytes
Leaderboard

/* Configuration */

var QUESTION_ID = 52630; // Obtain this from the url
// It will be like http://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";

/* App */

var answers = [], page = 1;

function answersUrl(index) {
  return "http://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

function getAnswers() {
  jQuery.ajax({
    url: answersUrl(page++),
    method: "get",
    dataType: "jsonp",
    crossDomain: true,
    success: function (data) {
      answers.push.apply(answers, data.items);
      if (data.has_more) getAnswers();
      else process();
    }
  });
}

getAnswers();

var SIZE_REG = /\d+(?=[^\d&]*(?:<(?:s>[^&]*<\/s>|[^&]+>)[^\d&]*)*$)/;
var NUMBER_REG = /\d+/;
var LANGUAGE_REG = /^#*\s*([^,]+)/;

function shouldHaveHeading(a) {
  var pass = false;
  var lines = a.body_markdown.split("\n");
  try {
    pass |= /^#/.test(a.body_markdown);
    pass |= ["-", "="]
              .indexOf(lines[1][0]) > -1;
    pass &= LANGUAGE_REG.test(a.body_markdown);
  } catch (ex) {}
  return pass;
}

function shouldHaveScore(a) {
  var pass = false;
  try {
    pass |= SIZE_REG.test(a.body_markdown.split("\n")[0]);
  } catch (ex) {}
  return pass;
}

function getAuthorName(a) {
  return a.owner.display_name;
}

function process() {
  answers = answers.filter(shouldHaveScore)
                   .filter(shouldHaveHeading);
  answers.sort(function (a, b) {
    var aB = +(a.body_markdown.split("\n")[0].match(SIZE_REG) || [Infinity])[0],
        bB = +(b.body_markdown.split("\n")[0].match(SIZE_REG) || [Infinity])[0];
    return aB - bB
  });

  var languages = {};
  var place = 1;
  var lastSize = null;
  var lastPlace = 1;
  answers.forEach(function (a) {
    var headline = a.body_markdown.split("\n")[0];
    //console.log(a);
    var answer = jQuery("#answer-template").html();
    var num = headline.match(NUMBER_REG)[0];
    var size = (headline.match(SIZE_REG)||[0])[0];
    var language = headline.match(LANGUAGE_REG)[1];
    var user = getAuthorName(a);
    if (size != lastSize)
      lastPlace = place;
    lastSize = size;
    ++place;
    answer = answer.replace("{{PLACE}}", lastPlace + ".")
                   .replace("{{NAME}}", user)
                   .replace("{{LANGUAGE}}", language)
                   .replace("{{SIZE}}", size)
                   .replace("{{LINK}}", a.share_link);
    answer = jQuery(answer)
    jQuery("#answers").append(answer);

    languages[language] = languages[language] || {lang: language, user: user, size: size, link: a.share_link};
  });

  var langs = [];
  for (var lang in languages)
    if (languages.hasOwnProperty(lang))
      langs.push(languages[lang]);

  langs.sort(function (a, b) {
    if (a.lang > b.lang) return 1;
    if (a.lang < b.lang) 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);
  }

}
body { text-align: left !important}

#answer-list {
  padding: 10px;
  width: 50%;
  float: left;
}

#language-list {
  padding: 10px;
  width: 50%px;
  float: left;
}

table thead {
  font-weight: bold;
}

table td {
  padding: 5px;
}

<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

@ThomasKwa Carbon then hydrogen then alphabetical

Is the library of elements allowed to be in any order (could we have it in Hill system order)?

Are your examples listed as output followed by corresponding input? I can follow it but listing them that way around creates a nagging doubt about whether I have understood the question correctly.

@ThomasKwa are you asking whether H2C=CH2 should be handled as an input or an output?

Do we need to handle inputs like H2C=CH2?

Does the library of elementw count for the score? 2. The Hill system uses alphabetical order (no special case for H) when there' no C. Do we use the Hill system or the order you described?

Do we take the periodic table in the question as definitive? It has a minor quirk in that it lists Fl and Lv instead of Uuq and Uuh even though some elements before these are listed in the Uu? form.

@steveverrill Yes, use the periodic table given

@Dennis 1. No 2. Yes you use my specified order

@ThomasKwa No you do not

PHP, 205 bytes
function($f)use($l){for($a=preg_split('#(?=[A-Z])#',eregi_replace('[^a-z]','',$f));++$i<count($a);)if($l[$a[$i]]++===null)die('Invalid elements in diagram');foreach($l as$k=>$v)echo$v?$k.($v>1?$v:''):'';};

The array of elements is stored in the $l variable in the following form:
$l = ['C' => 0, 'H' => 0, 'Ac' => 0, …, 'Zr' => 0];

Here is the ungolfed version:
function ($formula) use ($elementsList)
{
    $linearFormula = preg_replace('#[^a-z]#i', '', $formula);       // Remove everything except the letters in the formula
    $elementsInFormula = preg_split('#(?=[A-Z])#', $linearFormula); // Split the formula before each uppercase letter, with an additional empty element in the first position

    for ($i = 1; $i < count($elementsInFormula); ++$i)
    {
        // Check if the element is valid
        if (!isset($elementsList[$elementsInFormula[$i]])) {
            die('Invalid elements in diagram');
        }

        // Increment the associated counter
        ++$elementsList[$elementsInFormula[$i]];
    }

    // Print the raw formula
    foreach ($elementsList as $element => $number)
    {
        if ($number > 0) {
            echo $element;
            if ($number > 1) {
                echo $number;
            }
        }
    }
};

@BetaDecay I'm not sure if my manipulation of the (not counted) array of elements is allowed. If it's not, what are the allowed form for this array?

@BetaDecay I've given the expected form (the $l variable) in my answer. Basically, the elements are the keys of the array, ordered using the Hill system, and are associated with a 0 value.

Your problem needs to take input via function arguments or STDIN. A variable input is not allowed on PCG as a whole AFAIK

@BetaDecay I've modified my answer accordingly.

@BetaDecay It's strange that I write the only answer. I don't know why your question doesn't have more success…

Maybe people just couldn't be bothered to try

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Print the British Flag!
Inspired by Print the American Flag! this is a direct copy but with the British flag as it has some symmetries but is still quite complex!
Your challenge is to produce the following ASCII-Art in as few bytes as possible! Turn your head/screen (not both!) by 90 degrees to view it properly.
 __________________________________________
|\  \XXXXXXXXXXXX  000000  XXXXXXXXXXXX//0/|
|0\  \XXXXXXXXXXX  000000  XXXXXXXXXXX//0/ |
|\0\  \XXXXXXXXXX  000000  XXXXXXXXXX//0/  |
|\\0\  \XXXXXXXXX  000000  XXXXXXXXX//0/  /|
|X\\0\  \XXXXXXXX  000000  XXXXXXXX//0/  /X|
|XX\\0\  \XXXXXXX  000000  XXXXXXX//0/  /XX|
|XXX\\0\  \XXXXXX  000000  XXXXXX//0/  /XXX|
|XXXX\\0\  \XXXXX  000000  XXXXX//0/  /XXXX|
|XXXXX\\0\  \XXXX  000000  XXXX//0/  /XXXXX|
|XXXXXX\\0\  \XXX  000000  XXX//0/  /XXXXXX|
|XXXXXXX\\0\  \XX  000000  XX//0/  /XXXXXXX|
|XXXXXXXX\\0\  \X  000000  X//0/  /XXXXXXXX|
|XXXXXXXXX\\0\  \  000000  //0/  /XXXXXXXXX|
|XXXXXXXXXX\\0\    000000  /0/  /XXXXXXXXXX|
|XXXXXXXXXXX\\0\   000000  0/  /XXXXXXXXXXX|
|XXXXXXXXXXXX\\0\  000000  /  /XXXXXXXXXXXX|
|XXXXXXXXXXXXX\\0  000000    /XXXXXXXXXXXXX|
|XXXXXXXXXXXXXX\\  000000   /XXXXXXXXXXXXXX|
|                  000000                  |
|000000000000000000000000000000000000000000|
|000000000000000000000000000000000000000000|
|000000000000000000000000000000000000000000|
|                  000000                  |
|XXXXXXXXXXXXXX/   000000  \\XXXXXXXXXXXXXX|
|XXXXXXXXXXXXX/    000000  0\\XXXXXXXXXXXXX|
|XXXXXXXXXXXX/  /  000000  \0\\XXXXXXXXXXXX|
|XXXXXXXXXXX/  /0  000000   \0\\XXXXXXXXXXX|
|XXXXXXXXXX/  /0/  000000    \0\\XXXXXXXXXX|
|XXXXXXXXX/  /0//  000000  \  \0\\XXXXXXXXX|
|XXXXXXXX/  /0//X  000000  X\  \0\\XXXXXXXX|
|XXXXXXX/  /0//XX  000000  XX\  \0\\XXXXXXX|
|XXXXXX/  /0//XXX  000000  XXX\  \0\\XXXXXX|
|XXXXX/  /0//XXXX  000000  XXXX\  \0\\XXXXX|
|XXXX/  /0//XXXXX  000000  XXXXX\  \0\\XXXX|
|XXX/  /0//XXXXXX  000000  XXXXXX\  \0\\XXX|
|XX/  /0//XXXXXXX  000000  XXXXXXX\  \0\\XX|
|X/  /0//XXXXXXXX  000000  XXXXXXXX\  \0\\X|
|/  /0//XXXXXXXXX  000000  XXXXXXXXX\  \0\\|
|  /0//XXXXXXXXXX  000000  XXXXXXXXXX\  \0\|
| /0//XXXXXXXXXXX  000000  XXXXXXXXXXX\  \0|
|/0//XXXXXXXXXXXX__000000__XXXXXXXXXXXX\__\|

The block is 44 x 42 characters. Note that the first line ends with a single space! No other trailing spaces are allowed but a trailing new line is allowed on the last line.
I'm not aware of any date significance for the UK at the moment!

As a frenchman, my honor prevents me from doing this challenge

@Fatalize I'll post a French Flag challenge for Bastille Day but you'll have to get the colours right!

Newton's Principia Mathematica was published July 5, 1687, but I'm not sure if that counts. On the one hand it was under the Julian calendar; on the other hand our entire date system is more or less arbitrary anyway, so if it's called the same day, why not celebrate it?

@ThomasKwa Well, Princess Charlotte has been christened today, but I think Newton's achievement is more significant.  Today is Independence Day for Algeria, Cape Verde and Venezuela, all of which have stars in their flags.

@Fatalize Here's a French flag for you in accordance with the colour scheme of this challenge: X 0. I hope that small token helps you to overcome your objections.

@CJDennis Your ascii-art skills are a lot better than mine.

@DJMcMayhem The US flag is harder because you have to somehow align 9 rows of stars with the first 7 stripes. Not nice numbers to work with in ASCII-Art!

Annnnnd the sides swap 0 and space positions... Son of a...

SpecBAS - 1137 bytes
Absolutely no hope of winning on characters, but the output is in colour...
1 PAPER 15: CLS
2 PRINT AT 1,2;("_"*42): FOR y=2 TO 42: PRINT AT y,1;"|";AT y,44;"|": NEXT y
3 FOR y=4 TO 18: PRINT AT y,y-2;"\";AT y+1,y-2;"\": NEXT y: PRINT AT 19,17;"\"
4 FOR y=2 TO 14: PRINT AT y,y;"\  \";AT y+28,y+26;"\  \": NEXT y: FOR y=15 TO 17: PRINT AT y,y;"\";AT y+12,y+13;"\": NEXT y
5 FOR y=25 TO 39: PRINT AT y,y+3;"\\": NEXT y: PRINT AT 40,43;"\"
6 FOR y=2 TO 14: PRINT AT y,42-y;"/";AT y+1,42-y;"/": NEXT y: PRINT AT 2,41;"/"
7 FOR y=2 TO 17: PRINT AT y,45-y;"/";AT y+3,45-y;"/": NEXT y
8 FOR y=2 TO 16: PRINT AT y+23,18-y;"/";AT y+26,18-y;"/": NEXT y: PRINT AT 27,17;"/"
9 FOR y=1 TO 13: PRINT AT y+29,17-y;"//": NEXT y: PRINT AT 29,17;"/"
10 PRINT AT 42,18;"__";AT 42,26;"__";AT 42,41;"__"
11 INK 2
12 FOR y=2 TO 42: PRINT AT y,20;"0"*6: NEXT y
13 FOR y=21 TO 23: PRINT AT y,2;"0"*42: NEXT y
14 FOR y=3 TO 18: PRINT AT y,y-1;"0";AT y+23,y+25;"0": NEXT y
15 FOR y=2 TO 16: PRINT AT y,44-y;"0";AT y+26,19-y;"0": NEXT y
16 INK 1
17 FOR y=2 TO 13: LET l$="x"*(14-y): PRINT AT y,4+y;l$;AT y,28;l$;AT 44-y,4+y;l$;AT 44-y,28;l$: NEXT y
18 FOR y=6 TO 19: LET l$="x"*(y-5): PRINT AT y,2;l$;AT y,49-y;l$;AT 44-y,2;l$;AT 44-y,44-LEN l$;l$: NEXT y

How short is it without colour?

12 characters less (the INK statements). Considering this is already 1000+ characters more than most entries, I'm not going to quibble about them. :-)

Haha you know you could probably get this a lot shorter in BBC BASIC

I count 1554 bytes

Python 2, 223 bytes
o=""
x="X"*15
s=x+r"\  \0\\%s//0/  /"%x
exec'o+="|%s  000000  %s|\\n"%(s[18:2:-1],s[25:41]);s=s[1:]+s[0];'*18
print" "+"_"*42+" \n"+o+"\n".join("|%s000000%s|"%(c*18,c*18)for c in" 000 ")+o[:43:-1]+o[43::-1].replace(" ","_")

Still much to golf.
Despite its looks, the back half is the same as the front half reversed (barring the underscores), which is unusually nice for a pattern with slashes.

Python 3 361 331
p=print
p("","_"*42,"")
r='|'
w="X"*16
s="\\  \\0\\\\"
z="//0/  /"
O=" 000000 "
m=r+" "*18+"0"*3
o=w+s+w
e=w+z+w
T=e[::-1]
f=o[::-1]
R=range(18)
for i in R:p(r+o[i+19:i+3:-1],O,e[i+4:i+20]+r)
B="p(m+m[::-1]);"
exec(B+"p(r+'0'*42+r);"*3+B)
for i in R[1:]:p(r+T[i+1:i+17],O,f[i+16:i:-1]+r)
p(r+T[19:35]+"__000000__"+o[4:17]+"__\\|")

This program makes use of python's awesome string slicing capabilities to create a string that represents the stripes:
o = "XXXXXXXXXXXXXXX\  \0\\XXXXXXXXXXXXXXX"

Then repeatedly print it backwards while shifting it to the right by increasing the start and end of the string slice to get this:
\  \XXXXXXXXXXX
0\  \XXXXXXXXXX
\0\  \XXXXXXXXX
\\0\  \XXXXXXXX
X\\0\  \XXXXXXX
XX\\0\  \XXXXXX
XXX\\0\  \XXXXX
XXXX\\0\  \XXXX
XXXXX\\0\  \XXX
XXXXXX\\0\  \XX
XXXXXXX\\0\  \X
XXXXXXXX\\0\  \
XXXXXXXXX\\0\
XXXXXXXXXX\\0\
XXXXXXXXXXX\\0\
XXXXXXXXXXXX\\0
XXXXXXXXXXXXX\\

This is the top left corner.
I repeat this four times with variants on the original string (like reversing the bit in the middle) to get the other four corners.

@Sp3000 Is that better?

Now I think it's a tad too thin

btw I think you overaliased - for 2 chars (e.g. -1, 17) you need to use it six times before you save anything

@Sp3000 you're right, I thought that would save 2 each.

btw there's also a trailing space on the first line, which I don't think you print

CJam, 131 126 102 99 bytes
S'_42*SK,'XE*"//0/  /"+2*f>Gf<_2>
\W%2>.{"\/"_W%er" 000 ":_@}" 0 0"
[I6I63].*+s_W%+42/{N"||"@*}/S'_er

The two linefeeds are included to prevent horizontal scrolling. Try it online in the CJam interpreter.
Idea
We start by modifying the string
XXXXXXXXXXXXXX//0/  /XXXXXXXXXXXXXX

by pushing 19 copies, discarding the first n characters for the nth copy and cutting off each results after the 16th character.
XXXXXXXXXXXXXX//
XXXXXXXXXXXXX//0
XXXXXXXXXXXX//0/
XXXXXXXXXXX//0/
XXXXXXXXXX//0/
XXXXXXXXX//0/  /
XXXXXXXX//0/  /X
XXXXXXX//0/  /XX
XXXXXX//0/  /XXX
XXXXX//0/  /XXXX
XXXX//0/  /XXXXX
XXX//0/  /XXXXXX
XX//0/  /XXXXXXX
X//0/  /XXXXXXXX
//0/  /XXXXXXXXX
/0/  /XXXXXXXXXX
0/  /XXXXXXXXXXX
/  /XXXXXXXXXXXX
  /XXXXXXXXXXXXX
 /XXXXXXXXXXXXXX

By discarding the first two strings, we obtain the upper right quadrant of the flag.
Now, if we reverse the order of the strings, once again discard the first two and swap the inclinations of the slashes, we obtain the upper left quadrant.
By concatenating the corresponding strings, with "  000000  " in the middle and appending a few runs of spaces and zeroes, we obtain
\  \XXXXXXXXXXXX  000000  XXXXXXXXXXXX//0/
0\  \XXXXXXXXXXX  000000  XXXXXXXXXXX//0/
\0\  \XXXXXXXXXX  000000  XXXXXXXXXX//0/
\\0\  \XXXXXXXXX  000000  XXXXXXXXX//0/  /
X\\0\  \XXXXXXXX  000000  XXXXXXXX//0/  /X
XX\\0\  \XXXXXXX  000000  XXXXXXX//0/  /XX
XXX\\0\  \XXXXXX  000000  XXXXXX//0/  /XXX
XXXX\\0\  \XXXXX  000000  XXXXX//0/  /XXXX
XXXXX\\0\  \XXXX  000000  XXXX//0/  /XXXXX
XXXXXX\\0\  \XXX  000000  XXX//0/  /XXXXXX
XXXXXXX\\0\  \XX  000000  XX//0/  /XXXXXXX
XXXXXXXX\\0\  \X  000000  X//0/  /XXXXXXXX
XXXXXXXXX\\0\  \  000000  //0/  /XXXXXXXXX
XXXXXXXXXX\\0\    000000  /0/  /XXXXXXXXXX
XXXXXXXXXXX\\0\   000000  0/  /XXXXXXXXXXX
XXXXXXXXXXXX\\0\  000000  /  /XXXXXXXXXXXX
XXXXXXXXXXXXX\\0  000000    /XXXXXXXXXXXXX
XXXXXXXXXXXXXX\\  000000   /XXXXXXXXXXXXXX
                  000000
000000000000000000000000000000000000000000
000000000000000000000

The second half of the flag contains almost exactly the same character, in inverted reading order (right to left, bottom to top).
All that's left to do to complete the entire flag is to push the first line, replace spaces with underscores in the last and introducing the vertical bars and actual linefeeds.
Code
S'_42*S   e# Push a space, a string of 42 underscores and another space.
K,        e# Push [0 ... 19].
'XE*      e# Push a string of 14 X's.
"//0/  /" e# Push that string.
+2*       e# Concatenate and repeat the result twice.
f>        e# Push copies with 0, ..., 19 character removed from the left.
Gf<       e# Truncate each result after 16 characters.
_2>       e# Copy the array and discard its first two elements.
\W%2>     e# Reverse the original array and discard its first two elements.

.{        e# For each pair of corresponding strings in the arrays:
  "\/"    e#   Push "\/".
  _W%     e#   Reverse a copy to push "/\\".
  er      e#   Perform transliteration on the string from the right array..
  " 000 " e#   Push that string.
  :_      e#   Duplicate each charcter to push "  000000  ".
  @       e#   Rotate the string from the left array on top.
}         e#

" 0 0"    e# Push that string.
[I6I63]   e# Push [18 6 18 63].
.*        e# Vectorized repetition.
+s        e# Concatenate ad flatten.
_W%+      e# Push a reversed copy and concatenate.
42/       e# Split into chunks of length 42.
{         e# For each chunk:
  N       e#   Push a linefeed.
  "||"@*  e#   Join the string "||", using the chunk as separator.
}/        e#
S'_er     e# Replace spaces with underscores in the last string.

Javascript ES6, 726 725 655 647 643 bytes
a="__";l=" ";b=l+l;c=`|
|`;d="X";e="0";f=b+e[r="repeat"](6)+b;g="\\  \\";h="//0/";i="/  /";Z="\\";A=Z+Z;j=A+0;k=d[r].bind(d);y=c+l[r](16)+f+l[r](16);z=c+e[r](42);B="/";C="\\0";D="0//";E=B+D;q=n=>k(n)+f+k(n);F=n=>g+q(n)+h;G=n=>c+k(n)+j+F(9-n)+k(3+n);H=n=>A+k(n+1)+c+k(n);I=n=>q(n)+g+e+H(8-n)+i+D;console.log(l+a[r](21)+`
|`+F(12)+c+e+F(11)+d+c+C+F(10)+d+d+c+j+F(9)+k(3)+c+d+j+F(8)+k(4)+G(2)+G(3)+G(4)+G(5)+G(6)+G(7)+G(8)+y+z+z+z+y+c+k(14)+B+l+f+H(13)+B+b+f+e+H(12)+i+f+C+H(11)+i+e+f+l+C+H(10)+i+"0/"+f+b+C+H(9)+i+D+I(0)+I(1)+I(2)+I(3)+I(4)+I(5)+I(6)+I(7)+I(8)+q(9)+g+e+A+c+b+E+q(10)+g+e+Z+c+l+E+q(11)+g+e+c+E+k(12)+a+e[r](6)+a+k(12)+Z+a+Z+"|")

You're using ES6, why not fat-arrow functions?

Also, template strings can cut of about two bytes for \n

PHP, 240 bytes
 <?=str_pad(_,42,_)." ";for($o=18;$o--;)$r.="
".($s="|".substr("XXXXXXXXXXXXXX\\\\0\  \\XXXXXXXXXXXX//0/",$o,16)."  000").($v=strrev)(strtr($s,"\\","/"));echo$r;for(;$i<5;)echo"
",$s=str_pad("|",19,$i++%4?0:" ")."000",$v($s);echo"
",$v($r);

Note the space before the opening tag!
Try it online.

SpecBAS again - 507 Bytes
Here's a similar version to Brian's above (I don't have enough reputation to comment yet) but without the colour. It uses a very different method to generate the display.
10 DEF FN rr$(r$)=r$(2 TO)+r$(1): DEF FN rl$(r$)=r$(LEN r$)+r$( TO LEN r$-1)
20 a$="\  \"+"x"*14+"\\0",b$="x"*12+"//0/  /xx",c$="x"*14+"/  /0//",d$="\\"+"x"*14+"\  \0",e$="  000000  ": ?" ";"_"*42: DO 18: ?"|";a$( TO 16);e$;b$( TO 16);"|": a$=FN rl$(a$),b$=FN rr$(b$): LOOP: ?"|";TAB 17;e$;TAB 43;"|"'("|"+("0"*42)+"|"+#13)*3;"|";TAB 17;e$;TAB 43;"|": DO 18: ?"|";c$( TO 16);e$;d$( TO 16);"|": c$=FN rr$(c$),d$=FN rl$(d$): LOOP: ?#11;TAB 17;"__";TAB 25;"__";TAB 40;"__"

Bubblegum, 213 bytes
00000000: b5d3 0106 4421 1080 6100 de29 e606 759c  ....D!..a..)..u.
00000010: 105d a4c3 6fdb 461f 030f f607 f019 994c  .]..o.F........L
00000020: 8cd7 c533 7b44 6f14 5177 118d 4aa9 653e  ...3{Do.Qw..J.e>
00000030: b3a2 13d6 c6c2 1d9d b076 6375 c2d8 b270  .........vcu...p
00000040: 5327 8c6d 5fac 4e18 bbb1 3a61 ecc1 6ab1  S'.m_.N...:a..j.
00000050: f662 b518 0b46 83b1 6034 180b 5683 b162  .b...F..`4..V..b
00000060: f5c5 58b1 1a8c 05a3 c158 b1fa 62ac 587d  ..X......X..b.X}
00000070: 3156 ac06 630f 8ed4 c1a9 85eb ebfe 8adf  1V..c...........
00000080: bf39 6da3 803b 67cc eab0 e08a 0663 0b93  .9m..;g......c..
00000090: d160 2c3f 8806 6b99 8c06 6bc1 1d0d c67a  .`,?..k...k....z
000000a0: 2968 3056 8c06 63c5 6830 568c 0663 c5e8  )h0V..c.h0V..c..
000000b0: 8bb5 62f5 c1d8 8cd1 1b6b 3346 2fac cd58  ..b......k3F/..X
000000c0: bdb0 3663 f4c6 da8c d10b 6f4b 63fc f018  ..6c......oKc...
000000d0: 4d3d 469f 1f                             M=F..

Try it online!


text:
Print out the Smallest Perfect Squared Square
Squaring the Square is a process of tiling a square using only other squares.  If this tiling only uses squares of different sizes, then it is considered to be perfect.  The smallest possible perfect squared square is a 112x112 square tiled using 21 different squares.
I have created the ascii art version of this square below:
################################################################################################################
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ##                         #
#                                                ##                                 ############################
#                                                ##                                 ############################
#                                                ##                                 ##      ##                 #
#                                                ##                                 ##      ##                 #
#                                                ##                                 ##      ##                 #
#                                                ##                                 ##      ##                 #
#                                                ##                                 ##      ##                 #
#                                                ##                                 ##      ##                 #
#                                                #############################################                 #
#                                                #############################################                 #
#                                                ##             ##               ##         ##                 #
#                                                ##             ##               ##         ##                 #
#                                                ##             ##               ##         ##                 #
#                                                ##             ##               ##         ##                 #
#                                                ##             ##               ##         ##                 #
#                                                ##             ##               ##         ##                 #
#                                                ##             ##               ##         ##                 #
#                                                ##             ##               ##         ##                 #
#                                                ##             ##               ##         ##                 #
#                                                ##             ##               ###############################
#                                                ##             ##               ###############################
#                                                ##             ##               ##    ##                      #
#                                                ##             ##               ##    ##                      #
##################################################################               ##    ##                      #
##################################################################               ##    ##                      #
#                           ##                       ##       ###########################                      #
#                           ##                       ##       ###########################                      #
#                           ##                       ##       ##     ##                ##                      #
#                           ##                       ##       ##     ##                ##                      #
#                           ##                       ##       ##     ##                ##                      #
#                           ##                       ##       ##     ##                ##                      #
#                           ##                       ##       ##     ##                ##                      #
#                           ##                       ##################                ##                      #
#                           ##                       ##################                ##                      #
#                           ##                       ##              ##                ##                      #
#                           ##                       ##              ##                ##                      #
#                           ##                       ##              ##                ##                      #
#                           ##                       ##              ##                ##                      #
#                           ##                       ##              ##                ##                      #
#                           ##                       ##              ##                ##                      #
#                           ##                       ##              ##                ##                      #
#                           ##                       ##              ##                ##                      #
#                           ##                       ##              ##                ##                      #
#                           ##                       ##              ###########################################
#                           ##                       ##              ###########################################
#                           ##                       ##              ##                                        #
#                           ##                       ##              ##                                        #
#                           ##                       ##              ##                                        #
#                           ###########################################                                        #
#                           ###########################################                                        #
#                           ##  ##                                   ##                                        #
#                           ##  ##                                   ##                                        #
##################################                                   ##                                        #
##################################                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
#                               ##                                   ##                                        #
################################################################################################################

Your submission should print out the above square.  You may print a reflection and/or rotation of the above square if you wish.  A trailing newline on the last line is allowed.  This is a code-golf, so the smallest submission wins!

@Optimizer According to the question and Wikipedia, all the small squares have to be completely different sizes.

Nathan, Is my submission in accordance with the rules?  I used a uniform thickness for all lines.

@DavidCarraher I have each side of the square outlined (so inner sides have multiple pound signs).  Also, you need to use # instead of X

Nathan, In the plane, edges are not borders.  They are one dimensional line segments.  Where two tiles abut, we should see a single line, not two. Otherwise, we are conveying the idea that there is a gap between the tiles.

@DavidCarraher while that is true, I think it makes more sense to represent it in ascii this way.

CJam, 88 84 83 bytes
'p:Ci_C*a*"2#   *%!"{i_S*a*{3af.|W%z}4*1$0=C#C*f{\+}..e<{_C&{oNo}|}%}/

Test it here.
Explanation
Here is the basic idea: start with an "empty" 112x112 square. Now go through the squares in reading order (left to right, top to bottom). Add each square into the first available position. Afterwards, print all completed lines - this ensures that we only need to check the first (remaining) line to figure out where the next square goes.
The empty grid is initialised to ps, because I needed a character with character code larger than space and #, and because I could reuse its own character code 112 for the size of the initial grid. I made use of some of Dennis's ASCII art tricks here to fill the small squares into the grid.
'p:C        e# Store the character 'p' in C.
i           e# Convert to its character code 112.
_C*a*       e# Generate a 112x112 array of p's.
"2#   *%!"  e# The 21 characters in this string correspond to the side lengths of
            e# the squares in the solution in reading order.
{           e# For each character in that string...
  i         e#   Convert to its character code (the current square's side length N).
  _S*a*     e#   Generate an NxN array of spaces.
  {         e#   Run this block 4 times. Each iteration turns the leading column into #'s
            e#   and then rotates the square by 90 degrees.
    3af.|   e#     For the first character in each row, take the bitwise OR with 3.
            e#     This turns spaces into #'s and leaves #'s unchanged.
    W%z     e#     Reverse and transpose, which rotates by 90 degrees.
  }4*
  1$0=      e#   Copy the remaining grid and fetch the top row.
  C#        e#   Find the index of the first 'p'.
  C*        e#   Get a string of that many p's.
  f{\+}     e#   Prepend this string to each row of the small square, which gives the
            e#   square the correct horizontal position.
  ..e<      e#   Take the pairwise minimum of the square and the remaining grid. The p's
            e#   prepended to the square will leave the grid unchanged, but the spaces
            e#   and #'s in the square will overwrite the p's in the grid.
  {         e#   Map this block onto each row of the grid.
    _C&     e#     Copy the row and check if any p's are left.
    {oNo}|  e#     If NOT, the row is complete and we print it together with a newline.
            e#     This also removes the row from the grid, such that the top row for
            e#     the next iteration will have space for the next square left.
  }%
}/

Mathematica 360 426
The code works by first drawing the perfect square of squares, rasterising and binarizing the image, and then converting 0 to "#" and 1 to " ".
The output is returned as ordinary ASCII characters in a table.
f@{n_,x_,y_}:=Rectangle[{x,y},{x+n,y+n}];t=Transpose;
Flatten[i=Rasterize[Graphics[{EdgeForm[{(*Thickness[.015],*)Black}],White,
f/@ Partition[{33,0,0,29,0,33,50,0,62,37,33,0,25,29,37,42,70,0,18,70,42,24,88,42,9,54,53,7,63,53,15,50,62,17,65,60,
11,82,66,19,93,66,35,50,77,27,85,85},3]
},ImageSize->70
],RasterSize->70]//Binarize//ImageData,1]/.{0:> "#",1:> " "};
GraphicsGrid@t@Most@Most@Rest@t[Most@Most[Rest[ArrayReshape[%,Dimensions[i]]]]]

I prefer this rendering, obtained by deleting Thickness[.015]

The line thickness does not vary, the 50x50 square is 48 space characters across and 48 space characters down, with a border of #'s. It butts up against other squares at the right and bottom, which are drawn in a similar way. Where two squares which have # all round the outside meet, you therefore get a double # for inside lines,  And the squares are indeed square, they have the same number of characters vertically and horizontally, The problem is the font. This answer does not comply with the spec, If it got accepted, the question would get closevoted for a non-objective win.

The lines are conceived as one-dimensional, not two-dimensional.  They are not to be interpreted as borders having thickness.  After all, we are partitioning a square region into square subregions.  The borders should not take up any area.

That's kinda the point. The lines go between the squares, and OP chose to represent the squares with internal borders. It might've been clearer if he'd chosen to use a different symbol for each square (and possibly also filled them.) In any case, as you can see from recent flag questions, usual understanding (and whole point of the komolgorov complexity tag) is to faithfully reproduce the Ascii art representation supplied by the OP, not make your own interpretation. While interesting, this isn't a valid answer. Many squares still have different numbers of characters in their height & width.

Reminds me of Von Karman Streets

Ruby, 180 bytes
Golfed version based on the ungolfed version below. We take advantage of the fact that there are typically 2 or 3 squares with the same y coordinate for the top left corner.
The first magic string contains ASCII codes for the square sidelength+70 and y increment +40. When encountering a square sidelength (Ascii code >67) we assume the next square is at the same y coordinate, and the x coordinate can be obtained by incrementing the current x coordinate by sidelength+2. When encountering a y increment (Ascii code<67) we increment the y coordinate accordingly and reset the x coordinate to the figure encoded in the second magic string.
a=Array.new(112){?#*112}
x=y=1
j=9
'vg_CLW0SUO3J\,a]M*KV/T3n-Hi,e'.each_byte{|i|i>67?(s=i-70;(y..y+s-1).map{|i|a[i][x,s]=" "*s};x+=s+2):(x=')Fo_h){[~'[j-=1].ord-40;y+=i-40)}
puts a

Original version
This (completely ungolfed) solution contains 315 bytes, excluding unnecessary blank lines and indents. It simply creates an array of 112 strings of 112 #'s then replaces the insides of the squares with spaces.
$a=Array.new(112){"#"*112}
def f(x,y,s)
  (y..y+s-1).map{|i|$a[i][x,s]=" "*s}
end

f(1,1,48)
f(51,1,33)
f(86,1,25)

f(86,28,6)
f(94,28,17)

f(51,36,13)
f(66,36,15)
f(83,36,9)

f(83,47,4)
f(89,47,22)

f(1,51,27)
f(30,51,23)
f(55,51,7)

f(64,53,5)
f(71,53,16)

f(55,60,14)

f(71,71,40)

f(30,76,2)
f(34,76,35)

f(1,80,31)

puts $a

R, 293 291 287 282 bytes
a=array('#',112:113)
a[,113]='
'
for(g in list(c(0,0,49,34,26),c(27,85,7,18),c(35,50,14,16,10),c(46,82,5,23),c(50,0,28,24,8,1),c(52,63,6,17),c(59,54,15),c(70,70,41),c(75,29,3,36),c(79,0,32))){y=g[1];x=g[2]
for(b in g[0:1-2]){a[(y+2):(y+b),(x+2):(x+b)]=' '
x=x+b+1}}
cat(t(a),sep='')

After I did this, I realized I had done almost the identical process as @steveverrill.  An array of '#' and blank the square interiors.  Can probably squeeze some more out of this.  The carriage return for the 3rd line is significant.  Thanks to AlexA for a few.

You only reference s once, so couldn't you do for(g in list(...)) rather than specifying s separately beforehand? I think that would save you 2-3 bytes.

@AlexA. Thanks, an obvious one that I totally missed

C, 198 bytes
char*i="bSK8C?A;6HMI927B@Z4UQ",o[112][113],x,y,p,q,n;main(){for(;y<112;puts(o[y]),y++)for(x=-1;++x<112;)if(!o[y][x]){n=*i++-48;for(p=-1;++p<n;)for(q=-1;++q<n;)o[q+y][p+x]=p&&n-1-p&&q&&n-1-q?32:35;}}

(Ungolfed)
char *i="bSK8C?A;6HMI927B@Z4UQ", o[112][113], x, y, p, q, n;
main() {
  for ( ; y<112; puts(o[y]),y++) {
    for (x=-1; ++x<112; ) {
      if (!o[y][x]) {
        n = *i++ - 48;
        for (p=-1; ++p<n; ) {
          for(q=-1; ++q<n; ) {
            o[q+y][p+x] = (p && n-1-p && q && n-1-q) ? ' ' : '#';
          }
        }
      }
    }
  }
}

All this does is scan through an array of 112×112 bytes (initialized to zero). Whenever it encounters a zero byte, it fetches a value from array i and adds a box of the corresponding size. The extra byte in each row acts as a string terminator so we can use puts() to output entire lines instead of using putchar() to output characters individually.
This can probably be golfed a little more, but I don't think it stands much chance of beating steveverrill's answer.
(ideone link)

+1 This is an excellent concept, far better than mine, in a less golfy language. I believe it might be able to beat my answer. Note you need to print a #when !(p%(n-1)&&q%(n-1))I would also look into reducing the number of for loops from four to two , using x=i%113 and y=i/113 etc.

MS-DOS Binary, 137
The following code will run in MS-DOS if you write it into a file called square.com, no further compilation required (but since it's given in hex, you need to "unhex" it first):
fcba8f01b82370e83000bd1400bb4d018b1743438a27b02043e81e004d75
f1b97000ba8f3289d7b00daab00aaab82409aa83ea70cd214975ecc331c9
88e189ce89d788e1f3aa83c2704e75f4c3201d30e223218527190524063d
1f11521d0d811c0f321f09921c04b8141670101b4d12176619076f1905a6
141066120e4602288d100221022300021f

The output will be unrecognisable in most terminals, but you can redirect it to a file (square.com > output.txt) and look at it in an text editor. If you want something more readable, the following code will produce a working square.com if fed into debug.exe (debug.exe < square.asm):
a
cld
mov dx,18f
mov ax,7023
call 13a
mov bp,14
mov bx,14d
mov dx,[bx]
inc bx
inc bx
mov ah,[bx]
mov al,20
inc bx
call 13a
dec bp
jnz 110
mov cx,70
mov dx,328f
mov di,dx
mov al,d
stosb
mov al,a
stosb
mov ax,924
stosb
sub dx,70
int 21
dec cx
jnz 125
ret
xor cx,cx
mov cl,ah
mov si,cx
mov di,dx
mov cl,ah
rep stosb
add dx,70
dec si
jnz 140
ret
db 20,1d,30,e2,23,21
db 85,27,19,05,24,6
db 3d,1f,11,52,1d,d
db 81,1c,f,32,1f,9
db 92,1c,4,b8,14,16
db 70,10,1b,4d,12,17
db 66,19,7,6f,19,5
db a6,14,10,66,12,e
db 46,02,28,8d,10,2
db 21,02,23,00,02,1f

n square.com
rcx
89
w
q

Matlab/Octave, 258
As always, Matrices. I hardcoded the row and the column indices of each square ans well as the size. I can use these to fill up a big 'blank' square of #s.
r=[2,2,2,29,29,37,37,37,48,48,52,52,52,54,54,61,72,77,77,81];
c=[2,52,87,87,95,52,67,84,84,90,2,31,56,65,72,56,72,31,35,2];
s=[47,32,24,5,16,12,14,8,3,21,26,22,6,4,15,13,39,1,34,30];
z=ones(112)*35;
for i=1:20;
    z(r(i)+(0:s(i)),c(i)+(0:s(i)))=32;
end;disp([z,''])

Bash, 252
Every codegolfer should be able to beat a general purpose compression algorithm:
base64 -d<<<H4sIADyFv1UCA+3ZOw6EMAwFwH5PgeT735EOUSyfQAgOmVeCxUgusAkRbfOLqTARd0qAQCAQCAQCgcAvg80375dW/T+lQGAbsCCdgvsdXl0AAoHjgM8e7mUA92bKG+DtpAevDPflRsko7BXcKAQCD9+X3wOPCoFA4ABgnZ/OmcHTS+bw4PXzkV7Ak93KDdboVm6wxrOAQCAQCAQCgUAgENj++7BuZsq8xQ1vMQAA|gunzip

Thanks to Toby Speight for the hint to use shorter input (silly me used gzip instead of gzip -9 for compression) and a here-string.

2 shorter with here-string: base64 -d<<<H4sIAP9YuVUAA+3XQQrDIBAF0H1PUfD+d+yq0FA7GirGie/vdEZfkCy0lLl5lOfJlPaKoAUIBAKBQCAQCLwzOP3mfdFVv9IKBM4BTyQpGA0PE0AgcB8wzC3A6vS7egH4d5YH64WPtVGh/zvygj8agcCvQuufzA+2GoFA4AZgd9KCwS7Hzu3B7qQFO09rbXDEaa0NjtgLCAQCgUAgEAgEAoHz34dj8wLKvMUNbzEAAA==|gunzip

And a shorter input gets us down to 251: base64 -d<<<H4sIADyFv1UCA+3ZOw6EMAwFwH5PgeT735EOUSyfQAgOmVeCxUgusAkRbfOLqTARd0qAQCAQCAQCgcAvg80375dW/T+lQGAbsCCdgvsdXl0AAoHjgM8e7mUA92bKG+DtpAevDPflRsko7BXcKAQCD9+X3wOPCoFA4ABgnZ/OmcHTS+bw4PXzkV7Ak93KDdboVm6wxrOAQCAQCAQCgUAgENj++7BuZsq8xQ1vMQAA|gunzip

Are you sure that works? I only get gunzip: command not found. I can get it working using a subshell: (base64 -d|gunzip)<<<..., but that still uses 258 bytes.

Strange, @user284584 - something odd with your path?  I tested what I wrote (in an interactive shell, if that makes a difference)

oh god ... try copying your comment and pasting it back into the shell. Stackexchange "helpfully" inserted 6 invisible characters, 3 each of u+200c & u+200b. After removing them, it works.

Good catch!  linebreaks :-(