<commit_before>{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UnicodeSyntax #-}

{-| This module contains examples of 'Tree's that represent the solutions to
    the n-queens problem, which is the problem of finding ways to put n queens
    on an n-by-n chessboard in such a way that they do not conflict; recall
    that, in chess, a queen attacks the row it is on, the column it is one, and
    both diagonals that it is one. Thus, solutions of the n-queens problem take
    the form of a list of coordinates such that no coordinates have overlapping
    rows, columns, or diagonals.

    The 'Tree's in this module are written in such a way that the same code can
    return either the solutions themselves or just the number of solutions.
    Specifically, the generic form of the functions takes an initial value, a
    way to update this value when a queen has been placed, and a way to finalize
    this value when all queens have been placed. For the simple examples in this
    module, if one is interested in solutions then the initial value is '[]',
    the updater prepends the column of the new queen to the list (as the queens
    are in consecutive rows), and the finalizer reverses and adds row-numbers to
    the column coordinates. If one is only interested in the count then the
    value is (), the updater returns (), and the finalizer returns `WordSum 1`.
    (The advanced example uses a more complicated arrangement but are basically
    the same idea.) The reason for this design is that it allows one to use one
    code path to obtain both kinds of results, which means that once the
    solution mode has been fully tested the count mode should work as well as it
    uses the same tested code path.
 -}
module LogicGrowsOnTrees.Examples.Queens<commit_msg>Tweaked Queens module doc to refer to MonadPlus instead of Tree.<commit_after>{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UnicodeSyntax #-}

{-| This module contains examples of 'MonadPlus's that represent the solutions
    to the n-queens problem, which is the problem of finding ways to put n
    queens on an n-by-n chessboard in such a way that they do not conflict;
    recall that, in chess, a queen attacks the row it is on, the column it is
    one, and both diagonals that it is one. Thus, solutions of the n-queens
    problem take the form of a list of coordinates such that no coordinates have
    overlapping rows, columns, or diagonals.

    The 'MonadPlus's in this module are written in such a way that the same code
    can return either the solutions themselves or just the number of solutions.
    Specifically, the generic form of the functions takes an initial value, a
    way to update this value when a queen has been placed, and a way to finalize
    this value when all queens have been placed. For the simple examples in this
    module, if one is interested in solutions then the initial value is '[]',
    the updater prepends the column of the new queen to the list (as the queens
    are in consecutive rows), and the finalizer reverses and adds row-numbers to
    the column coordinates. If one is only interested in the count then the
    value is (), the updater returns (), and the finalizer returns `WordSum 1`.
    (The advanced example uses a more complicated arrangement but are basically
    the same idea.) The reason for this design is that it allows one to use one
    code path to obtain both kinds of results, which means that once the
    solution mode has been fully tested the count mode should work as well as it
    uses the same tested code path.
 -}
module LogicGrowsOnTrees.Examples.Queens
{'fraction_non_alphanumeric': 0.04199403955567597, 'fraction_numerical': 0.000541858574911948, 'mean_word_length': 3.469733656174334, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3097115', 'n_tokens_mistral': 951, 'n_tokens_neox': 923, 'n_words': 585}