Lines
100 %
Functions
Branches
50 %
/* acrostic-board-dimensions.c
*
* Copyright 2024 Tanmay Patil <tanmaynpatil105@gmail.com>
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* SPDX-License-Identifier: (LGPL-2.1-or-later OR MIT)
*/
#include "libipuz-config.h"
#include "ipuz-acrostic.h"
#include "acrostic-board-dimensions.h"
/*
* @Algorithm used to generate dimensions:
* def generate_dimensions (quote_length):
* RATIO = 1.6
* m, n = 0, 0
* MINI = math.inf
* for height in range (1, quote_length + 1):
* middle = math.floor (height * RATIO)
* for width in range (middle - 1, middle + 2):
* area = width * height
* if (area >= quote_length) and abs (quote_length - area) < MINI:
* MINI = abs(quote_length - area)
* m = width
* n = height
* return m, n
static AcrosticBoardDimension dimensions[IPUZ_ACROSTIC_MAX_QUOTE_STR_LENGTH] = {
{1, 1}, {2, 1}, {2, 2}, {2, 2}, {3, 2}, {3, 2},
{4, 2}, {4, 2}, {3, 3}, {4, 3}, {4, 3}, {4, 3},
{5, 3}, {5, 3}, {5, 3}, {5, 4}, {5, 4}, {5, 4},
{5, 4}, {5, 4}, {6, 4}, {6, 4}, {6, 4}, {6, 4},
{7, 4}, {7, 4}, {7, 4}, {7, 4}, {7, 5}, {7, 5},
{7, 5}, {7, 5}, {7, 5}, {7, 5}, {7, 5}, {8, 5},
{8, 5}, {8, 5}, {8, 5}, {8, 5}, {9, 5}, {9, 5},
{9, 5}, {9, 5}, {9, 5}, {8, 6}, {8, 6}, {8, 6},
{9, 6}, {9, 6}, {9, 6}, {9, 6}, {9, 6}, {9, 6},
{10, 6}, {10, 6}, {10, 6}, {10, 6}, {10, 6}, {10, 6},
{10, 7}, {10, 7}, {10, 7}, {10, 7}, {10, 7}, {10, 7},
{10, 7}, {10, 7}, {10, 7}, {10, 7}, {11, 7}, {11, 7},
{11, 7}, {11, 7}, {11, 7}, {11, 7}, {11, 7}, {12, 7},
{12, 7}, {12, 7}, {12, 7}, {12, 7}, {12, 7}, {12, 7},
{11, 8}, {11, 8}, {11, 8}, {11, 8}, {12, 8}, {12, 8},
{12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8}, {12, 8},
{13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8}, {13, 8},
{13, 8}, {13, 8}, {13, 9}, {13, 9}, {13, 9}, {13, 9},
{13, 9}, {13, 9}, {13, 9}, {13, 9}, {13, 9}, {13, 9},
{13, 9}, {13, 9}, {13, 9}, {14, 9}, {14, 9}, {14, 9},
{14, 9}, {14, 9}, {14, 9}, {14, 9}, {14, 9}, {14, 9},
{15, 9}, {15, 9}, {15, 9}, {15, 9}, {15, 9}, {15, 9},
{15, 9}, {15, 9}, {15, 9}, {15, 10}, {15, 10}, {15, 10},
{15, 10}, {15, 10}, {15, 10}, {15, 10}, {15, 10}, {15, 10},
{16, 10}, {16, 10}, {16, 10}, {16, 10}, {16, 10}, {16, 10},
{16, 10}, {16, 10}, {16, 10}, {16, 10}, {17, 10}, {17, 10},
{17, 10}, {17, 10}, {17, 10}, {17, 10}, {17, 10}, {17, 10},
{17, 10}, {17, 10}, {16, 11}, {16, 11}, {16, 11}, {16, 11},
{16, 11}, {16, 11}, {17, 11}, {17, 11}, {17, 11}, {17, 11},
{17, 11}, {17, 11}, {17, 11}, {17, 11}, {17, 11}, {17, 11},
{17, 11}, {18, 11}, {18, 11}, {18, 11}, {18, 11}, {18, 11},
{18, 11}, {18, 11}, {18, 11}, {18, 11}, {18, 11}, {18, 11},
{18, 12}, {18, 12}, {18, 12}, {18, 12}, {18, 12}, {18, 12},
{19, 12}, {19, 12}, {19, 12}, {19, 12}, {19, 12}, {19, 12},
{20, 12}, {20, 12}, {20, 12}, {20, 12}, {20, 12}, {20, 12},
{19, 13}, {19, 13}, {19, 13}, {19, 13}, {19, 13}, {19, 13},
{19, 13}, {20, 13}, {20, 13}, {20, 13}, {20, 13}, {20, 13},
{20, 13}, {20, 13}, {20, 13}, {20, 13}, {20, 13}, {20, 13},
{20, 13}, {20, 13}, {21, 13}, {21, 13}, {21, 13}, {21, 13},
{21, 13}, {21, 13}, {21, 13}, {21, 13}, {21, 13}, {21, 13},
{21, 13}, {21, 13}, {21, 13}, {21, 14}, {21, 14}, {21, 14},
{21, 14}, {21, 14}, {21, 14}, {21, 14}, {21, 14}, {21, 14},
{22, 14}, {22, 14}, {22, 14}, {22, 14}, {22, 14}, {22, 14},
{22, 14}, {22, 14}, {23, 14}, {23, 14}, {23, 14}, {23, 14},
{23, 14}, {23, 14}, {23, 14}, {23, 14}, {23, 14}, {23, 14},
{23, 14}, {23, 14}, {23, 14}, {23, 14}, {23, 15}, {23, 15},
{23, 15}, {23, 15}, {23, 15}, {23, 15}, {23, 15}, {23, 15},
{23, 15}, {23, 15}, {23, 15}, {24, 15}, {24, 15}, {24, 15},
{24, 15}, {24, 15}, {24, 15}, {24, 15}, {24, 15}, {24, 15},
{25, 15}, {25, 15}, {25, 15}, {25, 15}, {25, 15}, {25, 15},
{25, 15}, {25, 15}, {25, 15}, {24, 16}, {24, 16}, {24, 16},
{24, 16}, {24, 16}, {24, 16}, {24, 16}, {24, 16}, {24, 16},
{25, 16}, {25, 16}, {25, 16}, {25, 16}, {25, 16}, {25, 16},
{25, 16}, {25, 16}, {25, 16}, {25, 16}, {26, 16}, {26, 16},
{26, 16}, {26, 16}, {26, 16}, {26, 16}, {26, 16}, {26, 16},
{26, 16}, {26, 16}, {26, 17}, {26, 17}, {26, 17}, {26, 17},
{26, 17}, {26, 17}, {26, 17}, {26, 17}, {26, 17}, {26, 17},
{26, 17}, {26, 17}, {26, 17}, {26, 17}, {27, 17}, {27, 17},
{27, 17}, {27, 17}, {27, 17}, {27, 17}, {27, 17}, {27, 17},
{27, 17}, {27, 17}, {27, 17}, {28, 17}, {28, 17}, {28, 17},
{28, 17}, {28, 17}, {28, 17}, {28, 17}, {28, 17}, {28, 17},
{28, 17}, {28, 17}, {27, 18}, {27, 18}, {27, 18}, {27, 18},
{27, 18}, {27, 18}, {27, 18}, {27, 18}, {27, 18}, {27, 18},
{28, 18}, {28, 18}, {28, 18}, {28, 18}, {28, 18}, {28, 18},
{29, 18}, {29, 18}, {29, 18}, {29, 18}, {29, 18}, {29, 18},
{29, 19}, {29, 19}, {29, 19}, {29, 19}, {29, 19}, {29, 19},
{29, 19}, {29, 19}, {29, 19}, {29, 19}, {29, 19}, {30, 19},
{30, 19}, {30, 19}, {30, 19}, {30, 19}, {30, 19}, {30, 19},
{31, 19}, {31, 19}, {31, 19}, {31, 19}, {31, 19}, {31, 19},
{31, 19}, {31, 20}, {31, 20}, {31, 20}, {31, 20}, {31, 20},
{31, 20}, {31, 20}, {31, 20}, {31, 20}, {31, 20}, {31, 20},
{31, 20}, {31, 20}, {32, 20}, {32, 20}, {32, 20}, {32, 20},
{32, 20}, {32, 20}, {32, 20}, {32, 20}, {32, 20}, {32, 20},
{32, 20}, {32, 20}, {32, 20}, {32, 20}, {33, 20}, {33, 20},
{33, 20}, {33, 20}, {33, 20}, {33, 20}, {33, 20}, {33, 20},
{32, 21}, {32, 21}, {32, 21}, {32, 21}, {32, 21}, {32, 21},
{33, 21}, {33, 21}, {33, 21}, {33, 21}, {33, 21}, {33, 21},
{33, 21}, {33, 21}, {33, 21}, {34, 21}, {34, 21}, {34, 21},
{34, 21}, {34, 21}, {34, 21}, {34, 21}, {34, 21}, {34, 21},
{34, 22}, {34, 22}, {34, 22}, {34, 22}, {34, 22}, {34, 22},
{34, 22}, {34, 22}, {34, 22}, {34, 22}, {35, 22}, {35, 22},
{35, 22}, {35, 22}, {35, 22}, {35, 22}, {35, 22}, {35, 22},
{35, 22}, {35, 22}, {36, 22}, {36, 22}, {36, 22}, {36, 22},
{36, 22}, {36, 22}, {36, 22}, {36, 22}, {36, 22}, {36, 22},
{35, 23}, {35, 23}, {35, 23}, {35, 23}, {35, 23}, {35, 23},
{35, 23}, {36, 23}, {36, 23}, {36, 23}, {36, 23}, {36, 23},
{36, 23}, {36, 23}, {36, 23}, {36, 23}, {36, 23}, {36, 23},
{37, 23}, {37, 23}, {37, 23}, {37, 23}, {37, 23}, {37, 23},
{37, 23}, {37, 23}, {37, 23}, {37, 23}, {37, 23}, {37, 24},
{37, 24}, {37, 24}, {37, 24}, {37, 24}, {37, 24}, {37, 24},
{38, 24}, {38, 24}, {38, 24}, {38, 24}, {38, 24}, {38, 24},
{39, 24}, {39, 24}, {39, 24}, {39, 24}, {39, 24}, {39, 24},
{39, 25}, {39, 25}, {39, 25}, {39, 25}, {39, 25}, {39, 25},
{39, 25}, {39, 25}, {39, 25}, {40, 25}, {40, 25}, {40, 25},
{40, 25}, {40, 25}, {40, 25}, {40, 25}, {40, 25}, {40, 25},
{40, 25}, {40, 25}, {40, 25}, {40, 25},
};
AcrosticBoardDimension
acrostic_board_dimension_from_quote_length (guint quote_length)
{
AcrosticBoardDimension board = {
.width = 0,
.height = 0,
/* Update the table if IPUZ_ACROSTIC_MAX_QUOTE_STR_LENGTH ever changes */
g_assert (G_N_ELEMENTS (dimensions) == IPUZ_ACROSTIC_MAX_QUOTE_STR_LENGTH);
g_return_val_if_fail (quote_length > 0, board);
g_return_val_if_fail (quote_length <= IPUZ_ACROSTIC_MAX_QUOTE_STR_LENGTH, board);
return dimensions[quote_length - 1];
}