<commit_before>module Lib
(
  problem1
) where

import qualified Data.Set as Set

-- Problems from https://projecteuler.net
-- https://projecteuler.net/problem=1
problem1 = 
  let mults3 = takeWhile (<1000) (map (*3) [1..])
      mults5 = takeWhile (<1000) (map (*5) [1..])
  in sum (Set.fromList (concat [mults3, mults5]))

-- https://projecteuler.net/problem=2
problem2 = 
  let fibs = takeWhile (<4000000) (0 : 1 : zipWith (+) fibs (tail fibs))
  in sum (filter (even) fibs)

generatePrimes :: [Int]
generatePrimes = 2 : primes'
  where isPrime (p:ps) n = p*p > n || n `rem` p /= 0 && isPrime ps n
        primes' = 3 : filter (isPrime primes') [5, 7 ..]

-- https://projecteuler.net/problem=3
problem3 :: Int -> Int
problem3 factorize =
  let primeFactors = (filter (\x -> factorize `mod` x == 0) . takeWhile (\x -> x*x < factorize)) generatePrimes
  in maximum primeFactors<commit_msg>Solved euler project problem 4<commit_after>module Lib
(
  problem1
) where

import qualified Data.Set as Set

-- Problems from https://projecteuler.net
-- https://projecteuler.net/problem=1
problem1 = 
  let mults3 = takeWhile (<1000) (map (*3) [1..])
      mults5 = takeWhile (<1000) (map (*5) [1..])
  in sum (Set.fromList (concat [mults3, mults5]))

-- https://projecteuler.net/problem=2
problem2 = 
  let fibs = takeWhile (<4000000) (0 : 1 : zipWith (+) fibs (tail fibs))
  in sum (filter (even) fibs)

generatePrimes :: [Int]
generatePrimes = 2 : primes'
  where isPrime (p:ps) n = p*p > n || n `rem` p /= 0 && isPrime ps n
        primes' = 3 : filter (isPrime primes') [5, 7 ..]

-- https://projecteuler.net/problem=3
problem3 :: Int -> Int
problem3 factorize =
  let primeFactors = (filter (\x -> factorize `mod` x == 0) . takeWhile (\x -> x*x < factorize)) generatePrimes
  in maximum primeFactors

-- https://projecteuler.net/problem=4
problem4 = 
  let threeDigitNumbers = [100..999]
      combinatorial = [(x,y) | x <- threeDigitNumbers, y <- threeDigitNumbers]
      isPalindrome = \x -> (show x) == ((reverse . show) x)
  in (maximum . filter isPalindrome . map (\(a, b) -> a * b)) combinatorial
{'fraction_non_alphanumeric': 0.16380952380952382, 'fraction_numerical': 0.041428571428571426, 'mean_word_length': 3.261663286004057, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 9, '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': '2823695', 'n_tokens_mistral': 832, 'n_tokens_neox': 739, 'n_words': 225}