<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Letters and Numbers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import Data.List\n",
    "import Data.Char\n",
    "import Data.Function\n",
    "import qualified Data.IntMap as IntMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "type State = (IntMap.IntMap (Int, Int), Int)\n",
    "\n",
    "computeState :: State -> (Int, Char) -> State\n",
    "computeState (oldMap, oldLevel) (index, c) =\n",
    "    let\n",
    "        newLevel = (if isDigit c then succ else pred) oldLevel\n",
    "        oldRange = IntMap.findWithDefault (index, index) newLevel oldMap\n",
    "        newRange = (fst oldRange, index)\n",
    "        newMap = IntMap.insert newLevel newRange oldMap\n",
    "    in\n",
    "        (newMap, newLevel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false<commit_msg>Simplify solution for Task v6 17.05 (Haskell)<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Letters and Numbers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import Data.List\n",
    "import Data.Char\n",
    "import Data.Function\n",
    "import Data.Maybe\n",
    "import qualified Data.IntMap as IntMap"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "type State = (IntMap.IntMap (Int, Int), Int)\n",
    "\n",
    "computeState :: State -> (Int, Char) -> State\n",
    "computeState (oldMap, oldLevel) (index, c) =\n",
    "    let\n",
    "        newLevel = (if isDigit c then succ else pred) oldLevel\n",
    "        rangeStart = fromMaybe index $ fmap fst $ IntMap.lookup newLevel oldMap\n",
    "        newMap = IntMap.insert newLevel (rangeStart, index) oldMap\n",
    "    in\n",
    "        (newMap, newLevel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
{'fraction_non_alphanumeric': 0.1857081728712024, 'fraction_numerical': 0.004706889174154899, 'mean_word_length': 2.3737373737373737, 'pattern_counts': {'":': 40, '<': 3, '<?xml version=': 0, '>': 7, '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': '4610201', 'n_tokens_mistral': 872, 'n_tokens_neox': 846, 'n_words': 188}