Create a grid as close to a square as possible Create a function or program that makes a grid as close to an square as possible


You will be given an integer N as input, whole numbers (1,2,3,25, etc)
The output must be a perfect rectangular grid of N letters as close to a square as possible
The (wannabe)square must consist of one of the the letters O or X as specified by user


Points:


Hardcoded to only O or X: +1
A param(0/1, true/false, something similar) to rotate output (like with 5 or 8): -10
Design the square (use both O and X in some sort of pattern): -5


A pattern is considered valid if it contains both types of characters (where x/y-axis >= 3) and the pattern stays the same when flipped horizontally or vertically (exchanging Xs with Os is allowed)

Examples

INPUT: 4         INPUT: 5       INPUT: 8              INPUT: 9
OO               OOOOO          XXXX                  XOX
OO                              XXXX                  OXO  
                                or rotated 90deg      XOX


Examples which aren't allowed (not same length row or columns)

BAD RESULT: 5a        BAD RESULT: 5b      BAD RESULT: 8
OOO                   OO                  OOO
OO                    OO                  OOO
                      O                   OO


If possible please provide an online example.
CJam, 16 (31 - 10 - 5)

This takes two integers are input, first one being 0 or 1 for direction and second one being the number of O or X in the grid.

It prints an alternate O and X.

:X"OX"*X&lt;\Xmqi){(_X\%}g_X\/?/N*


This is just the function body, to try it out add l~ in front of the code like:

l~:X"OX"*X&lt;\Xmqi){(_X\%}g_X\/?/N*


and give input like

0 10


to get output like

OXOXO
XOXOX


or input like 

1 10


for

OX
OX
OX
OX
OX


Try it online here



How it works:

l~                                 "Put the two input integers to stack";
  :X                               "Assign the number of cells to X";
    "OX"*                          "Take string "OX" and repeat it X times";
         X&lt;                        "Slice it to take only first X characters";
           \                       "Swap top two stack elements, now string is at bottom";
            Xmqi)                  "Take square root of X, ceil it and put on stack";
                 {(_X\%}g          "Keep decrementing until it is perfectly divisible by X";
                         _X\/      "Copy it, divide X by that and put it on stack";
                             ?     "Based on first input integer, take either of numbers";
                              /    "Divide the XOXO string that many times";
                               N*  "Join the string parts with a new line";


Example run:

l~ed:X"OX"*edX&lt;ed\edXmqi)ed{(_X\%}ged_edXed\ed/ed?ed/edN*ed

#INPUT:
1 10

#OUTPUT:
Stack: [1 10]

Stack: [1 "OXOXOXOXOXOXOXOXOXOX"]

Stack: [1 "OXOXOXOXOX"]

Stack: ["OXOXOXOXOX" 1]

Stack: ["OXOXOXOXOX" 1 4]

Stack: ["OXOXOXOXOX" 1 2]

Stack: ["OXOXOXOXOX" 1 2 2]

Stack: ["OXOXOXOXOX" 1 2 2 10]

Stack: ["OXOXOXOXOX" 1 2 10 2]

Stack: ["OXOXOXOXOX" 1 2 5]

Stack: ["OXOXOXOXOX" 2]

Stack: [["OX" "OX" "OX" "OX" "OX"]]

Stack: ["OX
OX
OX
OX
OX"]

OX
OX
OX
OX
OX