Compare commits
No commits in common. "a6aab6fa2d9b63e43af1bde4f6792cd1c8d5586d" and "5faed85cf13ca9dc2f7af3f65710369d140ee5b9" have entirely different histories.
a6aab6fa2d
...
5faed85cf1
|
@ -1,15 +1 @@
|
||||||
# Ignore all executables
|
|
||||||
### Ignore all
|
|
||||||
*
|
|
||||||
### Unignore all with extensions
|
|
||||||
!*.*
|
|
||||||
### Unignore all dirs
|
|
||||||
!*/
|
|
||||||
|
|
||||||
|
|
||||||
# Regular gitignore
|
|
||||||
.direnv
|
.direnv
|
||||||
|
|
||||||
# Haskell IR files
|
|
||||||
*.hi
|
|
||||||
*.o
|
|
|
@ -2,7 +2,6 @@
|
||||||
"cSpell.words": [
|
"cSpell.words": [
|
||||||
"concat",
|
"concat",
|
||||||
"coprime",
|
"coprime",
|
||||||
"elems",
|
|
||||||
"foldl"
|
"foldl"
|
||||||
]
|
]
|
||||||
}
|
}
|
15
flake.nix
15
flake.nix
|
@ -55,18 +55,6 @@
|
||||||
Chart-cairo
|
Chart-cairo
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
clean = pkgs.writeShellScriptBin "clean" ''
|
|
||||||
# Delete executables
|
|
||||||
find . -type f -executable -not -path '*/.git/*' -delete
|
|
||||||
|
|
||||||
# Delete all Haskell IR files
|
|
||||||
find . -type f -name '*.hi' -delete
|
|
||||||
find . -type f -name '*.o' -delete
|
|
||||||
|
|
||||||
# Delete any test graphs created
|
|
||||||
find . -type f -name 'test.png' -delete
|
|
||||||
'';
|
|
||||||
in
|
in
|
||||||
pkgs.mkShell {
|
pkgs.mkShell {
|
||||||
buildInputs = with pkgs.haskellPackages; [
|
buildInputs = with pkgs.haskellPackages; [
|
||||||
|
@ -75,9 +63,6 @@
|
||||||
haskell-language-server
|
haskell-language-server
|
||||||
ghcid
|
ghcid
|
||||||
hlint
|
hlint
|
||||||
|
|
||||||
# Scripts
|
|
||||||
clean
|
|
||||||
];
|
];
|
||||||
|
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
import qualified Data.List as List
|
|
||||||
import qualified Data.Maybe as Maybe
|
|
||||||
import Data.Set (Set)
|
|
||||||
import qualified Data.Set as Set
|
|
||||||
|
|
||||||
{-
|
|
||||||
interviewing.io question:
|
|
||||||
<https://interviewing.io/mocks/linked-in-python-matching-pairs>
|
|
||||||
|
|
||||||
Given a list of whole positive numbers, how would you go about finding two numbers in that list that sum up to a given target number. Assume no duplicates in list.
|
|
||||||
|
|
||||||
-}
|
|
||||||
|
|
||||||
|
|
||||||
wholePositiveNumbers :: Set Integer
|
|
||||||
wholePositiveNumbers = Set.fromAscList [1..1_000_000]
|
|
||||||
|
|
||||||
-- findTargetSumIn xs n =
|
|
||||||
-- (if abs (x-n) `member` xs
|
|
||||||
-- && abs (x-n) + x == n
|
|
||||||
-- then Just (abs (x-n), x)
|
|
||||||
-- else Nothing) : findTargetSumIn xs n
|
|
||||||
-- where
|
|
||||||
-- x =
|
|
||||||
ans lst sum = List.nubBy isMirror $ Maybe.catMaybes $ Set.elems $ Set.map (\x ->
|
|
||||||
let x' = abs (x-sum)
|
|
||||||
in
|
|
||||||
if x' `Set.member` lst
|
|
||||||
&& x' + x == sum
|
|
||||||
then Just (x',x)
|
|
||||||
else Nothing
|
|
||||||
) lst
|
|
||||||
|
|
||||||
isMirror (a,a') (b,b')
|
|
||||||
= a == b'
|
|
||||||
&& b == a'
|
|
||||||
|
|
||||||
example = Set.fromList [14,13,6,7,8,10,1,2]
|
|
||||||
example' = Set.fromList [14,13,6,7,8,10,1]
|
|
||||||
example'' = Set.fromList [1,14,13,3,6,7,2,8,10,4]
|
|
||||||
|
|
||||||
main = do
|
|
||||||
print "Quick 3 answers:"
|
|
||||||
print $ ans example 3
|
|
||||||
print $ ans example' 3
|
|
||||||
print $ ans example'' 5
|
|
||||||
|
|
||||||
print "Long answer"
|
|
||||||
print $ ans wholePositiveNumbers 3
|
|
|
@ -221,6 +221,4 @@ ans :: [Integer]
|
||||||
ans = take 10 $ reverse . digits $ sum oneHundredFiftyDigitNumbers
|
ans = take 10 $ reverse . digits $ sum oneHundredFiftyDigitNumbers
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = print ans
|
||||||
print ans
|
|
||||||
print (sum oneHundredFiftyDigitNumbers)
|
|
||||||
|
|
|
@ -63,5 +63,3 @@ test = map (filter . multipleOf) [1..10]
|
||||||
|
|
||||||
-- lol
|
-- lol
|
||||||
solve = foldl1 lcm [1..20]
|
solve = foldl1 lcm [1..20]
|
||||||
|
|
||||||
main = print solve
|
|
||||||
|
|
|
@ -13,29 +13,16 @@ Find the difference between the sum of the squares
|
||||||
of the first one hundred natural numbers
|
of the first one hundred natural numbers
|
||||||
and the square of the sum.
|
and the square of the sum.
|
||||||
-}
|
-}
|
||||||
upperRange :: Integer
|
upperRange = 100
|
||||||
upperRange = 1_000_000
|
|
||||||
|
|
||||||
square :: Num a => a -> a
|
|
||||||
square n = n^2
|
square n = n^2
|
||||||
|
|
||||||
squares :: [Integer]
|
|
||||||
squares = map square [1..upperRange]
|
squares = map square [1..upperRange]
|
||||||
|
|
||||||
sum' :: [Integer] -> Integer
|
|
||||||
sum' = go 0
|
sum' = go 0
|
||||||
where
|
where
|
||||||
go acc [] = acc
|
go acc [] = acc
|
||||||
go acc (x:xs) = go (acc+x) xs
|
go acc (x:xs) = go (acc+x) xs
|
||||||
|
|
||||||
sumOfSquares :: Integer
|
sumOfSquares = sum' squares
|
||||||
sumOfSquares = sum squares
|
|
||||||
|
|
||||||
squareOfTheSum :: Integer
|
squareOfTheSum = (sum [1..upperRange])^2
|
||||||
squareOfTheSum = sum [1..upperRange] ^2
|
|
||||||
|
|
||||||
solution :: Integer
|
|
||||||
solution = squareOfTheSum - sumOfSquares
|
solution = squareOfTheSum - sumOfSquares
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = print solution
|
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
-- https://projecteuler.net/problem=7
|
-- https://projecteuler.net/problem=7
|
||||||
-- Find the 10_001 prime number
|
-- Find the 10_001 prime number
|
||||||
|
|
||||||
-- import Data.Numbers.Primes (primes)
|
|
||||||
import Math.NumberTheory.Primes (primes)
|
|
||||||
|
|
||||||
primes1 :: [Integer]
|
primes1 :: [Integer]
|
||||||
primes1 = 2:3:prs
|
primes1 = 2:3:prs
|
||||||
where
|
where
|
||||||
|
@ -33,8 +30,3 @@ primes2 = 2:([3..] `minus` composites)
|
||||||
primes3 = sieve [2..]
|
primes3 = sieve [2..]
|
||||||
where
|
where
|
||||||
sieve (p : xs) = p : sieve [x | x <- xs, x `mod` p > 0]
|
sieve (p : xs) = p : sieve [x | x <- xs, x `mod` p > 0]
|
||||||
|
|
||||||
main :: IO ()
|
|
||||||
main = print $ "Arithmoi - Math.NumberTheory.Primes: " <> show ans
|
|
||||||
|
|
||||||
ans = primes !! 10_000_000
|
|
||||||
|
|
|
@ -28,7 +28,6 @@ What is the value of this product?
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Data.Char (ord)
|
import Data.Char (ord)
|
||||||
import Data.Foldable (maximumBy)
|
|
||||||
import Data.List (sort)
|
import Data.List (sort)
|
||||||
import Data.List.Split (splitOn)
|
import Data.List.Split (splitOn)
|
||||||
|
|
||||||
|
@ -47,16 +46,9 @@ digits = go []
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = print ans
|
main = print ans
|
||||||
|
|
||||||
ans :: ([Integer], Integer)
|
ans :: [[Integer]]
|
||||||
ans = (l, p)
|
ans = (windowsOf 13 . digits) thousandDigitNum
|
||||||
where
|
-- "9878799272442"
|
||||||
l = maximumBy c $ (windowsOf 13 . digits) thousandDigitNum
|
|
||||||
p = product l
|
|
||||||
c a b
|
|
||||||
| product a > product b = GT
|
|
||||||
| product a < product b = LT
|
|
||||||
| otherwise = EQ
|
|
||||||
-- "([5,5,7,6,6,8,9,6,6,4,8,9,5],23514624000)"
|
|
||||||
|
|
||||||
-- what dose it mean to have the greatest product in adjacent digits?
|
-- what dose it mean to have the greatest product in adjacent digits?
|
||||||
-- why ask it like that???
|
-- why ask it like that???
|
||||||
|
|
|
@ -17,39 +17,14 @@ Find the product `abc`.
|
||||||
-}
|
-}
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = print answer
|
||||||
print answer
|
|
||||||
print (product answer)
|
|
||||||
|
|
||||||
-- head $ [(a,b,c) | a <- [1..limit], b <- [a+1..limit], c <- [limit - a - b], a < b, b < c, a^2 + b^2 == c^2]
|
answer :: String
|
||||||
answer :: [Integer]
|
answer = "I dunno"
|
||||||
answer = head $
|
|
||||||
[ [a, b, c] |
|
|
||||||
a <- [1 .. limit],
|
|
||||||
b <- [a + 1 .. limit],
|
|
||||||
c <- [limit - a - b],
|
|
||||||
b < c,
|
|
||||||
a ^ 2 + b ^ 2 == c ^ 2]
|
|
||||||
where limit = 1000
|
|
||||||
|
|
||||||
limit = 1000
|
|
||||||
version1 = [ [a, b, c] |
|
|
||||||
a <- [1 .. limit],
|
|
||||||
b <- [a + 1 .. limit],
|
|
||||||
c <- [limit - a - b],
|
|
||||||
b < c,
|
|
||||||
a ^ 2 + b ^ 2 == c ^ 2]
|
|
||||||
|
|
||||||
version2 = [ [a, b, c] |
|
|
||||||
a <- [1 .. limit],
|
|
||||||
b <- [a + 1 .. limit],
|
|
||||||
c <- [limit - a - b],
|
|
||||||
b < c,
|
|
||||||
a ^ 2 + b ^ 2 == c ^ 2]
|
|
||||||
|
|
||||||
|
|
||||||
solve :: Integer -> [(Integer, Integer, Integer)]
|
solve :: Integer -> [(Integer, Integer, Integer)]
|
||||||
solve x = takeWhile (\(a,b,c) -> a + b + c == 1000) $ primitiveTriplesUnder x
|
solve x = takeWhile (\(a,b,c) -> a + b + c <= 1000) $ primitiveTriplesUnder x
|
||||||
|
|
||||||
euclid'sFormula :: Num c => (c, c) -> (c, c, c)
|
euclid'sFormula :: Num c => (c, c) -> (c, c, c)
|
||||||
euclid'sFormula (m, n) = (a,b,c)
|
euclid'sFormula (m, n) = (a,b,c)
|
||||||
|
@ -112,19 +87,19 @@ ans' limit = [(a, b, c)
|
||||||
, b < c
|
, b < c
|
||||||
]
|
]
|
||||||
|
|
||||||
{-
|
{-
|
||||||
- Solution to Project Euler problem 9
|
- Solution to Project Euler problem 9
|
||||||
- Copyright (c) Project Nayuki. All rights reserved.
|
- Copyright (c) Project Nayuki. All rights reserved.
|
||||||
-
|
-
|
||||||
- https://www.nayuki.io/page/project-euler-solutions
|
- https://www.nayuki.io/page/project-euler-solutions
|
||||||
- https://github.com/nayuki/Project-Euler-solutions
|
- https://github.com/nayuki/Project-Euler-solutions
|
||||||
-}
|
-}
|
||||||
|
|
||||||
|
|
||||||
-- -- Computers are fast, so we can implement a brute-force search to directly solve the problem.
|
-- Computers are fast, so we can implement a brute-force search to directly solve the problem.
|
||||||
-- perim = 1000
|
perim = 1000
|
||||||
-- main = putStrLn (show ans)
|
main = putStrLn (show ans)
|
||||||
-- ans = head [a * b * (perim - a - b) | a <- [1..perim], b <- [a+1..perim], isIntegerRightTriangle a b]
|
ans = head [a * b * (perim - a - b) | a <- [1..perim], b <- [a+1..perim], isIntegerRightTriangle a b]
|
||||||
-- isIntegerRightTriangle a b = a < b && b < c
|
isIntegerRightTriangle a b = a < b && b < c
|
||||||
-- && a * a + b * b == c * c
|
&& a * a + b * b == c * c
|
||||||
-- where c = perim - a - b
|
where c = perim - a - b
|
Loading…
Reference in New Issue