<commit_before>{-# LANGUAGE OverloadedStrings #-}

module Day09 where

import           Data.Text      (Text)
import qualified Data.Text      as T
import qualified Data.Text.IO   as TIO
import           Data.Text.Read (decimal)
import           Prelude        hiding (toInteger)

parseMarker :: Text -> (Integer, Integer)
parseMarker m = (toInteger x, toInteger y)
  where
    [x, y] = T.splitOn "x" m
    toInteger s =
      case decimal s of
        Right v -> fst v
        Left  _ -> error "Invalid conversion while processing nonterminal"

evalExprs :: Bool -> Text -> Integer
evalExprs pt2 es
  | T.null es = 0
  | currElem == '(' =
      let
        (marker, es') = T.breakOn ")" (T.tail es)<commit_msg>General cleanup on day09<commit_after>{-# LANGUAGE OverloadedStrings #-}

module Day09 where

import           Data.Text      (Text)
import qualified Data.Text      as T
import qualified Data.Text.IO   as TIO
import           Data.Text.Read (decimal)
import           Prelude        hiding (toInteger)

parseMarker :: Text -> (Integer, Integer)
parseMarker m = (toInteger x, toInteger y)
  where
    [x, y] = T.splitOn "x" m
    toInteger s =
      case decimal s of
        Right v -> fst v
        Left  _ -> error "Invalid conversion while processing nonterminal"

-- Not ideal to have a boolean change the behaviour of a function
-- but since this is a toy solution, might as well avoid all the duplication
-- it presents.
evalExprs :: Bool -> Text -> Integer
evalExprs pt2 es
  | T.null es = 0
  | currElem == '(' =
      let
        (marker, es') = T.breakOn ")" (T.tail es)
{'fraction_non_alphanumeric': 0.09811320754716982, 'fraction_numerical': 0.006289308176100629, 'mean_word_length': 2.3565400843881856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5985786', 'n_tokens_mistral': 493, 'n_tokens_neox': 485, 'n_words': 182}