1
0

Compare commits

...

78 Commits

Author SHA1 Message Date
2ef8dad418 Update flake, latest haskell build with many libraries 2026-01-03 18:50:15 -05:00
c65e1b3828 Nix fmt formatter 2026-01-03 18:16:11 -05:00
640babea21 Setup precommit 2026-01-03 18:15:57 -05:00
f0b80ccc00 Switch to flake.parts 2026-01-03 18:15:21 -05:00
f564347e2c Thoughts for next steps 2025-08-05 09:20:00 -04:00
49d4f20b18 Make computation parallel 2025-08-05 09:18:33 -04:00
f511d1c0ea Update Haskell and Flake dependencies 2025-08-04 22:05:05 -04:00
23c65a00a8 Apply nix-rfc formatting to flake 2025-03-02 15:05:33 -05:00
ba2e16d000 Update dependencies 2025-03-02 15:04:10 -05:00
724b4abcf0 Advent of Code, 2024 - Day 2 Part 2 2024-12-29 14:13:25 -05:00
caee6ea61b Spelling 2024-12-29 14:12:58 -05:00
ea4d0e8580 Rebase laster some tests 2024-12-21 13:31:04 -05:00
d54b9f9812 Be smarter! 2024-12-21 13:06:55 -05:00
b818aa089e Advent of Code 2024 Day 1 and 2 2024-12-21 13:06:43 -05:00
2eecbe9980 Collatz changes 2024-12-01 23:37:39 -05:00
4906e74cf3 Advent of Code 2024 - Day 1 2024-12-01 23:36:10 -05:00
51ae128a14 Go back to a sum in prelude 2024-12-01 23:36:10 -05:00
e0aab0618b Some python stuff??? 2024-12-01 23:35:06 -05:00
8f0915640c Latest 2024-11-15 10:21:57 -05:00
273de564c2 Test 3N+1 in a language that isn't Haskell 2024-08-03 15:58:57 -04:00
05d587e1eb Project Euler #19 2024-08-03 15:58:33 -04:00
62bef0d75a AoC 2023 - Day 4, Part 1 2023-12-20 11:54:10 -05:00
0760edeabc Skipping 3 for a while 2023-12-09 12:17:57 -05:00
13f2a77803 Start Day 3 2023-12-06 15:31:15 -05:00
fac4b3aacc Finish Day 2 - Part 2 2023-12-06 15:17:41 -05:00
29c5ea7841 Finish Day 2 - Part 1 2023-12-06 14:21:35 -05:00
56ceceaa49 Start Day 2 2023-12-04 12:31:43 -05:00
bc4c273de0 Switch gitignore, collect AoC data 2023-12-04 12:29:19 -05:00
e316345265 Fix Day1 to be more elegant 2023-12-04 12:26:03 -05:00
caf3d3b43d Trying some overlap logic in Day 1 2023-12-02 13:40:32 -05:00
2005e169f4 Day1 2023-12-01 15:17:15 -05:00
6ca4b02c67 Start of magic square 2023-11-27 16:14:16 -05:00
47b3230d69 Bigger numbers, try parallel computation 2023-11-27 16:13:29 -05:00
42afd893c9 Implement solution in Haskell as depth-first-search 2023-11-17 14:44:39 -05:00
0c31a2da33 Add problem description to go code 2023-11-17 14:42:47 -05:00
262f2aae90 Fix infinite loop
Co-authored-by: David Schlachter <https://github.com/davidschlachter>
2023-11-15 17:37:09 -05:00
f9192bc541 Run gofmt on code 2023-11-15 17:37:09 -05:00
454937e2b8 Solve Project Euler 20 2023-11-15 17:37:09 -05:00
19b263e7e9 L33t code 841 initial
Co-authored-by: David Schlachter <https://github.com/davidschlachter>
2023-11-15 17:36:12 -05:00
f826f2b2d3 Ignore hint 2023-11-10 10:41:44 -05:00
0d71490cc3 Prime ghc 2023-11-10 10:30:16 -05:00
9bf196a8f9 HackerRank FP question 2023-11-01 19:41:13 -04:00
2e328f6075 Split out haskell and regular packages 2023-10-30 17:31:16 -04:00
03276cd8c5 Question 18 2023-10-20 12:30:57 -04:00
224c8cf70c pedantic 2023-10-20 12:30:14 -04:00
08a37af729 Re-arrange, remove cruft and random primes 2023-10-20 02:42:25 -04:00
78d4ca5aea Account for negative loops 2023-10-20 02:23:50 -04:00
a3dda37643 Length is indexed by 1, start counts there 2023-10-20 02:21:40 -04:00
956e56028f Add small collatz details 2023-10-20 02:14:34 -04:00
baf8ad2559 Add Collatz exploration 2023-10-19 17:09:05 -04:00
8144edd676 Thoughts on 1 2023-10-18 23:26:03 -04:00
bc3247a792 Flailing with 15 2023-10-18 23:25:50 -04:00
9cc718e6b2 Question 16 2023-10-18 23:25:25 -04:00
b0e3c4a87d Start of 15 2023-10-14 16:41:29 -04:00
6bee470b8a Add questions 1-3 2023-09-28 16:13:48 -04:00
d4cf6b25c8 Even wilder performance increases 2023-09-27 17:04:20 -04:00
bc28995115 Add performance improvement 2023-09-27 16:51:16 -04:00
7594cb1422 Finish 14 2023-09-27 16:39:46 -04:00
e6e3cfbccc Euler question 14 - start 2023-09-19 16:31:12 -04:00
970c584d0a Hide all files, add to clean script 2023-09-19 15:42:44 -04:00
0ab298bb66 Euler question 4 - add in question statement,
and solve the problem actually be asked lol
2023-09-19 15:35:57 -04:00
a6aab6fa2d Adding in clean script 2023-09-18 19:40:42 -04:00
683ad67214 Add main functions to any that were missing 2023-09-18 19:40:01 -04:00
6e17fe91f5 Hide all executables, as well as Haskell IR 2023-09-18 11:56:43 -04:00
1c8561bf72 spelling 2023-09-18 11:56:00 -04:00
0a942554b2 Interviewing.io questions, 2023-09-16 2023-09-18 11:55:47 -04:00
5faed85cf1 Euler question 13 2023-09-15 14:28:26 -04:00
8f5004d6ff Performance improvements with math 2023-09-15 02:47:36 -04:00
38ba59c3e4 Finish question 11 using lazy lists 2023-09-15 01:33:12 -04:00
7590b3c192 Question 11 start 2023-09-14 23:51:34 -04:00
9bf9588724 spelling 2023-09-14 23:46:41 -04:00
83ff425eb4 Euler Question 10 - Whole lotta primes 2023-09-14 23:46:22 -04:00
1b689521c1 Finish up Euler 9 2023-09-14 15:06:12 -04:00
bd0b941a6a Haskell spellings 2023-09-14 15:05:54 -04:00
8eb0cec5e0 Add graphing library 2023-09-14 14:23:51 -04:00
a1e47d4d32 Starting template 2023-09-14 14:23:11 -04:00
f5fa301f71 Euler question 8 2023-09-14 11:13:11 -04:00
9db5fd08e6 Euler question 7 2023-09-13 22:57:32 -04:00
49 changed files with 5864 additions and 88 deletions

17
.gitignore vendored
View File

@@ -1 +1,18 @@
# # Ignore all executables
# ### Ignore all
# *
# ### Unignore all with extensions
# !*.*
# ### Unignore all dirs
# !*/
Main
# Regular gitignore
.direnv
# Haskell IR files
*.hi
*.o
# Graphing images created with Cairo
*.png

1
.pre-commit-config.yaml Symbolic link
View File

@@ -0,0 +1 @@
/nix/store/gr5dfsr20jqrim8w0lbhicgdnpwwwhs2-pre-commit-config.json

19
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,19 @@
{
"cSpell.words": [
"Bifunctor",
"bimap",
"Collatz",
"Combinators",
"concat",
"coprime",
"elems",
"Factorisation",
"factorise",
"foldl",
"HLINT",
"mempty",
"Prec",
"succ",
"unrecognised"
]
}

View File

@@ -1,6 +1,6 @@
# [The Universal Calculator](https://git.ewanick.com/bill/universal-calculator)
Using the GHC REPL and Haskell to teach programming concepts through the guise of mathematics.
Using the GHC REPL and Haskell to teach programming concepts through the guise of mathematics.\
A handy assistant to help you understand and solve maths problems.
- GHC = [Glasgow Haskell Compiler](https://www.haskell.org/ghc/)

129
flake.lock generated
View File

@@ -1,24 +1,139 @@
{
"nodes": {
"nixpkgs": {
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1694304580,
"narHash": "sha256-5tIpNodDpEKT8mM/F5zCzWEAnidOg8eb1/x3SRaaBLs=",
"lastModified": 1767039857,
"narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "4c8cf44c5b9481a4f093f1df3b8b7ba997a7c760",
"repo": "flake-compat",
"rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-23.05",
"repo": "flake-compat",
"type": "github"
}
},
"flake-parts": {
"inputs": {
"nixpkgs-lib": "nixpkgs-lib"
},
"locked": {
"lastModified": 1765835352,
"narHash": "sha256-XswHlK/Qtjasvhd1nOa1e8MgZ8GS//jBoTqWtrS1Giw=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "a34fae9c08a15ad73f295041fec82323541400a9",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"git-hooks-nix": {
"inputs": {
"flake-compat": "flake-compat",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1767281941,
"narHash": "sha256-6MkqajPICgugsuZ92OMoQcgSHnD6sJHwk8AxvMcIgTE=",
"owner": "cachix",
"repo": "git-hooks.nix",
"rev": "f0927703b7b1c8d97511c4116eb9b4ec6645a0fa",
"type": "github"
},
"original": {
"owner": "cachix",
"repo": "git-hooks.nix",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"git-hooks-nix",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1767364772,
"narHash": "sha256-fFUnEYMla8b7UKjijLnMe+oVFOz6HjijGGNS1l7dYaQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "16c7794d0a28b5a37904d55bcca36003b9109aaa",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"lastModified": 1765674936,
"narHash": "sha256-k00uTP4JNfmejrCLJOwdObYC9jHRrr/5M/a/8L2EIdo=",
"owner": "nix-community",
"repo": "nixpkgs.lib",
"rev": "2075416fcb47225d9b68ac469a5c4801a9c4dd85",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "nixpkgs.lib",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
"flake-parts": "flake-parts",
"git-hooks-nix": "git-hooks-nix",
"nixpkgs": "nixpkgs",
"treefmt-nix": "treefmt-nix"
}
},
"treefmt-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1767468822,
"narHash": "sha256-MpffQxHxmjVKMiQd0Tg2IM/bSjjdQAM+NDcX6yxj7rE=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "d56486eb9493ad9c4777c65932618e9c2d0468fc",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
}
},

236
flake.nix
View File

@@ -1,91 +1,181 @@
{
description = ''
A basic Haskell flake for solving problems and sketching out concepts.
https://tristancacqueray.github.io/blog/beautiful-haskell
'';
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
git-hooks-nix.url = "github:cachix/git-hooks.nix";
git-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs }: {
devShell.x86_64-linux =
let
pkgs = nixpkgs.legacyPackages.x86_64-linux;
ghc = pkgs.haskell.packages.ghc928.ghcWithHoogle (self: with self;
[
relude
split
aeson
random
neat-interpolation
]
);
in
pkgs.mkShell {
buildInputs = with pkgs.haskellPackages; [
ghc
haskell-language-server
ghcid
hlint
];
shellHook = ''
echo ".------..------..------..------..------..------..------..------..------..------."
echo "|U.--. ||N.--. ||I.--. ||V.--. ||E.--. ||R.--. ||S.--. ||A.--. ||L.--. ||=.--. |"
echo "| (\/) || :(): || (\/) || :(): || (\/) || :(): || :/\: || (\/) || :/\: || (\/) |"
echo "| :\/: || ()() || :\/: || ()() || :\/: || ()() || :\/: || :\/: || (__) || :\/: |"
echo "| '--'U|| '--'N|| '--'I|| '--'V|| '--'E|| '--'R|| '--'S|| '--'A|| '--'L|| '--'=|"
echo "[------'[------'[------'[------'[------'[------'[------'[------'[------'[------'"
echo ".------..------..------..------..------..------..------..------..------..------."
echo "|C.--. ||A.--. ||L.--. ||C.--. ||U.--. ||L.--. ||A.--. ||T.--. ||O.--. ||R.--. |"
echo "| :/\: || (\/) || :/\: || :/\: || (\/) || :/\: || (\/) || :/\: || :/\: || :(): |"
echo "| :\/: || :\/: || (__) || :\/: || :\/: || (__) || :\/: || (__) || :\/: || ()() |"
echo "| '--'C|| '--'A|| '--'L|| '--'C|| '--'U|| '--'L|| '--'A|| '--'T|| '--'O|| '--'R|"
echo "[------'[------'[------'[------'[------'[------'[------'[------'[------'[------'"
echo " _ _ _ _ "
echo "| | | | (_) | | ______ "
echo "| | | | _ __ _ __ __ ___ _ __ ___ __ _ | ||______|"
echo "| | | || '_ \ | |\ \ / / / _ \| '__|/ __| / _[ || | ______ "
echo "| |_| || | | || | \ V / | __/| | \__ \| (_| || ||______|"
echo " \___/ |_| |_||_| \_/ \___||_| |___/ \__,_||_| "
echo " "
echo " "
echo " _____ _ _ _ "
echo "/ __ \ | | | | | | "
echo "| / \/ __ _ | | ___ _ _ | | __ _ | |_ ___ _ __ "
echo "| | / _[ || | / __|| | | || | / _[ || __| / _ \ | '__| "
echo "| \__/\| (_| || || (__ | |_| || || (_| || |_ | (_) || | "
echo " \____/ \__,_||_| \___| \__,_||_| \__,_| \__| \___/ |_| "
'';
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
# To import a flake module
# 1. Add foo to inputs
# 2. Add foo as a parameter to the outputs function
# 3. Add here: foo.flakeModule
inputs.git-hooks-nix.flakeModule
inputs.treefmt-nix.flakeModule
];
systems = [
"x86_64-linux"
# "aarch64-linux"
# "aarch64-darwin"
# "x86_64-darwin"
];
flake = {
# The usual flake attributes can be defined here, including system-
# agnostic ones like nixosModule and system-enumerating ones, although
# those are more easily expressed in perSystem.
};
};
perSystem = {
config,
self',
inputs',
pkgs,
system,
...
}: {
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
# system.
# Equivalent to inputs'.nixpkgs.legacyPackages.hello;
# packages.default = pkgs.hello;
devShells.default = let
# https://downloads.haskell.org/~ghc/9.10.3/docs/users_guide/index.html
ghc' = pkgs.haskell.packages.ghc9103.ghcWithHoogle (
self:
with self; [
relude
split
aeson
random
neat-interpolation
# maths
primes
arithmoi
parallel
# graphing libraries!
Chart
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 '*.png' -delete
'';
in
pkgs.mkShell {
packages = with pkgs; [
cowsay
alejandra
ghc'
clean
haskell-language-server
ghcid
hlint
kotlin
];
shellHook = ''
${config.pre-commit.installationScript}
echo ".------..------..------..------..------..------..------..------..------..------."
echo "|U.--. ||N.--. ||I.--. ||V.--. ||E.--. ||R.--. ||S.--. ||A.--. ||L.--. ||=.--. |"
echo "| (\/) || :(): || (\/) || :(): || (\/) || :(): || :/\: || (\/) || :/\: || (\/) |"
echo "| :\/: || ()() || :\/: || ()() || :\/: || ()() || :\/: || :\/: || (__) || :\/: |"
echo "| '--'U|| '--'N|| '--'I|| '--'V|| '--'E|| '--'R|| '--'S|| '--'A|| '--'L|| '--'=|"
echo "[------'[------'[------'[------'[------'[------'[------'[------'[------'[------'"
echo ".------..------..------..------..------..------..------..------..------..------."
echo "|C.--. ||A.--. ||L.--. ||C.--. ||U.--. ||L.--. ||A.--. ||T.--. ||O.--. ||R.--. |"
echo "| :/\: || (\/) || :/\: || :/\: || (\/) || :/\: || (\/) || :/\: || :/\: || :(): |"
echo "| :\/: || :\/: || (__) || :\/: || :\/: || (__) || :\/: || (__) || :\/: || ()() |"
echo "| '--'C|| '--'A|| '--'L|| '--'C|| '--'U|| '--'L|| '--'A|| '--'T|| '--'O|| '--'R|"
echo "[------'[------'[------'[------'[------'[------'[------'[------'[------'[------'"
echo " _ _ _ _ "
echo "| | | | (_) | | ______ "
echo "| | | | _ __ _ __ __ ___ _ __ ___ __ _ | ||______|"
echo "| | | || '_ \ | |\ \ / / / _ \| '__|/ __| / _[ || | ______ "
echo "| |_| || | | || | \ V / | __/| | \__ \| (_| || ||______|"
echo " \___/ |_| |_||_| \_/ \___||_| |___/ \__,_||_| "
echo " "
echo " "
echo " _____ _ _ _ "
echo "/ __ \ | | | | | | "
echo "| / \/ __ _ | | ___ _ _ | | __ _ | |_ ___ _ __ "
echo "| | / _[ || | / __|| | | || | / _[ || __| / _ \ | '__| "
echo "| \__/\| (_| || || (__ | |_| || || (_| || |_ | (_) || | "
echo " \____/ \__,_||_| \___| \__,_||_| \__,_| \__| \___/ |_| "
'';
};
pre-commit = {
settings.hooks = {
alejandra.enable = true;
mdformat.enable = true;
prettier.enable = true;
prettier.excludes = [".*\.md" "flake.lock"];
stylish-haskell.enable = true;
};
};
treefmt = {
programs = {
alejandra.enable = true;
mdformat.enable = true;
prettier.enable = true;
prettier.excludes = ["*.md"];
stylish-haskell.enable = true;
};
};
};
};
}

94
src/3n+1/Main.hs Normal file
View File

@@ -0,0 +1,94 @@
{-
The Simplest Math Problem No One Can Solve - Collatz Conjecture
https://youtu.be/094y1Z2wpJg
-}
import Control.Parallel.Strategies
import Data.Containers.ListUtils
import Debug.Trace (trace)
main :: IO ()
main = do
let start = 2^1_000_000
let end = 100
-- let message = "Starting at " <> show start <> ", and computing " <> show end <> " values."
let message = "Starting at 2^1_000_000, and computing " <> show end <> " values."
let results = parMap rpar f [start..start+end] :: [Integer]
putStrLn "======================================"
putStrLn message
print $ nubOrd results
putStrLn "======================================"
{-
Idea for next steps
Don't compute numbers if even, we know they'll go to 1
(https://smunix.github.io/dev.stephendiehl.com/hask/tutorial.pdf - Scientific numbers)
Sample a few numbers at a given order of magnitude, then increase the exponent and sample more numbers
eg. [-10..n..+10], where n = 2^1_000, then n = 2^1_001, then n = 2^2_000, etc.
-}
{-
Starting at 2^1_000, and computing 100 values.
- [1001,7249,7430]
Starting at 2^10_000, and computing 100 values.
- [10001,72379]
Starting at 2^100_000, and computing 100 values.
- [100001,717859]
Starting at 2^1_000_000, and computing 100 values.
- [1000001,7212801]
-}
lst :: [Integer]
lst = take 300 [2^100_000..]
f :: Integer -> Integer
f n = s 1 n
where
s :: Integer -> Integer -> Integer
s c n
| n == 1 = c
| n == 0 = c
| n == (-1) = c
| n == (-5) = c
| n == (-17) = c
| even n = s c' (n `div` 2)
| odd n = s c' (3*n + 1)
where c' = succ c
f' :: Integer -> Integer
f' n = f'' 1 n
where
f'' :: Integer -> Integer -> Integer
f'' i n'
| n' == 1 = t' 0 + t i
| n' == 0 = t' 0 + t i
| n' == (-1 ) = t' 0 + t i
| n' == (-5 ) = t' 0 + t i
| n' == (-17) = t' 0 + t i
| even n' = t $ f'' (succ i) (n' `div` 2)
| odd n' = t $ f'' (succ i) (3*n' + 1)
where t = trace ("i: " ++ show i ++ ", number: " ++ show n')
t' = t'' $ trace ("END: " ++ show n ++ ", length: " <> show i) t''
t'' = trace "\n#######################################################\n"
-- collatz collect
-- generate the collatz sequence and return it
cc :: Integer -> [Integer]
cc n = cc' [] n
where
cc' :: [Integer] -> Integer -> [Integer]
cc' acc n
| n == 1 = acc <> [1]
| n == 0 = acc <> [0]
| n == (-1) = acc <> [-1]
| n == (-5) = acc <> [-5]
| n == (-17) = acc <> [-17]
| even n = cc' acc' (n `div` 2)
| odd n = cc' acc' (3*n + 1)
where acc' = acc <> [n]
x = map (length . cc) [2^1_000+10..]

45
src/3n+1/Main.kt Normal file
View File

@@ -0,0 +1,45 @@
import java.math.BigInteger
// var count = 1
val big2 = BigInteger("2")
val big3 = BigInteger("3")
fun main() {
var startingN = BigInteger("10").pow(100000)
while(true) {
// print("Num: $startingN, ")
var count = f(startingN)
println("Count: $count")
startingN = startingN.inc()
}
}
fun f(nPrime: BigInteger): Int {
var count = 1
var n = nPrime
while (!n.equals(BigInteger.ONE)) {
val isEven = n.rem(big2).equals(BigInteger.ZERO)
count++
if(isEven) {
n = n.div(big2)
} else {
n = n.times(big3).inc()
}
}
return count
}
/*
f :: Integer -> Integer
f n = s 1 n
where
s :: Integer -> Integer -> Integer
s i n
| n == 1 = i
| n == 0 = i
| n == (-1) = i
| n == (-5) = i
| n == (-17) = i
| even n = s (succ i) (n `div` 2)
| odd n = s (succ i) (3*n + 1)
*/

View File

@@ -0,0 +1,81 @@
= Collatz Chains in Haskell
== Title header
This is a literate haskell blog post. You can load and run this code!
The Simplest Math Problem No One Can Solve - Collatz Conjecture
<https://youtu.be/094y1Z2wpJg>
Why do we want to do this?
> collatzStep :: Integer -> Integer
> collatzStep n
> | even n = n `div` 2
> | odd n = 3 * n + 1
With this, we can iterate over it.
> collatzStep' :: Integer -> Integer
> collatzStep' n
> | n == 1 = error "done"
> | even n = n `div` 2
> | odd n = 3 * n + 1
> result :: [Integer]
> result = iterate collatzStep' 5
collatz collect
generate the collatz sequence and return it
> cc :: Integer -> [Integer]
> cc n = cc' [] n
> where
> cc' :: [Integer] -> Integer -> [Integer]
> cc' acc n
> | n == 1 = acc <> [1]
> | n == 0 = acc <> [0]
> | n == (-1) = acc <> [-1]
> | n == (-5) = acc <> [-5]
> | n == (-17) = acc <> [-17]
> | even n = cc' acc' (n `div` 2)
> | odd n = cc' acc' (3*n + 1)
> where acc' = acc <> [n]
> a :: [Integer]
> a = reverse $ cc $ 2^1_000+1
> b :: [Integer]
> b = reverse $ cc $ 2^1_000+2
> comparingChains :: [Bool]
> comparingChains = zipWith (==) a b
Now if we collect the chain lengths of large numbers we see something slightly horrifying:
> x = map (length . cc) [2^1_000+10..]
This prints us the list of lengths of the chain as:
[7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7430,7249,7249,7249,7249,7249,7249,7249,7249,7249,7430,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7430,7430,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7430,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7430,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7430,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249,7249...]
λ> cc 13
[13,40,20,10,5,16,8,4,2,1]
λ> cc 12
[12,6,3,10,5,16,8,4,2,1]
Now this makes sense with small numbers.
But I find it weird with large numbers.
> f :: Integer -> Integer
> f n = s 1 n
> where
> s :: Integer -> Integer -> Integer
> s i n
> | n == 1 = i
> | n == 0 = i
> | n == (-1) = i
> | n == (-5) = i
> | n == (-17) = i
> | even n = s (succ i) (n `div` 2)
> | odd n = s (succ i) (3 * n + 1)

View File

@@ -0,0 +1,161 @@
-- https://adventofcode.com/2023/day/1
import Data.Bifunctor (bimap, second)
import Data.Maybe (fromJust, fromMaybe, isJust)
import Data.Text (Text, pack, replace, unpack)
import Text.ParserCombinators.ReadP (ReadP, choice, many, readP_to_S,
string, (<++))
main :: IO ()
main = do
entries <- lines <$> readFile "src/advent_of_code/2023/input1"
print "Advent of Code 2023 - Day 1"
-- print entries
print ("Part 1: " <> show (solveP1 entries))
print ("Part 2: " <> show (solveP2 entries))
--
-- Part 1
--
solveP1 :: [String] -> Int
solveP1 = sum . map solveP1Line
solveP1Line :: String -> Int
solveP1Line = sumPairS . bimap head last . doubleString . filter isNumP1 . tokenized tokensP1
tokensP1 :: ReadP String
tokensP1 = parseNumberChars <++ parseChars
--
-- Part 2
--
solveP2 :: [String] -> Int
solveP2 = sum . map solveP2Line
solveP2Line :: String -> Int
solveP2Line = sumPairS . bimap head last . doubleString . map stringToNum . filter isNumP2 . tokenized tokensP2 . replaceAll overlaps
tokensP2 :: ReadP String
tokensP2 = parseNumberWords <++ parseNumberChars <++ parseChars
--
-- Utility functions
--
-- Doing this because I want to use a bifunctor
doubleString :: str -> (str, str)
doubleString str = (str, str)
sumPairS :: (String, String) -> Int
sumPairS (x,y) = read (x ++ y)
stringToNum :: String -> String
stringToNum str = fromMaybe str (lookup str $ zip numberWords numberChars)
--
-- Boilerplate equality checks
-- Now condensed
--
isNumP1 :: String -> Bool
isNumP1 = flip elem numberChars
isNumP2 :: String -> Bool
isNumP2 = flip elem (numberChars ++ numberWords)
--
-- Parsing for question
--
letterChars :: String
letterChars = ['a'..'z']
numberChars :: [String]
numberChars = map show [0..9]
numberWords :: [String]
numberWords = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
parseChars :: ReadP String
parseChars = choice $ map (\c -> string [c]) letterChars
parseNumberChars :: ReadP String
parseNumberChars = choice $ map string numberChars
parseNumberWords :: ReadP String
parseNumberWords = choice $ map string numberWords
tokenized :: ReadP a -> String -> [a]
tokenized tokenSet = fst . last . readP_to_S (many tokenSet)
--
-- Detecting overlaps
-- - Instead of reversing to tokenize from the right, I'm using the numberWords list to create a set of possible string overlaps
-- - later I'll detect these and replace them, to be able to parse all strings from left to right
--
overlaps :: [(String, String)]
overlaps = concatMap combineOverlaps overlapsDerived
-- Not used, but the full list written manually
overlapsSpec :: [((String, String), String)]
overlapsSpec =
[ (("zero" , "one" ), "01")
, (("one" , "eight"), "18")
, (("two" , "one" ), "21")
, (("three", "eight"), "38")
, (("five" , "eight"), "58")
, (("seven", "nine" ), "79")
, (("eight", "two" ), "82")
, (("eight", "three"), "83")
, (("nine" , "eight"), "98")
]
overlapsDerived :: [(String, [String])]
overlapsDerived = map (second fromJust) . filter (isJust . snd) . zip numberWords $ map findOverlaps numberWords
where
findOverlaps :: String -> Maybe [String]
findOverlaps str = if null overlaps then Nothing else Just overlaps
where
overlaps = filter (\s -> last str == head s) numberWords
combineOverlaps :: (String, [String]) -> [(String, String)]
combineOverlaps (numStr, [] ) = []
combineOverlaps (numStr, over:laps) = (numStr ++ tail over, stringToNum numStr ++ stringToNum over) : combineOverlaps (numStr, laps)
-- String replace using Text lol
replace' :: String -> String -> String -> String
replace' needle replacement haystack = unpack $ replace needle' replacement' haystack'
where
needle' = pack needle
replacement' = pack replacement
haystack' = pack haystack
replaceAll :: [(String, String)] -> String -> String
replaceAll overlaps str = foldl (\haystack (needle, replacement) -> replace' needle replacement haystack) str overlaps
--
-- Examples
--
example1 :: [String]
example1 =
[ "1abc2"
, "pqr3stu8vwx"
, "a1b2c3d4e5f"
, "treb7uchet"
]
example2 :: [String]
example2 =
[ "two1nine"
, "eightwothree"
, "abcone2threexyz"
, "xtwone3four"
, "4nineeightseven2"
, "zoneight234"
, "7pqrstsixteen"
]

View File

@@ -0,0 +1,124 @@
-- https://adventofcode.com/2023/day/2
{-# LANGUAGE OverloadedStrings #-}
import Data.Bifunctor (Bifunctor (bimap, second))
import Data.Char (isSpace)
import Data.List (foldl')
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
main :: IO ()
main = do
entries <- T.lines <$> T.readFile "src/advent_of_code/2023/input2"
putStrLn "Advent of Code 2023 - Day 2"
putStrLn ("Part 1: " <> show (solveP1 entries))
putStrLn ("Part 2: " <> show (solveP2 entries))
--
-- Part 1
--
data Colour
= Red
| Green
| Blue
deriving (Show, Read, Ord, Eq)
data Cube c n
= Cube c n
deriving (Show, Read, Ord, Eq)
cubeLessThanLimit :: (Cube Colour Int, Cube Colour Int, Cube Colour Int) -> Cube Colour Int -> Bool
cubeLessThanLimit (Cube Red n, _, _) (Cube Red v) = v <= n
cubeLessThanLimit (_, Cube Green n, _) (Cube Green v) = v <= n
cubeLessThanLimit (_, _, Cube Blue n) (Cube Blue v) = v <= n
lessThanP1 :: Cube Colour Int -> Bool
lessThanP1 = cubeLessThanLimit p1Limit
p1Limit :: (Cube Colour Int, Cube Colour Int, Cube Colour Int)
p1Limit = (Cube Red 12, Cube Green 13, Cube Blue 14)
solveP1 :: [Text] -> Int
solveP1 = sum . map fst . filter snd . map (second (all (== True) . concatMap (map lessThanP1)) . parseInput)
--
-- Part 2
--
solveP2 :: [Text] -> Int
solveP2 = sumOfPowerCubes . allMinCubes . parsedEntries
parsedEntries :: [Text] -> [[[Cube Colour Int]]]
parsedEntries = map (snd . parseInput)
allMinCubes :: [[[Cube Colour Int]]] -> [(Cube Colour Int, Cube Colour Int, Cube Colour Int)]
allMinCubes = map findMinimumCubes
where
findMinimumCubes :: [[Cube Colour Int]] -> (Cube Colour Int, Cube Colour Int, Cube Colour Int)
findMinimumCubes = foldl' (compareRGBCubes (>)) cubeMempty . map (foldl' minimumCubesRequired cubeMempty)
sumOfPowerCubes :: [(Cube Colour Int, Cube Colour Int, Cube Colour Int)] -> Int
sumOfPowerCubes = sum . map powerCube
where
powerCube :: (Cube Colour Int, Cube Colour Int, Cube Colour Int) -> Int
powerCube (r,g,b) = n
where
r' = cubeVal r
g' = cubeVal g
b' = cubeVal b
n = r' * g' * b'
minimumCubesRequired
:: (Cube Colour Int, Cube Colour Int, Cube Colour Int)
-> Cube Colour Int
-> (Cube Colour Int, Cube Colour Int, Cube Colour Int)
minimumCubesRequired (r,g,b) (Cube Red n) = if n > cubeVal r then (Cube Red n,g,b ) else (r,g,b)
minimumCubesRequired (r,g,b) (Cube Green n) = if n > cubeVal g then (r,Cube Green n,b) else (r,g,b)
minimumCubesRequired (r,g,b) (Cube Blue n) = if n > cubeVal b then (r,g,Cube Blue n ) else (r,g,b)
compareRGBCubes
:: (Int -> Int -> Bool)
-> (Cube Colour Int, Cube Colour Int, Cube Colour Int)
-> (Cube Colour Int, Cube Colour Int, Cube Colour Int)
-> (Cube Colour Int, Cube Colour Int, Cube Colour Int)
compareRGBCubes f (h,i,j) (k,l,m) = (r,g,b)
where
r = if cubeVal h `f` cubeVal k then h else k
g = if cubeVal i `f` cubeVal l then i else l
b = if cubeVal j `f` cubeVal m then j else m
cubeMempty :: (Cube Colour Int, Cube Colour Int, Cube Colour Int)
cubeMempty = (Cube Red 0, Cube Green 0, Cube Blue 0)
cubeVal :: Cube Colour Int -> Int
cubeVal (Cube _ n) = n
--
-- Parsing
--
parseInput :: Text -> (Int, [[Cube Colour Int]])
parseInput = bimap (read . T.unpack . T.drop 5) (map (map stringToCube . T.splitOn ", ") . T.splitOn "; " . T.drop 2) . T.breakOn ": "
stringToCube :: Text -> Cube Colour Int
stringToCube str = read $ "Cube " <> colour' <> " " <> n'
where
(n, colour) = second (T.drop 1) . T.break isSpace $ str
colour' = T.unpack (T.toTitle colour)
n' = T.unpack n
--
-- Examples
--
example :: [Text]
example =
[ "Game 1: 3 blue, 4 red; 1 red, 2 green, 6 blue; 2 green"
, "Game 2: 1 blue, 2 green; 3 green, 4 blue, 1 red; 1 green, 1 blue"
, "Game 3: 8 green, 6 blue, 20 red; 5 blue, 4 red, 13 green; 5 green, 1 red"
, "Game 4: 1 green, 3 red, 6 blue; 3 green, 6 red; 3 green, 15 blue, 14 red"
, "Game 5: 6 red, 1 blue, 3 green; 2 blue, 1 red, 2 green"
]

View File

@@ -0,0 +1,108 @@
-- https://adventofcode.com/2023/day/3
{-# LANGUAGE OverloadedStrings #-}
import Data.Bifunctor
import Data.List
import Data.Char
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import Debug.Trace (trace)
main :: IO ()
main = do
entries <- T.lines <$> T.readFile "src/advent_of_code/2023/input3"
putStrLn "Advent of Code 2023 - Day 3"
putStrLn ("Part 1: " <> show (solveP1 entries))
-- putStrLn ("Part 2: " <> show (solveP2 entries))
--
-- Part 1
--
allCoords :: Int -> [(Int, Int)]
allCoords n = [ (x,y) | x <- [0..n-1], y <- [0..n-1]]
getSymbolSet :: [Text] -> String
getSymbolSet = nub . concatMap
(filter (\str
-> not (isDigit str)
&& (/= '.') str
) . T.unpack)
nextCoord :: [(Int, Int)]
nextCoord = [ (x,y) | x <- [-1,0,1], y <- [-1,0,1] ]
adjacentCoords :: Int -> (Int, Int) -> [(Int, Int)]
adjacentCoords l (x,y) =
filter (and . tupleToList . bimap gtl gtl)
. filter (and . tupleToList . bimap gtz gtz)
$ map (bimap (+x) (+y)) nextCoord
where
gtz = (>=0)
gtl = (< l)
tupleToList (a, b) = [a,b]
pointer :: [Text] -> String -> (Int, Int) -> Int
pointer txt symbolSet (x,y) = numberAt symbolSet x $ txt !! y
numberAt :: String -> Int -> Text -> Int
numberAt symbolSet n txt = if not $ check (T.head h')
then 0
else sumPair . bimap
(T.takeWhileEnd check)
(T.takeWhile check)
$ (h,h')
where
isElem = flip elem symbolSet
check a = a /= '.' && not (isElem a)
(h,h') = T.splitAt n txt
sumPair :: (Text, Text) -> Int
sumPair (a,b) = read str'
where
str = T.unpack $ T.concat [a,b]
str' = if null str then "0" else str
-- attachCoords :: [Text] -> [((Int, Int), Char)]
-- attachCoords = concat . zipWith (\col -> map (\(r,c) -> ((r,col),c))) [0..] . map (zip [0..] . T.unpack)
attachCoords :: [Text] -> [[((Int, Int), Char)]]
attachCoords = zipWith (\col -> map (\(r,c) -> ((r,col),c))) [0..] . map (zip [0..] . T.unpack)
solveP1 = id
getAllNumbers :: [Text] -> [Int]
getAllNumbers = map (read . T.unpack) . concatMap (filter (not . T.null) . T.split (not . isDigit))
test = groupBy (\((i,_),c) ((j,_),c')
-> trace ("\n" <> show c <> show i <> ", " <> show c' <> show j <> "\n")
i == j-1
) $ concatMap (filter (\(_,c)-> isDigit c)) $ attachCoords example
--
-- Part 2
--
solveP2 = id
--
-- Examples
--
example :: [Text]
example =
[ "467..114.."
, "...*......"
, "..35..633."
, "......#..."
, "617*......"
, ".....+.58."
, "..592....."
, "......755."
, "...$.*...."
, ".664.598.."
]

View File

@@ -0,0 +1,69 @@
-- https://adventofcode.com/2023/day/4
{-# LANGUAGE OverloadedStrings #-}
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
main :: IO ()
main = do
entries <- T.lines <$> T.readFile "src/advent_of_code/2023/input4"
putStrLn "Advent of Code 2023 - Day 4"
-- print entries
putStrLn ("Part 1: " <> show (solveP1 entries))
-- putStrLn ("Part 2: " <> show (solveP2 entries))
--
-- Part 1
--
double :: Int -> Int
double = (* 2)
scoreWins :: Int -> Int
scoreWins 0 = 0
scoreWins n = last . take n $ iterate double 1
parse :: Text -> ([Int], [Int])
parse line = (winners, numbers)
where
parsed =
map (map (read . T.unpack)
. filter (not . T.null)
. T.splitOn " ")
. T.splitOn "|"
. T.drop 2
. T.dropWhile (/= ':')
$ line
winners = head parsed
numbers = last parsed
scoreTicket :: ([Int], [Int]) -> Int
scoreTicket (winners, numbers) = scoreWins . length
$ filter (`elem` winners) numbers
solveP1 :: [Text] -> Int
solveP1 = sum . map (scoreTicket . parse)
--
-- Part 2
--
--
-- Examples
--
example :: [Text]
example =
[ "Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53"
, "Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19"
, "Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1"
, "Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83"
, "Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36"
, "Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11"
]

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,100 @@
Game 1: 8 green; 5 green, 6 blue, 1 red; 2 green, 1 blue, 4 red; 10 green, 1 red, 2 blue; 2 blue, 3 red
Game 2: 10 blue, 12 red; 8 red; 7 green, 5 red, 7 blue
Game 3: 1 red, 15 blue, 3 green; 8 blue, 2 red, 4 green; 2 red, 5 green, 9 blue
Game 4: 8 green, 4 blue, 1 red; 3 green; 4 blue, 1 red, 12 green; 5 green, 1 red, 8 blue; 3 green, 5 blue, 1 red
Game 5: 2 green, 8 blue; 7 blue, 4 green; 7 blue; 5 blue; 5 green, 2 blue, 1 red
Game 6: 6 blue, 3 green; 18 green, 8 blue; 9 green, 4 blue; 4 blue, 2 red, 3 green
Game 7: 15 red, 12 blue, 15 green; 12 blue, 18 green; 9 blue, 11 red; 16 green, 6 blue, 18 red; 6 blue, 12 red; 14 red, 18 green, 12 blue
Game 8: 6 red, 13 blue, 3 green; 18 blue; 3 green, 8 red
Game 9: 3 blue, 4 red; 8 red, 2 blue; 4 green, 8 red, 3 blue; 6 red, 1 blue; 16 green, 2 red, 2 blue
Game 10: 3 red, 7 blue, 2 green; 1 green, 15 red, 5 blue; 1 red, 5 blue; 3 blue, 4 green
Game 11: 12 green, 3 blue; 3 red; 1 red, 6 blue, 9 green; 7 blue, 1 red, 13 green; 1 blue, 5 green, 4 red; 18 green, 3 red
Game 12: 9 green, 13 blue; 3 red, 4 blue, 4 green; 10 green, 7 red, 5 blue; 9 red, 12 blue, 3 green
Game 13: 15 red, 18 blue, 10 green; 11 red, 3 green, 4 blue; 2 green, 12 blue, 4 red
Game 14: 12 blue, 6 red; 2 blue, 7 green, 6 red; 12 blue, 7 green; 4 blue, 1 green, 4 red; 9 green, 12 blue; 3 red, 5 green, 8 blue
Game 15: 9 green, 1 blue; 14 green, 4 red, 1 blue; 1 blue, 6 green, 2 red; 7 red, 13 green, 2 blue; 4 red, 9 green; 2 green, 1 blue, 2 red
Game 16: 3 blue, 2 green, 5 red; 4 green, 3 blue, 4 red; 6 red, 5 blue, 2 green; 3 red, 11 blue; 6 green, 15 blue, 4 red
Game 17: 15 blue, 3 green, 2 red; 2 green, 2 red, 15 blue; 1 red, 1 blue, 7 green
Game 18: 2 blue, 9 red; 12 red, 1 green, 6 blue; 5 red, 5 blue, 2 green
Game 19: 3 red, 4 green, 8 blue; 10 red, 8 green, 1 blue; 13 blue, 7 green, 10 red; 6 red, 1 green, 11 blue; 9 green, 7 blue, 10 red; 7 blue, 7 red
Game 20: 8 blue, 4 green, 14 red; 4 green, 16 red, 1 blue; 10 blue, 14 red, 8 green; 4 green, 13 blue, 20 red; 5 blue, 5 green, 1 red
Game 21: 4 green, 10 blue, 5 red; 11 blue, 4 green, 1 red; 3 blue, 3 red, 2 green; 1 red, 11 blue, 6 green; 1 green, 9 blue, 5 red; 7 blue, 5 green
Game 22: 3 green, 7 blue, 6 red; 12 red, 11 blue, 2 green; 1 blue, 1 green, 15 red; 6 blue, 1 green, 8 red; 4 blue, 1 red; 2 blue, 1 green, 5 red
Game 23: 2 blue, 5 green, 13 red; 1 green, 5 blue, 16 red; 6 blue, 9 green, 9 red; 7 green, 3 blue
Game 24: 2 green; 2 red, 7 blue, 17 green; 5 red, 6 blue, 13 green; 1 green, 6 blue; 2 green, 4 red, 2 blue; 4 blue, 2 green
Game 25: 2 green, 5 blue, 9 red; 2 green, 8 red, 5 blue; 3 green, 1 red, 19 blue
Game 26: 3 green, 2 blue, 8 red; 4 red, 2 blue; 11 red, 3 green; 9 red, 3 green, 6 blue; 10 red, 1 green, 2 blue; 4 blue, 4 green, 14 red
Game 27: 1 green, 4 red, 7 blue; 13 red; 17 red
Game 28: 5 red, 17 green, 15 blue; 7 blue; 7 red, 12 green, 10 blue; 5 red, 11 blue, 3 green
Game 29: 4 blue, 9 red, 9 green; 2 green, 10 red, 2 blue; 3 red, 4 blue, 6 green; 2 green, 17 red, 1 blue; 2 red, 7 green, 1 blue
Game 30: 16 red, 5 blue, 11 green; 5 blue, 5 green, 9 red; 7 green, 1 red, 6 blue
Game 31: 3 green, 11 blue; 5 green; 8 green, 13 blue; 4 red, 10 blue, 8 green
Game 32: 11 blue, 5 green, 4 red; 7 blue; 1 red, 1 green, 7 blue; 7 red, 1 blue, 4 green
Game 33: 7 red, 3 green, 6 blue; 2 red, 16 green, 5 blue; 1 blue, 2 red, 8 green
Game 34: 1 blue, 1 red, 1 green; 9 red, 6 green; 2 blue, 8 red, 6 green; 1 blue, 12 green, 13 red
Game 35: 10 red, 9 green; 1 red, 4 blue, 4 green; 7 blue, 3 green, 4 red
Game 36: 5 red, 6 green, 4 blue; 9 green, 1 red; 12 red, 12 green, 4 blue; 3 red; 18 green, 5 red, 4 blue
Game 37: 10 green, 4 blue, 2 red; 1 red, 3 blue, 9 green; 5 blue, 4 green, 1 red; 6 green, 12 blue; 7 green, 1 red, 13 blue; 9 green, 20 blue, 2 red
Game 38: 9 blue, 20 red, 2 green; 3 blue, 6 green, 19 red; 10 green, 8 red, 2 blue; 4 blue, 4 red, 3 green
Game 39: 4 green, 2 blue, 4 red; 16 blue, 1 red, 2 green; 13 red, 2 green; 16 blue, 7 red, 3 green
Game 40: 8 blue, 2 green, 2 red; 7 blue, 2 red, 1 green; 8 green, 12 blue, 2 red; 2 red, 3 blue, 8 green
Game 41: 9 blue, 2 green; 10 blue, 3 green; 1 green, 9 blue, 3 red; 3 blue, 3 green; 12 blue, 1 red; 3 blue, 1 green, 1 red
Game 42: 1 blue, 1 green, 8 red; 1 blue, 1 red; 2 red, 1 green
Game 43: 5 red, 2 green, 8 blue; 11 blue, 10 green, 1 red; 11 blue, 7 red
Game 44: 9 red, 3 green; 9 red, 1 blue, 6 green; 14 red, 5 green; 4 red, 2 green, 1 blue
Game 45: 5 blue, 1 red, 1 green; 5 blue, 1 red; 6 blue; 10 blue, 1 green; 1 red
Game 46: 4 green, 8 blue, 13 red; 12 green, 11 blue, 12 red; 1 green, 13 red, 1 blue; 12 red, 8 green, 12 blue
Game 47: 1 green, 16 blue, 15 red; 1 blue; 18 red, 10 blue, 9 green; 17 blue, 16 red, 5 green; 2 red, 3 blue, 9 green
Game 48: 2 blue, 4 green; 7 blue, 3 red, 2 green; 17 blue, 13 red; 2 red, 1 green, 9 blue; 2 red, 14 blue
Game 49: 6 red, 2 blue, 3 green; 1 green, 4 blue, 7 red; 5 red, 8 green, 6 blue; 1 red, 9 green
Game 50: 18 red, 4 blue; 6 blue, 3 green, 13 red; 1 green, 7 red, 6 blue
Game 51: 10 blue, 1 green, 9 red; 3 green, 6 blue, 8 red; 4 red, 2 green, 12 blue
Game 52: 7 blue, 1 red, 8 green; 2 red, 9 blue, 8 green; 16 blue, 7 green; 1 red, 11 green, 8 blue; 2 red, 20 blue
Game 53: 8 green, 15 red, 4 blue; 5 green, 13 blue; 6 blue, 6 green, 15 red; 12 blue, 2 green, 2 red
Game 54: 3 green, 5 red, 1 blue; 1 blue, 6 green, 2 red; 4 green, 3 red
Game 55: 12 green, 8 red, 3 blue; 6 blue, 2 red, 7 green; 4 blue, 13 red, 11 green; 12 green, 9 blue, 7 red; 10 red, 6 blue, 3 green
Game 56: 6 red, 1 green, 2 blue; 1 red, 1 green, 3 blue; 12 red, 4 blue, 4 green; 3 green, 5 blue, 1 red; 5 blue, 3 green, 2 red; 1 green, 5 red, 7 blue
Game 57: 1 blue, 1 green, 3 red; 10 red, 6 green, 1 blue; 4 red, 4 green, 2 blue; 7 green, 2 blue, 1 red
Game 58: 5 green, 2 blue, 4 red; 2 red, 2 blue; 5 red, 3 green; 3 blue, 5 green; 6 red, 2 green, 2 blue; 7 red, 3 blue, 5 green
Game 59: 14 red, 9 green; 11 red, 2 blue, 5 green; 18 red, 2 blue, 4 green
Game 60: 16 red, 9 green, 2 blue; 8 green, 17 red; 3 blue, 5 green, 14 red
Game 61: 12 red, 17 blue, 18 green; 1 green, 1 blue; 1 blue, 4 green, 6 red
Game 62: 2 blue, 5 green, 3 red; 1 blue, 7 green, 6 red; 8 blue, 1 red; 4 blue, 5 red, 12 green; 15 blue, 3 green, 1 red
Game 63: 2 blue, 2 red, 1 green; 5 red, 10 blue, 4 green; 4 green, 5 blue, 8 red
Game 64: 2 blue, 14 green; 9 green, 5 red; 7 red, 3 blue, 10 green; 14 green, 2 blue, 5 red
Game 65: 4 green, 7 blue, 1 red; 3 red, 2 green, 7 blue; 5 blue, 2 red, 1 green; 6 blue, 2 green; 7 blue
Game 66: 9 red, 2 green, 5 blue; 5 blue; 8 blue, 5 green, 11 red; 17 blue, 3 green, 14 red; 2 green, 9 blue; 11 red, 4 blue
Game 67: 2 green, 7 red, 8 blue; 6 red, 4 green; 1 red, 3 green, 7 blue; 7 blue, 7 red, 4 green; 2 red, 1 green; 3 green, 6 red, 2 blue
Game 68: 4 red, 2 blue, 5 green; 5 blue, 8 red, 2 green; 11 red, 2 green, 4 blue; 7 red, 5 blue, 3 green
Game 69: 8 blue, 1 green, 4 red; 3 red, 11 blue, 9 green; 12 blue, 10 green; 1 red, 15 blue, 7 green
Game 70: 13 blue, 1 green, 8 red; 15 blue, 10 red; 10 blue, 17 red; 15 red, 4 green, 6 blue; 11 red, 1 blue, 2 green; 14 red, 4 green, 4 blue
Game 71: 1 red, 10 blue; 1 green, 12 blue, 2 red; 4 red, 4 green, 8 blue
Game 72: 2 green, 6 red, 1 blue; 7 red, 4 green, 4 blue; 7 red, 4 blue, 7 green; 7 green, 3 blue; 10 green, 9 blue, 8 red; 5 red, 2 green, 8 blue
Game 73: 8 blue, 2 green, 9 red; 2 green, 10 red, 6 blue; 3 blue, 6 green, 2 red
Game 74: 2 blue, 10 green, 7 red; 4 blue, 13 red, 3 green; 11 green, 3 red, 4 blue
Game 75: 14 green, 1 red, 7 blue; 15 blue, 11 green, 1 red; 11 green, 15 blue, 6 red
Game 76: 7 green, 7 red, 2 blue; 4 blue, 18 red, 9 green; 12 red, 4 blue, 1 green
Game 77: 3 blue, 1 green, 12 red; 10 green, 13 red, 7 blue; 7 green, 12 red; 6 blue, 10 red; 5 blue, 3 green, 17 red; 3 green, 5 blue, 13 red
Game 78: 11 red, 9 blue; 2 red, 7 blue; 12 red, 7 blue, 3 green; 3 green, 8 red, 9 blue; 1 green, 5 red, 6 blue
Game 79: 6 red, 12 blue; 5 red, 4 green, 11 blue; 13 blue, 2 green, 3 red
Game 80: 7 red, 6 blue; 2 green, 7 red, 6 blue; 5 blue, 6 red, 2 green; 1 green, 7 red, 2 blue; 4 green, 6 blue, 7 red; 1 green, 6 red, 10 blue
Game 81: 10 blue, 7 green, 3 red; 7 green, 3 red, 16 blue; 18 blue, 3 red, 7 green
Game 82: 7 red, 5 blue, 9 green; 7 blue, 8 green, 11 red; 1 blue, 1 green, 10 red; 5 red, 8 blue, 7 green; 6 red, 10 green, 2 blue; 3 blue, 5 green, 10 red
Game 83: 2 red, 2 green, 1 blue; 2 green, 2 red; 6 red, 1 green; 8 red, 1 blue, 1 green; 1 red, 1 green; 3 red
Game 84: 9 red, 4 green; 1 red, 13 green, 2 blue; 2 green, 15 red, 2 blue
Game 85: 2 green, 4 red; 1 blue; 2 green, 4 red, 1 blue
Game 86: 2 green, 10 red, 3 blue; 3 red, 5 blue; 3 green, 2 blue, 8 red; 1 blue, 5 red, 2 green
Game 87: 19 green, 9 blue, 7 red; 12 red, 15 green; 4 blue, 8 green; 6 green, 3 red, 11 blue; 16 green, 4 blue, 11 red; 10 red, 4 blue, 9 green
Game 88: 6 red, 2 green; 10 red, 4 green, 4 blue; 1 blue, 8 red, 12 green; 7 green, 2 blue, 12 red; 1 green, 5 blue, 16 red; 10 red, 5 blue
Game 89: 1 red, 14 blue, 1 green; 1 red, 12 blue, 8 green; 2 red, 13 blue, 11 green; 8 blue, 4 red, 16 green; 4 red, 5 blue; 6 blue, 1 red, 1 green
Game 90: 3 blue, 9 green, 5 red; 4 green, 6 red, 1 blue; 2 blue, 12 green, 5 red; 1 green, 1 blue, 3 red; 5 red, 3 green
Game 91: 8 green, 3 blue, 8 red; 8 green, 4 blue, 4 red; 5 red, 1 green
Game 92: 1 green, 9 red; 1 red, 4 blue; 9 red, 2 green; 3 red, 1 blue
Game 93: 1 red, 16 green, 5 blue; 1 red, 1 green, 4 blue; 4 blue, 6 red, 13 green
Game 94: 9 red, 9 blue, 3 green; 5 green, 11 blue, 1 red; 3 red, 6 blue
Game 95: 2 green, 4 blue; 8 green, 2 blue, 12 red; 10 red, 9 green; 4 red, 2 blue, 4 green; 8 blue, 7 green, 14 red; 1 blue, 4 red, 8 green
Game 96: 12 red, 2 blue, 8 green; 6 green, 6 red; 7 blue, 8 green, 6 red; 14 red, 8 green; 2 blue, 4 green, 10 red; 6 green, 7 blue, 7 red
Game 97: 4 green, 12 red, 2 blue; 8 blue, 3 red, 3 green; 2 blue, 2 red, 7 green; 17 blue, 1 green, 7 red; 19 blue, 1 red, 6 green; 6 green, 7 red, 9 blue
Game 98: 13 red, 15 green, 14 blue; 6 blue, 1 green; 14 blue, 12 red, 1 green
Game 99: 1 green, 11 red, 12 blue; 7 red, 20 blue, 1 green; 5 blue, 5 red; 6 blue, 4 red; 1 blue, 1 green; 6 red, 8 blue
Game 100: 2 red, 9 green, 11 blue; 13 blue, 4 red, 16 green; 8 green, 13 blue; 10 green, 1 red, 12 blue

View File

@@ -0,0 +1,140 @@
...317..........214.....................................751.................................630...479..205....41.993............416.........
...*....813........%....572........%...629.154......518....*....365..................-.......*.......#.....................422...........661
269.......*...58...........=......264.....*..........*......937.-...........235...303.........848..............195.....154*.........144.-...
........476..@...162.855................$....288...821..............107.....-...........290......../..301.........=...........135..*........
618.............=....*...547...........441....*........................@................*........851....+...................+..*...102.310..
...*961....905......534..$...377...............854...341.342....485.......109....89.995..927..............................90..997......*....
............*...................*.................../.....*......@...........%....*...*.......................+44.....913.........9.....891.
....62......724...592....946.878...854....$.701............480......575.246....119.....54..296.906..684..................*.........*838.....
.................+......*...............478....................469.....*..................*...........+..502..156.........821...........983.
....................315.764..996..571...............=........................804.......&...892....958.....*......*.............61...........
........+...697*.....+.........*...*...........@.448........................*.......322.............*....309..37.602.....775....*...........
32.480..665.....557......+...435..449..691..327....................#....921..535..........755...43...597........................322..7......
......*.....848.........745.............*.......679/............106.......&........404......+....*...................888..750........*......
......93...*....=.............*297......550...........324.597............................................819.....997*......-...734$..588....
.........363..112..754...............&..........723....................14..954.............175....773...*.............&.....................
..................*.......#..........502......../...............606.........@..778*.......#.........*....844...713...743....-.........&.....
............827.895.-539...469...938...../.248.....................*.49............749.............783.........$...+.........33....471......
..............*.................../...517...&......368*710......432...*............................................841.=.................194
.....*491....395.......&481.................../.#...................83................668..181.....698..155*...........981.200..............
...................219.................196.473..224.....=.....733*.......=.........98*.......*.420..........671.....*......*......369.205...
........@......696*....669.....50.....................853.593.........168....@.............802..*...388............3......792........*......
......641............./....62..*...836#.......*169.........@...............872.................416....*.................-...................
..........................#...377..........179.......101........+504.................*554.............947..............447.............830..
243........*902.....#................480*...........+.....*258.........*243.......389.......&....................723.........838...991......
........182.........33..........840......616.733.......756..........290.....................145..119..........................+......&......
..............................................*....807...................777......+..556............@....85#................................
.212.664..3......316..579..462..............435.......*............@....*........36...$........572................703..732........@.........
...........=....@.....*.....*............*.......-..337......656...411.357.373.....................*21....37.........%./.....918...185.387..
...350.................338...161.856..157.906...527...........*............+.........*336.......204............755.............*............
....&...........683...................................801......313............831.230......374.......................383.....940.48.........
...............*........447......635....335......%.........627........44@..........................895....................@.................
....$....958..943.......#...935.%..........*...794......16.*..................+...........100..469........743.*.........529....=.......883..
..308.....*........*776.......*.....*....430............*..562.......895......765.................*.........*..776..........246..921&.......
.........200...............*..1....572................814...........$......#..........138...&....487..668..58.......485.....................
...*845.............935...958.................................667.....%.121.......691.......245.........*..............*........131.........
.........*............*.............=............................*.593.............*..................380........189...219.211......@.......
.....152..783........634...........521.+.......26.............659...............328...%.............................*........$......397.*...
......*.......124..........299..........808.....*........359................424.....%..454..........553.............49..562.....257......723
......641.........24.............576.............975........=..............*.......974.............*...........146......*......../...@......
940.........&....@....221........*.........149.......&...............689....418...........538...................*.....985............526....
.............192.........*816...582...561..+..........915..981%.......*..................*......&8....+.........497..........145............
.........144........$....................@......................425.933....846*824.$...370.342*....375...641..=........927.....*.......160..
............$.......925...67.655....57.............=905..881....@..................585.........746.............224..........224...864...*...
.....872................#..*...$.....*.........#............*...........979....699...................947.........................*.....788..
............949......676..42........340.....694...144......712..296..45...*.......*..............191.@.......889-......=786.....417.........
...........*.................846....................*..160.......*.......403.....347...914.91...=...........................................
.371.=....904.643......816...*...647...$.858.......431..........486..........706......*....-..............961........................698....
......398.....*....252*....591..../..224...$..341...........#................*................956............*...27..............57.....*534
.............363...............................&.............69........163.233.580....113*367..............44...*..................*406.....
...893..457..........91%........................................538.....$......*..............................475....864.......289..........
..........-........................549............909..572.....-..............385.............97.....................=.....159..*...........
...174...............................*...576.875....*.....=...................................*....506..115...............*....856....408...
.....=.......685....58........177.965...-.....*....489......402/..&603.....................357......=..&....84.....451&.810........93...*...
.....................*...87.........................................................447........@............*................-......*...117.
......205.593........298..................................622....955.......34*325......*....965...................604......729....509.......
........=..*.......+...............966.......................$.$...................206......................99....-....424..............$...
378..........636..141.543%....34...........437-.................303.........80....*.............915...........*........*...885...........148
............*................=......................39......-.......208.560*...906...................320.860.975....532....*.........740....
....834...13...................426.395*962...44.......-......552...................*539.+........953.......%............647.........*.......
..............589...............*..........................................179...71.....207........#.577......758...247..........958........
....930.......*......&139...820.56.....%164....................536.=31......*.............................................89................
.....#.........569............*.............882....296......&................465.......21............=.....331........998*..................
..........847..............206....$............%.....#.464.318..=.....751*........................501..971...*..............227.......854...
.466......*......768..../.......110......................*.......612......551......868.......727.......*......39.850..-.....*.........*.....
.........377.561....&.718...94............246..........159...........255............%.........*...........445........472...520.......304.472
...............*..........................@.....292.............................476......&.........135......*...223.........................
..............288.....................944........*......775*934................+......152.............*55..806............239#..............
...181*552...............................*....238...............499...880.476...................................417.#66.........472.........
.....................*........%...629.853............*......@9...@......=.....443...673........271...*..........-...........98..............
.........567*288...10.257..837......*.........862..14................21......*...................%..714...........963.........%.450....528..
....................................862..................889.....604...*424..350...812..34........................*...646...................
...............*....*933.....355@..................*528....=......................+.....*...&996..493.....992..840.......*..271.............
..............984...............................678.................+571.....648......262............*......*..............*......293..197..
..........386..............463..984......129................-588..............*..361...............408..269.652...........406........*..+...
.........*............494....*.......847...*..#..942..825.............&......32.........................*........427...........-....339.....
.......415.=434..439.....*..23........$..34..410.........+.......746.976.............731..../.1*.........709.......*.........197........#...
................*......493.......760.............................................654*....398.........158....../......396.............922....
.....845.=....955...................*.....*574....954*........@...........$.......................-....*.....796......-...426...$732........
.......*.88.............@.........738..924............213...40....115......315...................299...108...................*.......320....
....567...............%..13.................*14...........$.......@.....%.........../...518.......................-.810...514..952..........
........892...275....485.......820.......367.......@.....544...........428.........54..-.............*....108..964...*..........*...........
.......@...................861......#.........893.116.........836.982......961.............../...615.188.....*.....914.........761....765...
...........169.962.........*......81...769...#...............................-..714.424..759.390...@.........855...........562.........*....
....../906......../......81..968.......-..............................185..............*.%............=......................*.205.....72...
................*............*....110........./.907....241.......708...*...383.701..869...............346..............649.771.#............
.............531.976...670...288...........382....*.......*116.........820.-...*............764..556...........@..984....$.......638...165..
........................-..........479.............55..........................515.....345...#................533...*.......................
.....$....569.936.301.........914..*.......-.....=................453..............209..*..........................551.-.......479..........
..233.....*......*.....506.........931..246....221.639....#..................@......*....784........591.................818...%.......523...
.......233....%.........................................416...714&........448.......698......387........432............................*....
...........718.......@......465....................430........................603.......491..*..........*...22.164...+...............179....
...............450.462.549.=....283.185...880......................652.......................142..430.372.....*.......633...................
.370....143....*.........*.........*......*.....962...........*.....*....................537........%...........&136........................
.....39.......956......213...........476.143.......*.......321.60....708..........966.......#...921......+146............+...665............
...........................941...321*.............880.499...........................*.............*.383........668.....212...*....827*428...
..236..527...................=..........................*........../..854......................489...-........................234...........
.....*.................................622..........289..599....207...*............&953.599=...............885............682.....914.....12
793...754.............$497..............*............*................163....................+.........15.....*..*....338*..................
...*.......864................348..........758.......439...................1........83....748...............325.535...................=.....
...368....*........382*250....*.....317.......*................473*....877.+.........*..................@................%....331..513......
.........55..239...........2...377...=......1.792...294*607........831..........*.950...&....-....#....864.....139.......512................
....427.......*...*...#....%...........765...............................418.995.........6..492.465...........@....................*218.....
......*......939.410.371......#...-......#.................&............*.............................496..........503..........629.........
.....410....................215.193.................678.786.....370...71..598......329..........262.................*.......473.............
.........979..855..432=................212.....346..*....................*........*............#...................249...=.....+...525.217..
.........*....*...............387.....*...........*.228......./....%....245..&.....690.....429............................685.........*.....
129....907.423........949.772......666....173..679........992.313...398......427..............*...................244.......................
.........................*.....*............................*........................../....998..........510..825*..........................
.....132....867........%.....42.780..............776*744...898.......664....196....360..823......899.211..=.................+...............
.....*.......%......703................916...%...............................*....*................*....&.....689..$......591.......64*238..
...684..160.......................445.....*...164.......602....249...........431.12.............=..758............138..........983..........
..........@..766.92..............*......334........671..*...............&646..................797.............950.........935.........469...
................*..................510..............*..285..........................................650.......*....807...*............#.....
..205.669...768...88........................+59..148............682........#.................3..............376...*.......191...............
.........&....*..%........................................183......*......61................/........657..........163............255........
..674.......46..............392..251....507.................*.248...74..........+...775.97.....222.........%..........135...950.....*.......
....*...........*967..533...*............*......949..245.276...#.........*.....728...................677..137.....*.....*..&........522.....
...367.......196.......$..239..........510.748..*............/...481..722....................800........*........735..268...................
.........442...................111...............752........567...*.........*..........696..%............790................................
.............182....677..613............................/..........814...372.86........*......915*..............799.................*....253
....&....739*........../....*206.........284...........584...427................727..485..........781.992.........-...............619.......
.....603.........................907........*....607......../.............................617............*...=.......986-.............918...
.........819..667..341...........*....#..397................................#........$..................822...20...........359.....43.......
.......&....*...#....*.......*....88.691.........................700.675....910...227........350...&591............301.......$.......*......
..404$..259.......557....876.218...........216.=211.7...=569........*........................=.................320..*....462...480....747...
..........................+.............#..*........*.................=518........................274............@...276........../.........
.......#...904......622..............923....543....969../..................571..778......#888.253..................+.....163.........-679...
295.207.........708......................................942...496....#...*.......*.373@.......*..645...............580.......177...........
................................982*317............304........*.......28.823....994.......370..96........@.=...*675............*.....604....
644.138.522......%......901.................374*..*.........458.....................#135....=..........730.355........955...=.47.277*.......
...*....*.........288..*.............+.433.........240.................317/........................609............#90.*...623...............
.....%..675....87.......110...126.408..*......355.............................@131......110....778...*..519.834.......537.....19........502.
..831............*460........*..........824.....*..751...467.829..........850..........*............365....*................................
..........398..............473....-..........751.....*......*................@.446*....780...........................732....................
.......................#.........333..................170........596...............943......66..186......@...........@.....=................
......124....780.....58.....933........926.../.............693...*..........*828...............*........666.............=..337..............
.......*.........197..........$.......*......67............-...335...........................122...582................197..........328......
.....151...............................763......180....@............890../....835...578..871..........*295..#....%...........-541.$.........
........................153.........-........@.....*...661..*833......*.775.....-...........................40....665...............701.....
..890....252......................544........809..425..............925......................................................................

View File

@@ -0,0 +1,192 @@
Card 1: 26 36 90 2 75 32 3 21 59 18 | 47 97 83 82 43 7 61 73 57 2 67 31 69 11 44 38 23 52 10 21 45 36 86 49 14
Card 2: 45 10 54 17 15 38 59 96 25 32 | 17 12 77 87 29 70 38 96 15 54 86 64 32 10 28 59 24 45 65 81 42 25 98 14 60
Card 3: 37 31 21 71 80 76 91 77 64 69 | 90 71 91 13 2 40 83 22 45 31 69 53 77 27 97 35 4 55 14 9 52 21 16 19 63
Card 4: 16 82 44 42 51 11 86 14 92 47 | 44 61 81 88 15 11 76 42 17 98 48 83 14 92 99 16 82 86 56 47 10 66 13 22 51
Card 5: 83 84 64 81 97 88 96 59 92 25 | 52 65 98 86 75 48 96 60 56 33 76 81 29 44 97 82 59 64 88 25 23 92 37 84 83
Card 6: 50 51 91 86 25 44 75 23 5 56 | 86 17 56 16 91 75 27 94 39 80 25 71 23 26 12 31 43 45 5 18 50 44 96 51 57
Card 7: 34 14 63 33 87 92 69 67 24 13 | 86 47 31 45 3 32 81 96 21 93 80 25 90 63 79 6 49 91 7 95 62 66 19 24 76
Card 8: 19 67 63 77 62 92 51 49 52 1 | 35 1 94 87 11 82 12 84 49 28 39 96 92 23 34 4 56 5 63 13 77 47 14 9 78
Card 9: 54 14 61 36 10 35 92 34 47 95 | 87 92 95 54 3 47 15 36 90 11 9 84 10 75 45 72 61 88 14 64 35 34 98 46 76
Card 10: 27 59 55 95 4 99 8 48 97 6 | 51 50 48 91 34 4 97 86 27 99 20 95 17 6 80 43 21 60 28 10 89 59 73 55 8
Card 11: 74 46 96 17 62 65 38 4 29 6 | 48 83 42 4 17 35 1 38 6 74 40 95 80 49 46 29 65 62 85 47 96 18 76 36 68
Card 12: 68 12 22 46 33 57 61 86 13 62 | 62 35 20 7 16 78 60 11 9 31 46 34 73 68 77 36 61 66 65 14 26 83 98 95 69
Card 13: 50 14 10 3 83 27 52 84 61 44 | 75 22 56 60 62 36 87 33 85 52 7 95 19 81 10 47 20 73 50 13 46 3 83 37 84
Card 14: 51 42 40 21 29 78 10 31 54 24 | 78 67 10 17 54 99 1 87 8 66 23 56 5 63 92 50 71 47 98 3 73 16 74 42 85
Card 15: 65 68 76 6 40 78 11 60 55 84 | 39 40 59 43 55 69 72 14 94 66 20 80 11 93 64 68 96 34 38 84 67 41 53 89 88
Card 16: 77 95 61 17 74 46 54 3 37 81 | 3 14 41 73 12 75 31 71 24 26 92 74 64 98 89 95 93 19 15 82 91 30 66 81 40
Card 17: 87 11 32 58 43 99 7 79 37 82 | 70 14 67 68 18 29 54 12 15 17 34 71 84 74 4 36 98 42 24 23 38 97 79 81 83
Card 18: 2 70 93 86 50 39 15 76 64 8 | 76 42 75 67 14 39 15 64 45 10 56 12 32 2 93 52 8 68 97 36 79 98 17 37 59
Card 19: 55 53 86 35 88 48 79 56 34 33 | 77 89 45 76 82 23 52 97 62 27 7 38 84 81 99 41 40 70 42 50 21 4 80 12 46
Card 20: 53 21 29 48 42 89 12 34 76 14 | 56 46 69 50 88 85 74 40 66 47 79 77 61 9 67 39 22 63 6 59 54 92 14 51 96
Card 21: 11 87 63 43 5 91 22 45 61 26 | 46 99 43 57 88 75 32 34 91 7 87 15 13 54 66 82 1 10 31 70 24 16 2 90 39
Card 22: 31 89 65 74 38 4 99 40 19 9 | 45 28 54 77 3 42 14 55 41 71 81 84 82 69 64 97 76 48 56 13 23 66 15 30 8
Card 23: 6 59 76 99 9 86 4 84 5 27 | 37 80 51 24 46 72 68 82 89 30 21 55 96 7 91 85 92 93 78 14 70 61 2 11 50
Card 24: 11 37 40 53 70 95 44 3 92 49 | 60 67 54 52 34 93 87 26 74 88 4 91 78 68 17 38 97 7 43 69 64 18 73 15 80
Card 25: 35 52 84 65 30 2 37 89 67 90 | 51 14 25 96 45 4 28 88 8 22 13 66 9 48 82 85 86 54 75 91 1 10 29 5 39
Card 26: 88 84 2 68 47 81 8 11 46 29 | 47 84 98 20 75 63 44 64 15 7 27 53 43 26 68 73 2 91 78 29 46 11 76 8 99
Card 27: 65 94 27 71 54 86 77 47 64 31 | 65 8 27 76 83 64 69 96 78 61 7 11 72 55 41 10 54 93 15 52 90 4 33 94 82
Card 28: 46 89 43 92 93 60 14 34 91 69 | 60 94 46 43 82 53 91 34 92 15 28 55 6 88 57 89 14 67 4 61 36 69 2 93 12
Card 29: 73 54 41 45 29 83 65 70 80 72 | 42 59 6 73 36 87 23 14 47 96 77 72 43 29 70 93 90 50 65 68 56 19 17 63 76
Card 30: 73 18 66 4 96 55 52 59 93 97 | 36 50 90 22 78 96 71 60 87 26 84 74 66 68 55 54 63 73 20 97 10 12 16 76 93
Card 31: 58 42 91 76 86 26 80 5 14 79 | 1 40 4 42 11 13 68 99 10 97 59 76 56 67 5 91 93 26 38 87 80 17 86 33 12
Card 32: 65 29 20 80 13 60 43 18 17 95 | 55 53 72 8 22 45 90 79 81 10 77 5 26 87 52 56 43 30 54 98 93 14 62 74 51
Card 33: 40 81 10 65 18 59 1 68 69 35 | 65 91 69 35 59 48 23 37 33 10 29 11 76 25 55 64 58 9 46 47 83 51 98 68 1
Card 34: 9 87 17 41 81 51 50 20 5 14 | 54 19 81 60 48 90 70 43 44 62 78 3 9 6 87 51 4 47 77 30 82 76 56 13 94
Card 35: 58 71 47 3 59 96 92 30 74 4 | 9 78 30 51 43 82 96 35 48 76 53 52 62 49 4 41 39 93 27 80 87 59 33 34 7
Card 36: 8 45 92 39 66 36 34 69 82 63 | 67 37 24 19 85 46 47 92 74 3 17 97 61 65 83 39 77 34 15 55 75 7 20 28 54
Card 37: 39 59 17 65 89 24 28 87 86 29 | 3 67 73 44 27 68 8 12 32 59 2 50 40 76 62 75 34 5 72 18 52 25 70 90 53
Card 38: 7 91 1 70 12 16 57 78 89 69 | 92 28 56 94 15 44 31 35 51 82 11 52 7 74 62 3 76 93 26 6 19 72 86 30 2
Card 39: 63 43 99 29 91 33 52 96 76 26 | 61 53 42 2 84 73 72 55 49 18 80 34 77 62 43 45 92 50 38 40 89 60 47 69 16
Card 40: 83 91 18 21 48 6 82 85 39 17 | 38 43 7 77 59 40 73 1 49 76 66 64 84 22 53 56 15 42 94 24 2 10 99 70 63
Card 41: 19 74 11 78 71 39 21 58 25 50 | 81 26 33 82 71 58 54 4 19 47 37 73 50 74 99 25 44 39 38 78 21 77 11 88 59
Card 42: 22 15 3 33 62 13 67 18 24 72 | 50 4 86 74 15 38 47 42 89 9 30 87 2 20 33 17 78 45 48 81 62 51 71 35 96
Card 43: 39 42 48 11 23 59 25 54 40 88 | 7 73 32 8 1 60 4 13 14 70 79 3 98 68 76 43 47 6 56 85 92 94 74 62 90
Card 44: 30 16 41 34 89 13 1 53 3 59 | 64 50 55 74 67 78 89 86 63 85 26 28 34 69 59 31 44 56 37 39 20 15 17 71 93
Card 45: 13 57 96 32 69 88 75 15 40 47 | 40 61 32 70 95 29 28 75 87 37 69 57 72 63 15 30 21 38 13 47 20 96 56 76 88
Card 46: 71 28 77 18 39 16 25 1 95 66 | 50 30 39 62 54 25 22 16 24 32 40 41 95 11 64 38 77 14 34 90 86 48 1 4 79
Card 47: 32 31 18 26 43 33 46 39 60 29 | 85 51 41 74 77 14 72 89 65 60 11 92 33 39 18 15 32 95 42 46 94 38 90 68 53
Card 48: 13 47 30 5 40 66 64 51 60 83 | 13 30 84 83 43 40 46 5 98 47 91 86 4 66 23 96 10 92 51 60 93 64 36 71 53
Card 49: 72 99 94 27 31 49 75 36 66 82 | 95 4 14 11 36 89 19 45 50 84 24 72 99 90 82 71 56 16 20 58 39 83 75 49 22
Card 50: 25 81 56 1 64 50 80 79 87 23 | 98 19 25 22 50 24 74 29 51 1 54 39 80 28 23 87 75 56 93 89 55 71 3 65 79
Card 51: 81 10 35 77 13 47 90 24 79 97 | 14 32 77 85 58 17 30 89 8 51 13 76 80 94 79 56 65 43 11 5 19 47 70 90 81
Card 52: 14 34 90 39 44 26 95 17 19 20 | 80 78 93 16 67 15 68 36 98 1 35 45 10 86 65 61 47 26 82 9 69 83 81 23 48
Card 53: 55 75 8 44 62 30 19 97 65 12 | 77 96 15 42 86 84 70 24 68 11 97 69 16 56 66 13 73 74 46 67 2 88 63 50 98
Card 54: 2 69 28 76 77 6 86 74 32 38 | 83 96 73 79 71 8 4 46 63 49 65 16 84 75 26 50 61 37 17 39 36 47 58 14 91
Card 55: 41 89 46 60 37 82 69 52 35 72 | 16 56 63 34 45 59 37 1 29 46 51 75 99 90 76 7 60 57 5 98 62 20 93 50 44
Card 56: 27 11 5 14 81 18 33 36 96 69 | 67 61 6 28 77 63 74 44 60 29 54 93 94 40 83 20 97 66 52 87 2 79 32 1 70
Card 57: 30 91 94 56 18 73 32 88 51 84 | 62 45 54 7 53 96 29 43 3 81 91 80 24 14 46 65 89 4 92 50 71 35 49 47 86
Card 58: 47 55 32 62 21 25 69 60 14 41 | 98 87 10 84 89 4 28 96 72 35 66 31 95 91 76 3 52 45 81 24 97 8 1 27 67
Card 59: 34 10 7 40 92 72 4 44 98 23 | 50 92 98 10 4 17 34 44 65 74 21 64 6 23 40 72 79 86 59 27 7 91 47 63 16
Card 60: 75 7 58 65 17 14 50 8 69 20 | 96 25 69 20 75 50 7 8 64 31 14 17 24 65 93 19 40 62 53 90 34 58 74 85 51
Card 61: 40 93 9 39 71 44 36 80 87 90 | 87 27 25 39 26 36 97 82 79 93 44 15 31 20 2 61 90 55 40 74 1 80 7 95 49
Card 62: 78 91 53 31 29 93 98 99 46 43 | 59 53 28 70 31 37 99 1 82 46 44 60 17 61 43 29 98 93 91 8 42 6 78 32 23
Card 63: 36 20 89 67 86 17 50 29 49 12 | 43 99 83 28 29 94 50 76 82 51 40 47 97 30 20 78 49 72 6 57 46 67 75 68 86
Card 64: 69 24 34 10 2 14 86 38 76 5 | 70 38 34 99 64 10 75 82 58 72 5 2 83 76 9 15 42 81 86 24 59 74 18 69 14
Card 65: 33 69 2 45 25 40 35 48 83 53 | 64 40 33 48 63 96 2 22 53 97 43 69 83 79 20 5 35 9 25 29 74 47 72 99 45
Card 66: 93 1 92 57 71 23 85 51 13 88 | 10 27 92 6 65 28 33 67 53 58 38 13 40 69 90 97 24 50 36 85 54 91 94 30 21
Card 67: 82 25 87 96 97 55 35 90 68 93 | 40 74 21 45 59 82 16 67 79 36 32 28 12 73 81 60 84 54 77 29 7 58 86 34 3
Card 68: 13 22 75 87 19 67 29 51 80 17 | 91 87 16 98 52 24 43 34 19 80 23 21 99 44 27 13 60 42 17 79 67 14 1 31 3
Card 69: 50 35 32 17 92 40 88 41 91 77 | 71 17 41 23 26 5 92 29 55 91 40 83 88 65 51 9 50 53 77 46 54 35 62 32 52
Card 70: 56 61 5 90 8 15 6 46 10 98 | 10 55 82 56 30 72 78 13 91 95 49 6 93 27 74 85 64 62 70 8 9 54 57 45 90
Card 71: 76 2 26 66 56 41 72 70 61 94 | 88 32 97 68 83 37 76 41 36 86 3 84 44 9 24 69 5 95 7 50 35 1 27 77 46
Card 72: 82 38 71 98 60 55 29 73 4 1 | 83 92 69 85 64 97 35 33 20 87 81 71 57 75 66 82 29 19 63 36 23 58 60 93 72
Card 73: 74 70 33 43 58 5 47 18 98 59 | 77 81 75 64 69 92 20 2 1 28 40 32 7 12 57 31 68 36 45 46 61 97 39 66 63
Card 74: 85 6 64 88 46 86 4 25 12 17 | 11 49 38 40 36 46 23 62 84 48 12 60 76 75 9 10 90 35 26 37 69 89 4 17 43
Card 75: 71 52 55 35 87 86 60 27 32 89 | 35 30 73 10 89 98 4 69 22 9 23 17 71 53 87 83 48 86 74 40 21 62 63 85 50
Card 76: 75 66 33 41 3 25 99 98 37 91 | 35 38 12 11 46 40 20 15 94 61 47 79 10 83 24 50 51 2 48 26 63 13 72 4 88
Card 77: 78 8 62 30 92 18 76 36 84 91 | 4 26 82 15 92 94 13 48 33 49 46 60 74 58 81 67 10 2 9 23 70 6 57 53 79
Card 78: 56 55 32 44 13 84 95 85 20 92 | 7 17 87 86 16 60 70 65 74 12 4 18 95 8 19 54 15 6 94 84 82 58 59 28 99
Card 79: 16 14 42 27 10 49 89 65 91 76 | 68 70 1 61 81 71 32 40 51 41 36 31 45 33 18 94 17 2 60 76 74 6 62 79 11
Card 80: 56 78 20 15 58 30 49 75 79 66 | 12 52 96 14 80 34 61 7 40 9 17 47 97 6 2 93 39 3 76 42 43 71 33 67 54
Card 81: 75 44 15 74 17 25 51 28 96 67 | 45 69 89 75 8 67 71 70 46 40 15 96 87 20 28 17 21 42 85 68 44 18 74 59 51
Card 82: 74 29 44 13 94 22 40 80 36 27 | 55 51 74 40 77 36 49 87 43 13 46 62 23 38 90 30 39 57 70 1 80 22 91 32 89
Card 83: 87 21 17 14 49 92 19 1 77 36 | 67 36 31 74 87 13 1 21 35 97 99 52 19 92 9 77 51 49 89 72 14 26 56 17 90
Card 84: 2 60 7 46 57 31 68 83 25 5 | 42 72 20 38 88 35 73 98 92 89 41 90 65 81 96 21 50 62 87 36 43 33 8 66 55
Card 85: 38 43 61 78 57 48 82 80 3 26 | 25 17 61 94 50 69 5 26 39 85 76 58 80 8 33 11 55 38 79 60 82 93 84 20 86
Card 86: 17 36 14 77 98 99 33 38 34 4 | 17 97 98 30 38 65 16 43 28 85 77 36 83 88 29 18 60 26 14 33 80 78 99 34 4
Card 87: 42 52 68 76 78 48 36 50 65 44 | 21 23 42 68 13 43 63 36 33 67 8 66 70 90 48 1 65 50 34 7 69 82 76 78 44
Card 88: 68 67 15 30 92 38 96 63 75 44 | 59 30 83 6 48 42 35 28 46 34 92 44 49 78 43 27 47 75 15 33 62 37 3 68 60
Card 89: 12 46 88 26 86 43 52 83 29 92 | 4 29 60 78 25 43 15 74 73 99 83 86 59 27 96 44 38 48 6 37 52 85 42 41 46
Card 90: 95 71 59 29 13 83 90 57 7 94 | 71 19 43 13 68 84 51 29 16 31 45 94 57 92 7 90 20 55 98 36 64 83 59 10 95
Card 91: 16 74 55 79 95 25 84 61 67 14 | 67 44 80 79 62 81 25 84 61 35 72 78 10 93 14 95 16 45 85 66 74 47 8 29 53
Card 92: 41 74 92 35 88 76 9 79 71 53 | 51 88 44 71 81 49 36 97 35 46 33 62 18 9 85 98 79 76 53 47 41 89 92 63 94
Card 93: 71 11 27 69 65 21 23 25 40 81 | 90 96 34 21 11 55 20 76 44 49 60 75 71 98 27 40 58 63 43 81 18 59 33 88 47
Card 94: 4 39 9 70 63 75 14 99 29 25 | 99 77 91 19 30 94 25 26 1 80 73 32 48 10 61 4 7 31 75 39 70 36 63 51 57
Card 95: 30 24 19 73 42 89 47 66 61 13 | 30 86 52 37 61 25 65 33 32 41 44 92 10 95 59 34 93 39 43 14 73 74 82 13 94
Card 96: 51 3 7 37 96 54 9 83 69 95 | 95 61 28 83 69 22 31 54 51 50 25 29 89 27 4 14 49 3 53 6 59 7 21 30 79
Card 97: 67 5 91 27 33 4 99 15 19 85 | 33 84 51 65 15 67 93 47 94 35 80 11 45 86 69 82 55 85 63 12 29 68 76 61 41
Card 98: 60 64 34 61 95 94 36 2 11 75 | 71 60 39 12 11 51 7 88 64 54 5 90 84 50 26 22 42 36 92 53 67 28 76 58 38
Card 99: 40 77 57 46 19 55 28 31 11 70 | 62 12 45 46 49 32 94 93 13 7 29 66 70 99 37 63 30 52 4 84 54 36 2 11 33
Card 100: 15 18 10 32 26 89 17 78 85 64 | 14 54 15 11 75 45 91 83 88 86 60 62 92 8 29 19 58 79 59 31 93 66 55 46 13
Card 101: 15 44 6 92 88 7 24 20 28 83 | 12 41 95 92 61 16 84 29 31 89 85 97 79 63 54 78 60 27 11 64 72 23 94 52 14
Card 102: 87 56 58 2 25 57 85 83 95 24 | 51 42 58 71 44 62 19 43 27 45 9 13 59 28 93 99 8 31 38 65 32 54 48 97 90
Card 103: 32 37 48 65 94 71 83 31 24 80 | 47 76 28 74 99 46 91 78 21 34 40 20 11 35 88 14 16 55 87 97 52 36 56 90 81
Card 104: 5 35 42 73 55 13 59 81 33 9 | 50 12 81 85 35 82 62 13 73 58 93 59 9 80 68 4 18 7 86 5 33 16 55 65 42
Card 105: 44 69 1 73 91 24 94 64 31 77 | 34 77 39 94 41 9 69 52 95 17 31 74 98 73 42 44 67 1 36 50 21 91 35 64 24
Card 106: 49 69 38 10 46 92 35 50 15 93 | 89 69 27 24 10 46 35 32 15 81 38 67 49 58 91 29 93 92 57 70 68 82 50 86 90
Card 107: 92 57 65 15 23 45 96 56 88 25 | 92 25 15 31 57 56 64 41 87 30 23 78 38 45 28 10 65 71 96 88 27 3 69 91 73
Card 108: 31 1 94 61 10 45 34 11 41 66 | 2 66 38 78 57 88 19 46 35 23 36 59 34 61 10 96 41 45 81 1 94 63 28 12 76
Card 109: 16 72 48 78 77 27 12 36 7 42 | 22 99 23 36 13 53 2 25 72 1 47 48 14 49 69 3 93 44 78 87 38 55 60 52 90
Card 110: 6 80 47 92 32 83 37 53 4 87 | 92 6 41 4 20 91 81 83 40 70 7 87 19 73 63 37 18 47 99 53 80 32 66 45 39
Card 111: 9 72 17 89 28 68 34 63 76 81 | 80 70 22 36 23 61 59 7 53 43 45 67 3 60 6 89 79 95 56 85 31 98 65 39 48
Card 112: 10 23 9 78 98 3 27 6 84 60 | 16 68 84 10 22 50 87 9 5 23 27 74 21 98 3 2 60 85 73 1 26 83 6 89 78
Card 113: 14 90 59 66 86 7 44 10 40 69 | 91 87 14 59 29 40 56 45 11 66 15 90 48 24 62 69 44 79 20 98 76 10 86 7 43
Card 114: 31 90 75 12 34 60 39 74 24 2 | 56 52 85 40 1 14 80 60 42 84 75 18 6 90 76 25 44 74 28 34 13 12 54 48 7
Card 115: 67 42 11 91 53 57 98 17 95 50 | 74 45 25 98 57 66 67 77 69 95 87 79 83 39 96 84 42 91 21 3 53 17 63 50 11
Card 116: 66 36 5 11 33 51 30 67 38 3 | 50 86 36 76 33 77 30 51 11 67 38 26 43 66 39 69 17 90 21 3 16 56 62 5 73
Card 117: 53 34 69 9 10 61 18 23 93 14 | 44 9 69 2 90 14 53 23 21 92 49 72 31 61 46 10 27 70 57 38 18 93 34 67 11
Card 118: 83 89 94 55 65 36 20 79 53 14 | 36 65 41 8 49 29 99 83 94 5 62 78 53 20 68 66 14 89 4 74 48 81 77 52 55
Card 119: 82 69 85 60 9 13 16 3 18 44 | 82 55 85 3 5 80 43 11 13 86 16 31 56 70 17 46 79 69 60 44 95 81 45 49 93
Card 120: 35 53 9 78 73 55 20 64 13 62 | 9 20 3 84 35 71 22 86 8 64 58 82 88 51 54 13 38 68 5 77 81 56 21 74 55
Card 121: 61 34 85 77 66 87 91 49 15 36 | 59 49 46 70 10 94 93 87 36 3 44 66 24 61 95 83 91 75 89 60 81 57 41 85 74
Card 122: 22 90 71 49 34 4 56 74 42 3 | 21 52 19 53 79 34 56 71 95 5 91 14 4 40 78 96 61 42 57 47 73 50 10 74 87
Card 123: 87 49 40 25 31 4 20 48 1 76 | 12 6 43 69 48 2 9 24 95 65 47 57 4 91 94 39 16 62 68 8 23 42 38 59 78
Card 124: 63 38 94 44 69 76 33 89 47 32 | 8 19 96 98 68 24 54 31 28 67 57 73 45 70 64 22 65 50 34 80 6 4 10 78 90
Card 125: 4 48 65 10 93 80 26 23 90 12 | 64 32 40 87 58 3 13 18 86 60 66 71 74 9 61 43 50 99 88 52 95 46 37 22 67
Card 126: 90 71 53 57 5 24 6 3 52 8 | 96 33 13 70 44 27 87 89 81 63 65 8 66 47 31 92 40 53 7 88 99 19 64 38 79
Card 127: 89 68 48 98 32 22 73 79 53 93 | 75 30 35 15 96 64 19 4 14 66 88 85 33 11 43 82 25 1 61 91 94 45 6 78 77
Card 128: 15 39 76 95 5 70 9 23 4 65 | 64 58 90 54 46 42 68 29 11 38 20 92 87 44 98 83 99 27 67 22 13 6 14 43 55
Card 129: 45 83 47 63 64 38 15 95 6 48 | 49 91 6 20 64 56 52 28 55 5 15 54 61 11 71 95 53 57 8 75 27 98 92 13 81
Card 130: 37 14 56 22 7 1 9 76 83 91 | 56 53 1 36 74 37 9 73 70 91 22 77 83 44 68 97 54 39 76 7 65 55 14 34 38
Card 131: 23 92 82 24 86 78 31 98 68 48 | 83 29 28 54 65 47 92 67 94 48 89 49 24 4 59 40 41 82 86 64 38 98 78 66 68
Card 132: 9 63 36 66 29 97 90 20 81 46 | 10 40 43 82 4 9 37 87 3 27 28 54 65 5 50 80 8 31 73 26 88 96 74 23 57
Card 133: 17 48 12 31 13 44 57 45 40 88 | 56 80 55 26 8 16 22 70 13 45 78 7 4 40 10 71 34 32 59 35 69 82 47 88 46
Card 134: 91 87 65 7 49 67 17 60 9 78 | 50 35 40 25 74 62 29 80 21 93 92 52 39 81 51 8 47 65 4 89 83 6 88 87 43
Card 135: 35 87 16 9 34 80 15 81 83 61 | 46 40 8 93 89 67 86 35 71 9 76 95 49 26 22 28 87 90 64 34 79 27 32 59 23
Card 136: 23 1 83 65 67 46 40 97 71 55 | 86 8 79 95 2 59 20 60 31 11 42 97 62 12 67 80 19 55 81 33 13 87 57 9 23
Card 137: 23 99 91 8 79 45 29 3 42 27 | 85 45 65 82 36 76 29 48 8 78 54 79 57 34 70 52 3 96 19 86 12 91 51 59 66
Card 138: 47 48 85 73 89 61 98 39 36 2 | 83 50 1 63 71 30 76 11 93 82 60 4 78 56 66 25 75 33 51 57 28 24 67 74 58
Card 139: 40 41 96 36 71 97 74 78 9 83 | 41 73 51 70 76 22 23 63 56 58 26 91 47 37 88 80 18 67 95 33 11 60 34 7 94
Card 140: 98 32 46 64 18 95 27 65 74 41 | 89 20 42 40 58 84 48 76 67 12 73 44 23 92 90 70 81 71 85 11 83 59 78 22 9
Card 141: 34 18 67 74 52 35 31 27 14 54 | 92 44 48 73 14 51 98 54 88 5 70 65 80 66 84 56 7 40 39 71 94 86 26 25 11
Card 142: 57 53 93 13 4 96 83 23 74 90 | 82 43 42 40 38 87 81 58 44 71 59 50 7 9 30 98 66 80 85 29 1 84 20 26 72
Card 143: 47 3 32 53 72 82 44 64 85 24 | 2 71 98 94 62 23 87 68 93 86 70 96 19 84 74 15 95 42 29 90 6 54 67 30 61
Card 144: 74 46 9 94 60 86 56 40 34 57 | 66 55 16 95 5 25 75 90 47 76 54 93 61 23 37 89 64 48 42 30 18 31 3 97 27
Card 145: 57 25 17 78 1 63 31 3 65 23 | 39 95 13 65 3 27 17 85 56 47 10 8 63 51 23 25 40 22 54 78 81 62 90 4 50
Card 146: 54 71 5 68 25 76 33 31 32 64 | 99 75 87 61 32 91 47 71 11 51 43 36 33 83 3 63 35 42 16 31 81 28 86 22 90
Card 147: 22 98 86 67 26 72 31 52 93 20 | 87 42 20 49 43 35 27 52 56 86 40 22 29 59 76 26 9 93 30 58 67 31 72 33 98
Card 148: 47 81 86 1 87 63 16 58 98 26 | 34 15 7 39 47 86 21 14 81 49 87 43 91 24 73 63 18 98 37 29 77 53 67 26 19
Card 149: 24 21 62 66 80 31 50 23 13 54 | 47 6 13 90 54 49 66 74 62 34 4 95 23 55 50 45 18 59 61 21 26 75 39 80 24
Card 150: 14 97 9 69 44 64 63 22 8 89 | 71 65 32 59 28 43 97 48 6 70 45 75 63 99 60 39 20 78 95 47 55 1 74 58 13
Card 151: 93 73 94 83 23 50 68 40 18 13 | 76 70 83 7 4 23 82 29 78 40 93 77 66 94 92 68 18 2 15 49 17 39 37 35 64
Card 152: 73 6 44 81 1 39 61 34 7 23 | 32 81 85 42 23 40 97 74 55 46 39 2 79 86 91 3 37 33 76 58 77 88 75 12 53
Card 153: 15 19 22 66 3 50 77 97 21 62 | 66 59 27 78 6 28 54 13 32 70 23 51 48 50 17 43 42 21 22 34 16 64 3 37 74
Card 154: 10 17 93 15 92 4 22 2 44 88 | 60 69 90 85 19 13 88 11 84 39 68 33 14 27 95 2 53 87 66 82 74 36 41 42 46
Card 155: 74 88 14 39 78 54 60 75 11 65 | 64 14 66 16 18 81 20 36 3 82 8 62 34 87 43 53 80 96 59 39 78 5 40 13 21
Card 156: 25 5 87 20 51 57 61 39 16 83 | 37 63 60 79 83 52 81 99 92 26 70 76 56 8 73 98 5 48 1 46 16 86 28 12 78
Card 157: 45 7 33 97 91 59 10 77 2 82 | 98 10 1 28 4 37 69 92 99 58 40 42 34 38 26 81 3 18 84 45 31 20 55 36 44
Card 158: 98 33 35 10 56 43 60 68 25 62 | 61 89 80 40 2 26 3 13 57 10 96 71 86 27 78 87 59 37 45 75 79 46 49 36 66
Card 159: 12 31 72 74 90 88 58 73 25 9 | 51 71 23 44 5 34 82 33 55 49 68 39 20 93 13 97 81 14 2 91 76 75 50 95 7
Card 160: 38 23 46 5 85 22 26 81 91 93 | 85 38 22 58 19 3 89 35 84 46 18 53 95 91 47 93 99 33 81 68 57 49 80 71 23
Card 161: 57 14 48 68 72 81 93 61 43 40 | 6 5 47 59 11 81 13 38 52 26 91 22 57 55 35 19 61 2 29 93 14 74 53 45 60
Card 162: 20 52 9 61 26 94 11 84 28 37 | 39 9 88 48 73 14 24 29 28 37 31 27 95 79 98 26 45 11 96 68 47 58 35 62 52
Card 163: 11 42 60 15 27 43 13 17 72 98 | 12 74 81 37 95 20 86 42 72 79 66 89 62 63 38 73 65 82 8 28 50 70 78 15 94
Card 164: 88 38 30 3 48 17 19 68 73 2 | 13 71 34 83 40 38 59 12 73 2 91 52 60 19 87 84 1 82 65 3 8 99 80 79 70
Card 165: 22 62 51 13 76 17 26 41 46 34 | 93 50 94 18 84 39 48 75 59 3 44 67 37 32 55 82 79 14 7 86 61 27 31 74 42
Card 166: 27 80 73 77 72 18 83 97 53 3 | 6 74 34 22 75 60 99 17 47 12 29 64 48 67 15 14 63 13 19 49 5 89 42 9 11
Card 167: 14 31 99 33 53 52 98 95 49 73 | 95 92 60 18 19 39 90 31 10 58 7 6 59 51 73 22 45 49 4 21 67 76 78 56 20
Card 168: 11 78 93 57 58 47 40 22 23 85 | 6 27 66 43 57 2 90 49 25 60 99 19 36 22 47 80 1 32 21 87 98 58 93 9 76
Card 169: 99 40 75 47 22 83 41 50 18 51 | 94 74 86 14 12 5 78 61 89 17 8 83 30 90 51 87 53 43 41 27 13 92 26 49 76
Card 170: 23 16 36 32 91 52 73 53 18 83 | 90 76 24 97 95 62 39 70 3 52 63 30 19 75 96 82 9 71 81 64 22 84 99 35 21
Card 171: 38 27 53 94 16 71 18 6 83 17 | 76 3 78 23 31 19 50 22 57 97 39 35 56 51 83 94 55 85 1 5 12 43 86 58 46
Card 172: 45 79 25 86 56 50 20 18 97 52 | 40 85 90 28 97 43 4 3 22 76 21 61 16 62 95 29 83 44 15 12 56 34 53 36 93
Card 173: 1 79 49 77 62 33 84 76 7 50 | 29 6 42 56 67 47 94 25 97 48 86 43 3 18 51 21 93 16 95 14 15 82 71 87 75
Card 174: 83 64 11 39 24 97 35 54 27 60 | 22 16 31 92 42 94 72 62 58 5 69 8 28 33 89 47 23 52 90 57 68 80 9 96 7
Card 175: 87 10 42 65 40 51 31 45 48 89 | 75 37 60 71 76 92 10 29 14 63 81 34 94 88 32 91 6 82 79 90 53 89 68 49 26
Card 176: 96 83 15 50 17 16 81 85 11 35 | 31 17 8 30 33 47 11 15 41 73 99 40 70 48 91 26 96 60 39 95 52 59 45 23 50
Card 177: 64 51 20 97 68 69 57 58 34 12 | 54 82 32 79 89 70 47 52 16 36 83 10 49 8 18 94 73 77 48 42 19 98 55 75 80
Card 178: 36 1 53 62 73 77 52 59 51 3 | 59 35 68 1 45 77 4 79 83 16 36 63 99 53 52 3 73 51 13 89 84 32 64 33 62
Card 179: 30 70 61 7 29 52 97 81 65 59 | 48 5 42 71 88 89 93 64 37 28 26 25 90 94 92 21 50 6 19 33 68 66 78 1 15
Card 180: 66 3 33 16 57 41 91 83 48 68 | 58 68 33 80 42 13 69 78 16 83 18 41 34 35 79 48 66 62 86 90 2 6 96 57 91
Card 181: 86 94 43 29 75 78 42 95 13 10 | 42 88 43 13 60 52 47 86 87 59 95 72 8 23 82 2 69 61 14 71 94 90 30 85 51
Card 182: 73 90 84 14 52 15 98 43 3 23 | 84 8 11 64 83 62 77 18 53 81 19 47 1 79 99 41 40 74 93 89 20 72 49 26 38
Card 183: 24 78 51 40 92 66 77 39 97 68 | 38 70 63 5 19 21 95 73 64 14 55 80 23 22 77 65 74 97 37 26 82 83 9 52 60
Card 184: 98 12 62 53 69 27 84 64 91 94 | 19 9 90 98 43 26 7 12 68 16 10 45 20 23 4 63 3 38 77 6 27 8 91 70 60
Card 185: 32 37 2 76 75 62 39 33 12 13 | 11 29 49 77 50 97 65 87 25 91 10 21 15 82 95 99 80 71 54 42 48 78 72 63 34
Card 186: 55 49 21 41 83 40 29 51 54 57 | 20 88 52 62 85 90 25 45 54 58 72 91 98 14 13 28 74 92 31 8 42 3 26 11 59
Card 187: 95 43 56 46 98 96 55 31 28 50 | 23 5 13 35 95 37 1 89 76 45 68 73 52 15 26 3 38 36 99 51 80 8 63 77 28
Card 188: 84 71 30 79 6 13 57 3 63 55 | 46 45 43 26 48 47 37 35 88 13 59 9 95 86 49 98 64 62 54 44 22 92 25 3 15
Card 189: 56 94 93 30 27 53 85 58 4 91 | 86 70 1 96 60 92 66 33 9 50 78 41 67 55 7 28 89 31 14 19 76 42 71 82 63
Card 190: 17 27 42 70 11 38 47 58 92 88 | 73 15 86 13 25 64 58 4 61 95 36 41 94 17 72 90 22 6 56 98 35 45 60 19 33
Card 191: 19 96 44 57 88 39 7 67 85 89 | 49 31 15 98 77 14 43 59 85 2 79 71 69 81 95 93 33 66 25 87 65 13 62 46 91
Card 192: 29 77 54 66 79 7 88 72 99 35 | 50 94 48 18 60 56 74 59 97 5 87 8 70 93 81 27 14 57 25 22 71 63 83 44 15

View File

@@ -0,0 +1,37 @@
-- https://adventofcode.com/2024/day/1
import Data.List (elemIndices, sort)
import GHC.IO (unsafePerformIO)
input :: FilePath
input = "src/advent_of_code/2024/1.input"
-- entries :: ([Int], [Int])
-- entries = unzip $ map parse' $ unsafePerformIO $ lines <$> readFile input
entries = unsafePerformIO $ lines <$> readFile input
main :: IO ()
main = do
entries <- lines <$> readFile input
print "Advent of Code 2024 - Day 1"
print $ "Part 1: " <> show (solveP1 $ unzip $ map parse' entries)
print $ "Part 2: " <> show (solveP2 $ unzip $ map parse' entries)
parse' :: String -> (Int, Int)
parse' str = (read l, read r)
where
[l, r] = words str
solveP1 :: ([Int], [Int]) -> Int
solveP1 (as, bs) = sum $ map abs $ zipWith subtract as' bs'
where
as' = sort as
bs' = sort bs
solveP2 :: ([Int], [Int]) -> Int
solveP2 (as, bs) = sum $ zipWith (*) as (map (f bs) as)
where
f :: [Int] -> Int -> Int
f bs a = length $ elemIndices a bs

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
3 4
4 3
2 5
1 3
3 9
3 3

View File

@@ -0,0 +1,51 @@
-- https://adventofcode.com/2024/day/2
{-# LANGUAGE OverloadedStrings #-}
import Data.List (all, drop, elem, filter, length, map, or, sort,
sortOn, tail, take, zipWith)
import Data.Ord (Down (Down), Ord ((<=), (>=)))
import Data.Text (Text, lines, pack, splitOn, unpack)
import Data.Text.IO (readFile)
import GHC.IO (unsafePerformIO)
import Prelude hiding (lines, readFile)
entries :: [[Int]]
entries = parse . unsafePerformIO $ lines <$> readFile "src/advent_of_code/2024/2.input"
entries' :: [[Int]]
entries' = parse . unsafePerformIO $ lines <$> readFile "src/advent_of_code/2024/2f.input"
parse :: [Text] -> [[Int]]
parse = map (map (read . unpack) . splitOn " ")
main :: IO ()
main = do
entries <- parse . lines <$> readFile "src/advent_of_code/2024/2.input"
print "Advent of Code 2024 - Day 2"
print $ "Part 1: " <> show (solveP1 entries)
print $ "Part 2: " <> show (solveP2 entries)
solveP1 :: [[Int]] -> Int
solveP1 = length . filter (== True) . map safeReportP1
solveP2 :: [[Int]] -> Int
solveP2 = length . filter (== True) . map safeReportP2
safeReportP1 :: [Int] -> Bool
safeReportP1 report = isSorted report && adjacentLevelCheck report
isSorted :: [Int] -> Bool
isSorted report = report `elem` [sort report, sortOn Down report]
adjacentLevelCheck :: [Int] -> Bool
adjacentLevelCheck report =
all (((== True) . (\n-> n>=1 && n<=3)) . abs)
(zipWith subtract report (tail report))
safeReportP2 :: [Int] -> Bool
safeReportP2 report = any safeReportP1 (removeOneBadReport report)
removeOneBadReport :: [Int] -> [[Int]]
removeOneBadReport lst = map (\i -> take i lst <> drop (succ i) lst) [0..length lst-1]

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
7 6 4 2 1
1 2 7 8 9
9 7 6 2 1
1 3 2 4 5
8 6 4 4 1
1 3 6 7 9

View File

@@ -0,0 +1,37 @@
-- https://www.hackerrank.com/challenges/magic-square-forming/problem
module Main where
import Data.List (transpose)
main :: IO ()
main = print "test"
s :: [[Integer]]
s =
[ [5, 3, 4]
, [1, 5, 8]
, [6, 4, 2]
]
-- isMagicSquare n s =
-- all (sum rows == n) &&
-- all (sum cols == n) &&
-- all (sum diag == n)
-- where
-- rows =
get s (x,y) = s !! x !! y
allCoords n = [ (x,y) | x <- [0..n-1], y <- [0..n-1] ]
diagCoords n = [ (x,y) | x <- [0..n-1], y <- [0 ..n-1], x == y ] ++
[ (x,y) | x <- [0..n-1], y <- [n-1, n-2.. 0], x + y == n-1 ]
rowSums :: [[Integer]] -> [Integer]
rowSums = map sum
colSums :: [[Integer]] -> [Integer]
colSums = map sum . transpose
diagSums :: [[Integer]] -> [Integer]
diagSums n = map (\(x,y) -> get n (x,y)) (diagCoords 3)

View File

@@ -0,0 +1,4 @@
-- https://www.hackerrank.com/challenges/fp-list-replication/
f :: Int -> [Int] -> [Int]
f s = concatMap (replicate s)

View File

@@ -0,0 +1,49 @@
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

64
src/l33tcode/841.go Normal file
View File

@@ -0,0 +1,64 @@
/*
Keys and Rooms
Instructions:
There are n rooms labeled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key.
When you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting which room it unlocks, and you can take all of them with you to unlock the other rooms.
Given an array rooms where rooms[i] is the set of keys that you can obtain if you visited room i, return true if you can visit all the rooms, or false otherwise.
Constraints:
n == rooms.length
2 <= n <= 1000
0 <= rooms[i].length <= 1000
1 <= sum(rooms[i].length) <= 3000
0 <= rooms[i][j] < n
All the values of rooms[i] are unique.
*/
package main
import "fmt"
func main() {
res := canVisitAllRooms([][]int{{1}, {2}, {3}, {}})
fmt.Printf("Example 1 works: %+v\n\n", res)
res = canVisitAllRooms([][]int{{1, 3}, {3, 0, 1}, {2}, {0}})
fmt.Printf("Example 2 works: %+v\n", res)
}
func canVisitAllRooms(rooms [][]int) bool {
if len(rooms) > 0 && len(rooms[0]) == 0 {
return false
}
keys := getAllKeys(0, make(map[int]struct{}), rooms)
keys[0] = struct{}{}
for i := 0; i < len(rooms); i++ {
if _, ok := keys[i]; !ok {
return false
}
}
return true
}
func getAllKeys(index int, seen map[int]struct{}, rooms [][]int) map[int]struct{} {
keys := map[int]struct{}{}
for j := 0; j < len(rooms[index]); j++ {
if _, ok := seen[rooms[index][j]]; ok {
continue
} else {
seen[rooms[index][j]] = struct{}{}
}
keys[rooms[index][j]] = struct{}{}
insideKeys := getAllKeys(rooms[index][j], seen, rooms)
for k := range insideKeys {
keys[k] = struct{}{}
}
}
return keys
}

52
src/l33tcode/841.hs Normal file
View File

@@ -0,0 +1,52 @@
{-
Keys and Rooms
Instructions:
There are n rooms labelled from 0 to n - 1 and all the rooms are locked except for room 0. Your goal is to visit all the rooms. However, you cannot enter a locked room without having its key.
When you visit a room, you may find a set of distinct keys in it. Each key has a number on it, denoting which room it unlocks, and you can take all of them with you to unlock the other rooms.
Given an array rooms where rooms[i] is the set of keys that you can obtain if you visited room i, return true if you can visit all the rooms, or false otherwise.
Constraints:
n == rooms.length
2 <= n <= 1000
0 <= rooms[i].length <= 1000
1 <= sum(rooms[i].length) <= 3000
0 <= rooms[i][j] < n
All the values of rooms[i] are unique.
-}
module Main where
import Data.List (genericIndex, genericLength)
input1Rooms :: [[Integer]]
input1Rooms = [[1],[2],[3],[]]
input2Rooms :: [[Integer]]
input2Rooms = [[1,3],[3,0,1],[2],[0]]
main :: IO ()
main = do
print $ "Example 1 is: " <> show (canVisitAll input1Rooms)
print $ "Example 2 is: " <> show (canVisitAll input2Rooms)
canVisitAll :: [[Integer]] -> Bool
canVisitAll rooms = [0..l] == dfs rooms 0 []
where
l = l' rooms - 1
dfs :: [[Integer]] -> Integer -> [Integer] -> [Integer]
dfs graph current visited =
foldl (\visited next ->
if next `elem` visited
then visited
else dfs graph next visited)
(visited ++ [current])
(graph !!! current)
l' :: [a] -> Integer
l' = genericLength
(!!!) :: [a] -> Integer -> a
(!!!) = genericIndex

View File

@@ -0,0 +1,25 @@
{-
https://projecteuler.net/problem=1
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
-}
module Main where
import Data.List (union)
main :: IO ()
main = print ans
ans :: Integer
ans = sum (_3s <> _5s)
_3s :: [Integer]
_3s = [3,6..999]
_5s :: [Integer]
_5s = [5,10..999]
solution :: Integer
solution = sum $ union _3s _5s

View File

@@ -0,0 +1,24 @@
/*
https://projecteuler.net/problem=1
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
The sum of these multiples is 23.
Find the sum of all the multiples of 3 or 5 below 1000.
*/
var isMultipleOf = (m) => (n) => n % m === 0;
var is3_ = isMultipleOf(3);
var is5_ = isMultipleOf(5);
var is3 = (n) => n % 3 === 0;
var is5 = (n) => n % 5 === 0;
var limit = 1000;
let result = 0;
for (let i = 0; i < limit; i++) {
if (is3(i) || is5(i)) {
result += i;
}
}
console.log(`Answer is ${result}`);

View File

@@ -0,0 +1,121 @@
{-
Summation of Primes
Problem 10
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
Find the sum of all the primes below two million.
https://wiki.haskell.org/Prime_numbers
Compile with `ghc -O3 src/projectEuler/question10.hs`
Run with `time src/projectEuler/question10`
-}
{-# OPTIONS_GHC -O2 #-}
import Control.Monad (forM_, when)
import Data.Array.Base (IArray (unsafeAt),
MArray (unsafeWrite),
UArray (UArray),
unsafeFreezeSTUArray)
import Data.Array.ST (MArray (newArray), readArray,
runSTUArray, writeArray)
import Data.Array.Unboxed (UArray, assocs)
import Data.Bits (Bits (shiftL, shiftR))
import Data.Int (Int64)
import Data.List (genericIndex, genericTake)
import Data.Word (Word64)
-- https://hackage.haskell.org/package/arithmoi-0.13.0.0
import Math.NumberTheory.Primes (Prime (unPrime), primes)
main :: IO ()
main = do
print "Hello! Welcome to the prime number generator."
-- print "Please enter which nth prime you'd like: "
-- n <- getLine
-- let n' = read n :: Integer
-- print $ "Finding the " ++ n ++ "th prime."
-- print $ primes() `genericIndex` (10^ (10 :: Int))
print $ last $ take (10^ (10 :: Int)) primes
ans :: Integer
ans = sum $ takeWhile (< 2_000_000) $ map unPrime primes
primes1 :: [Integer]
primes1 = sieve [2..]
where
sieve (p : xs) = p : sieve [x | x <- xs, x `mod` p > 0]
primes2 :: [Integer]
primes2 = 2:([3..] `minus` composites)
where
composites = union [multiples p | p <- primes2]
multiples n = map (n*) [n..]
(x:xs) `minus` (y:ys) | x < y = x:(xs `minus` (y:ys))
| x == y = xs `minus` ys
| x > y = (x:xs) `minus` ys
union = foldr merge [ ]
where
merge (x:xs) ys = x:merge' xs ys
merge' (x:xs) (y:ys) | x < y = x:merge' xs (y:ys)
| x == y = x:merge' xs ys
| x > y = y:merge' (x:xs) ys
{-
https://wiki.haskell.org/Prime_numbers
Using Page-Segmented ST-Mutable Unboxed Array
-}
-- type Prime = Word64
-- cSieveBufferLimit :: Int
-- cSieveBufferLimit = 2^17 * 8 - 1 -- CPU L2 cache in bits
-- primes :: () -> [Prime]
-- primes() = 2 : _Y (listPagePrms . pagesFrom 0) where
-- _Y g = g (_Y g) -- non-sharing multi-stage fixpoint combinator
-- listPagePrms pgs@(hdpg@(UArray lwi _ rng _) : tlpgs) =
-- let loop i | i >= fromIntegral rng = listPagePrms tlpgs
-- | unsafeAt hdpg i = loop (i + 1)
-- | otherwise = let ii = lwi + fromIntegral i in
-- case fromIntegral $ 3 + ii + ii of
-- p -> p `seq` p : loop (i + 1) in loop 0
-- makePg lwi bps = runSTUArray $ do
-- let limi = lwi + fromIntegral cSieveBufferLimit
-- bplmt = floor $ sqrt $ fromIntegral $ limi + limi + 3
-- strta bp = let si = fromIntegral $ (bp * bp - 3) `shiftR` 1
-- in if si >= lwi then fromIntegral $ si - lwi else
-- let r = fromIntegral (lwi - si) `mod` bp
-- in if r == 0 then 0 else fromIntegral $ bp - r
-- cmpsts <- newArray (lwi, limi) False
-- fcmpsts <- unsafeFreezeSTUArray cmpsts
-- let cbps = if lwi == 0 then listPagePrms [fcmpsts] else bps
-- forM_ (takeWhile (<= bplmt) cbps) $ \ bp ->
-- forM_ (let sp = fromIntegral $ strta bp
-- in [ sp, sp + fromIntegral bp .. cSieveBufferLimit ]) $ \c ->
-- unsafeWrite cmpsts c True
-- return cmpsts
-- pagesFrom lwi bps = map (`makePg` bps)
-- [ lwi, lwi + fromIntegral cSieveBufferLimit + 1 .. ]
-- sieveUA :: Int -> UArray Int Bool
-- sieveUA top = runSTUArray $ do
-- let m = (top-1) `div` 2
-- r = floor . sqrt $ fromIntegral top + 1
-- sieve <- newArray (1,m) True -- :: ST s (STUArray s Int Bool)
-- forM_ [1..r `div` 2] $ \i -> do
-- isPrime <- readArray sieve i
-- when isPrime $ do -- ((2*i+1)^2-1)`div`2 == 2*i*(i+1)
-- forM_ [2*i*(i+1), 2*i*(i+2)+1..m] $ \j -> do
-- writeArray sieve j False
-- return sieve
-- primesToUA :: Int -> [Int]
-- primesToUA top = 2 : [i*2+1 | (i,True) <- assocs $ sieveUA top]

View File

@@ -0,0 +1,110 @@
{-
In the 20x20 grid below, four numbers along a diagonal line have been marked in *red*.
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10*26*38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95*63*94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17*78*78 96 83 14 88 34 89 63 72
21 36 23 09 75 00 76 44 20 45 35*14*00 61 33 97 34 31 33 95
78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
The product of these numbers is 26x63x78x14 = 1788696.
What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20x20 grid?
-}
import Data.List (genericDrop, genericIndex, genericTake)
grid :: [[Integer]]
grid =
[ [08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08]
, [49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00]
, [81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65]
, [52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91]
, [22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80]
, [24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50]
, [32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70]
, [67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 08, 40, 91, 66, 49, 94, 21]
, [24, 55, 58, 05, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72]
, [21, 36, 23, 09, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95]
, [78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 03, 80, 04, 62, 16, 14, 09, 53, 56, 92]
, [16, 39, 05, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57]
, [86, 56, 00, 48, 35, 71, 89, 07, 05, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58]
, [19, 80, 81, 68, 05, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 04, 89, 55, 40]
, [04, 52, 08, 83, 97, 35, 99, 16, 07, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66]
, [88, 36, 68, 87, 57, 62, 20, 72, 03, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69]
, [04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 08, 46, 29, 32, 40, 62, 76, 36]
, [20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16]
, [20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54]
, [01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48]
]
points :: Integer -> [(Integer, Integer)]
points n = [ (x,y) | x <- [1..n], y <- [1..n] ]
allDiagonals :: Integer -> [[(Integer, Integer)]]
allDiagonals n =
[ [(i, j), b, c, d]
| (i, j) <- points n
, i+3 <= n
, j+3 <= n
, b <- [(i + 1, j + 1)]
, c <- [(i + 2, j + 2)]
, d <- [(i + 3, j + 3)]
]
allUpDown :: Integer -> [[(Integer, Integer)]]
allUpDown n =
[ [(i, j), b, c, d]
| (i, j) <- points n
, i <= n
, j+3 <= n
, b <- [(i, j + 1)]
, c <- [(i, j + 2)]
, d <- [(i, j + 3)]
]
allLeftRight :: Integer -> [[(Integer, Integer)]]
allLeftRight n =
[ [(i, j), b, c, d]
| (i, j) <- points n
, i+3 <= n
, j <= n
, b <- [(i + 1, j)]
, c <- [(i + 2, j)]
, d <- [(i + 3, j)]
]
allSequences :: Integer -> [[(Integer, Integer)]]
allSequences n = allDiagonals n ++ allUpDown n ++ allLeftRight n
s20x20 :: [[(Integer, Integer)]]
s20x20 = allSequences 20
getValue :: [[Integer]] -> (Integer, Integer) -> Integer
getValue grid (x,y) = row `genericIndex` y'
where row = (head . genericDrop (x-1) . genericTake x) grid
y' = y-1 -- compensate for 1 index numbering above
-- |
-- λ> ans
-- 51267216
-- (0.13 secs, 38,281,312 bytes)
ans :: Integer
ans = maximum $ map (product . map (getValue grid)) s20x20
main :: IO ()
main = print ans

View File

@@ -0,0 +1,32 @@
-- module Main where
import Data.IntSet (size)
import Data.List (unfoldr)
import Math.NumberTheory.ArithmeticFunctions (divisorsSmall)
main :: IO ()
main = print ans
-- triangleNumber :: Integer -> [Integer]
-- triangleNumber 1 = [1]
-- triangleNumber n = sum [1..n] : triangleNumber (n-1)
triangleNumber i = (i * (i + 1)) `div` 2
triangleNumbers = map triangleNumber [1..]
-- triangleNumbers :: [Int]
-- triangleNumbers = unfoldr (\b-> Just (sum [1..b],b+1)) 1
-- isDivisible a b = a `rem` b == 0
-- divisors n = filter (isDivisible n) [1..(floor . sqrt) n ]
-- Triangle Numbers With More than N divisors
tnwmtNd :: Int -> [Int]
tnwmtNd n = filter ((>= n) . size . divisorsSmall) triangleNumbers
ans :: Int
ans = head $ tnwmtNd 500
{-
λ> main
76576500
(0.00 secs, 114,944 bytes)
First triangle number to have over 500 divisors is 76576500
-}

View File

@@ -0,0 +1,226 @@
{-
Work out the first ten digits of the sum of the following one-hundred 50-digit numbers.
37107287533902102798797998220837590246510135740250
46376937677490009712648124896970078050417018260538
74324986199524741059474233309513058123726617309629
91942213363574161572522430563301811072406154908250
23067588207539346171171980310421047513778063246676
89261670696623633820136378418383684178734361726757
28112879812849979408065481931592621691275889832738
44274228917432520321923589422876796487670272189318
47451445736001306439091167216856844588711603153276
70386486105843025439939619828917593665686757934951
62176457141856560629502157223196586755079324193331
64906352462741904929101432445813822663347944758178
92575867718337217661963751590579239728245598838407
58203565325359399008402633568948830189458628227828
80181199384826282014278194139940567587151170094390
35398664372827112653829987240784473053190104293586
86515506006295864861532075273371959191420517255829
71693888707715466499115593487603532921714970056938
54370070576826684624621495650076471787294438377604
53282654108756828443191190634694037855217779295145
36123272525000296071075082563815656710885258350721
45876576172410976447339110607218265236877223636045
17423706905851860660448207621209813287860733969412
81142660418086830619328460811191061556940512689692
51934325451728388641918047049293215058642563049483
62467221648435076201727918039944693004732956340691
15732444386908125794514089057706229429197107928209
55037687525678773091862540744969844508330393682126
18336384825330154686196124348767681297534375946515
80386287592878490201521685554828717201219257766954
78182833757993103614740356856449095527097864797581
16726320100436897842553539920931837441497806860984
48403098129077791799088218795327364475675590848030
87086987551392711854517078544161852424320693150332
59959406895756536782107074926966537676326235447210
69793950679652694742597709739166693763042633987085
41052684708299085211399427365734116182760315001271
65378607361501080857009149939512557028198746004375
35829035317434717326932123578154982629742552737307
94953759765105305946966067683156574377167401875275
88902802571733229619176668713819931811048770190271
25267680276078003013678680992525463401061632866526
36270218540497705585629946580636237993140746255962
24074486908231174977792365466257246923322810917141
91430288197103288597806669760892938638285025333403
34413065578016127815921815005561868836468420090470
23053081172816430487623791969842487255036638784583
11487696932154902810424020138335124462181441773470
63783299490636259666498587618221225225512486764533
67720186971698544312419572409913959008952310058822
95548255300263520781532296796249481641953868218774
76085327132285723110424803456124867697064507995236
37774242535411291684276865538926205024910326572967
23701913275725675285653248258265463092207058596522
29798860272258331913126375147341994889534765745501
18495701454879288984856827726077713721403798879715
38298203783031473527721580348144513491373226651381
34829543829199918180278916522431027392251122869539
40957953066405232632538044100059654939159879593635
29746152185502371307642255121183693803580388584903
41698116222072977186158236678424689157993532961922
62467957194401269043877107275048102390895523597457
23189706772547915061505504953922979530901129967519
86188088225875314529584099251203829009407770775672
11306739708304724483816533873502340845647058077308
82959174767140363198008187129011875491310547126581
97623331044818386269515456334926366572897563400500
42846280183517070527831839425882145521227251250327
55121603546981200581762165212827652751691296897789
32238195734329339946437501907836945765883352399886
75506164965184775180738168837861091527357929701337
62177842752192623401942399639168044983993173312731
32924185707147349566916674687634660915035914677504
99518671430235219628894890102423325116913619626622
73267460800591547471830798392868535206946944540724
76841822524674417161514036427982273348055556214818
97142617910342598647204516893989422179826088076852
87783646182799346313767754307809363333018982642090
10848802521674670883215120185883543223812876952786
71329612474782464538636993009049310363619763878039
62184073572399794223406235393808339651327408011116
66627891981488087797941876876144230030984490851411
60661826293682836764744779239180335110989069790714
85786944089552990653640447425576083659976645795096
66024396409905389607120198219976047599490197230297
64913982680032973156037120041377903785566085089252
16730939319872750275468906903707539413042652315011
94809377245048795150954100921645863754710598436791
78639167021187492431995700641917969777599028300699
15368713711936614952811305876380278410754449733078
40789923115535562561142322423255033685442488917353
44889911501440648020369068063960672322193204149535
41503128880339536053299340368006977710650566631954
81234880673210146739058568557934581403627822703280
82616570773948327592232845941706525094512325230608
22918802058777319719839450180888072429661980811197
77158542502016545090413245809786882778948721859617
72107838435069186155435662884062257473692284509516
20849603980134001723930671666823555245252804609722
53503534226472524250874054075591789781264330331690
-}
oneHundredFiftyDigitNumbers :: [Integer]
oneHundredFiftyDigitNumbers =
[ 37107287533902102798797998220837590246510135740250
, 46376937677490009712648124896970078050417018260538
, 74324986199524741059474233309513058123726617309629
, 91942213363574161572522430563301811072406154908250
, 23067588207539346171171980310421047513778063246676
, 89261670696623633820136378418383684178734361726757
, 28112879812849979408065481931592621691275889832738
, 44274228917432520321923589422876796487670272189318
, 47451445736001306439091167216856844588711603153276
, 70386486105843025439939619828917593665686757934951
, 62176457141856560629502157223196586755079324193331
, 64906352462741904929101432445813822663347944758178
, 92575867718337217661963751590579239728245598838407
, 58203565325359399008402633568948830189458628227828
, 80181199384826282014278194139940567587151170094390
, 35398664372827112653829987240784473053190104293586
, 86515506006295864861532075273371959191420517255829
, 71693888707715466499115593487603532921714970056938
, 54370070576826684624621495650076471787294438377604
, 53282654108756828443191190634694037855217779295145
, 36123272525000296071075082563815656710885258350721
, 45876576172410976447339110607218265236877223636045
, 17423706905851860660448207621209813287860733969412
, 81142660418086830619328460811191061556940512689692
, 51934325451728388641918047049293215058642563049483
, 62467221648435076201727918039944693004732956340691
, 15732444386908125794514089057706229429197107928209
, 55037687525678773091862540744969844508330393682126
, 18336384825330154686196124348767681297534375946515
, 80386287592878490201521685554828717201219257766954
, 78182833757993103614740356856449095527097864797581
, 16726320100436897842553539920931837441497806860984
, 48403098129077791799088218795327364475675590848030
, 87086987551392711854517078544161852424320693150332
, 59959406895756536782107074926966537676326235447210
, 69793950679652694742597709739166693763042633987085
, 41052684708299085211399427365734116182760315001271
, 65378607361501080857009149939512557028198746004375
, 35829035317434717326932123578154982629742552737307
, 94953759765105305946966067683156574377167401875275
, 88902802571733229619176668713819931811048770190271
, 25267680276078003013678680992525463401061632866526
, 36270218540497705585629946580636237993140746255962
, 24074486908231174977792365466257246923322810917141
, 91430288197103288597806669760892938638285025333403
, 34413065578016127815921815005561868836468420090470
, 23053081172816430487623791969842487255036638784583
, 11487696932154902810424020138335124462181441773470
, 63783299490636259666498587618221225225512486764533
, 67720186971698544312419572409913959008952310058822
, 95548255300263520781532296796249481641953868218774
, 76085327132285723110424803456124867697064507995236
, 37774242535411291684276865538926205024910326572967
, 23701913275725675285653248258265463092207058596522
, 29798860272258331913126375147341994889534765745501
, 18495701454879288984856827726077713721403798879715
, 38298203783031473527721580348144513491373226651381
, 34829543829199918180278916522431027392251122869539
, 40957953066405232632538044100059654939159879593635
, 29746152185502371307642255121183693803580388584903
, 41698116222072977186158236678424689157993532961922
, 62467957194401269043877107275048102390895523597457
, 23189706772547915061505504953922979530901129967519
, 86188088225875314529584099251203829009407770775672
, 11306739708304724483816533873502340845647058077308
, 82959174767140363198008187129011875491310547126581
, 97623331044818386269515456334926366572897563400500
, 42846280183517070527831839425882145521227251250327
, 55121603546981200581762165212827652751691296897789
, 32238195734329339946437501907836945765883352399886
, 75506164965184775180738168837861091527357929701337
, 62177842752192623401942399639168044983993173312731
, 32924185707147349566916674687634660915035914677504
, 99518671430235219628894890102423325116913619626622
, 73267460800591547471830798392868535206946944540724
, 76841822524674417161514036427982273348055556214818
, 97142617910342598647204516893989422179826088076852
, 87783646182799346313767754307809363333018982642090
, 10848802521674670883215120185883543223812876952786
, 71329612474782464538636993009049310363619763878039
, 62184073572399794223406235393808339651327408011116
, 66627891981488087797941876876144230030984490851411
, 60661826293682836764744779239180335110989069790714
, 85786944089552990653640447425576083659976645795096
, 66024396409905389607120198219976047599490197230297
, 64913982680032973156037120041377903785566085089252
, 16730939319872750275468906903707539413042652315011
, 94809377245048795150954100921645863754710598436791
, 78639167021187492431995700641917969777599028300699
, 15368713711936614952811305876380278410754449733078
, 40789923115535562561142322423255033685442488917353
, 44889911501440648020369068063960672322193204149535
, 41503128880339536053299340368006977710650566631954
, 81234880673210146739058568557934581403627822703280
, 82616570773948327592232845941706525094512325230608
, 22918802058777319719839450180888072429661980811197
, 77158542502016545090413245809786882778948721859617
, 72107838435069186155435662884062257473692284509516
, 20849603980134001723930671666823555245252804609722
, 53503534226472524250874054075591789781264330331690
]
digits :: Integer -> [Integer]
digits = go []
where
go acc 0 = acc
go acc n = go (digit:acc) rest
where
digit = n `rem` 10
rest = n `div` 10
ans :: [Integer]
ans = take 10 $ reverse . digits $ sum oneHundredFiftyDigitNumbers
main :: IO ()
main = do
print ans
print (sum oneHundredFiftyDigitNumbers)

View File

@@ -0,0 +1,39 @@
{-
The following iterative sequence is defined for the set of positive integers:
n -> n/2 (n is even)
n -> 3n+1 (n is odd )
Using the rule above and starting with 13, we generate the following sequence:
13 -> 40 -> 20 -> 10 -> 5 -> 16 -> 8 -> 4 -> 2 -> 1
It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms.
Although it has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.
Which starting number, under one million, produces the longest chain?
NOTE: Once the chain starts the terms are allowed to go above one million.
-}
module Main where
import Data.List (sortOn)
import Data.Ord (Down (Down))
main :: IO ()
main = print ans
ans :: Int
ans = fst $ head $ sortOn (Down . snd) $ map collatzChainStartingAt [1..limit]
nextCollatz :: Int -> Int
nextCollatz n
| n == 1 = 0
| even n = n `div` 2
| odd n = 3*n + 1
collatzChainStartingAt :: Int -> (Int, Int)
collatzChainStartingAt n = (n, s')
where s' = length $ takeWhile (/= 0) $ iterate nextCollatz n
limit :: Int
limit = 1_000_000

View File

@@ -0,0 +1,44 @@
{-
https://projecteuler.net/problem=15
Starting in the top left corner of a 2x2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
How many such routes are there through a 20x20 grid?
-}
module Main where
import Prelude hiding (Right)
main :: IO ()
main = print ans
ans = 42
limit = 2
points = [ (x,y)
| x <- [0..limit]
, y <- [0..limit]
]
data Direction = Right | Down
move Right (x,y) = (x+1, y )
move Down (x,y) = (x , y+1)
-- solve :: (Int, Int) -> [[(Int, Int)]]
{-
λ> [(0,0)]
[(0,0)]
λ> [(0,0),(1,0),(2,0),(2,1),(2,2)]
[(0,0),(1,0),(2,0),(2,1),(2,2)]
λ> [ [(0,0),(1,0),(2,0),(2,1),(2,2)], [(0,0),(1,0),(1,1),(2,1),(2,2)]]
[[(0,0),(1,0),(2,0),(2,1),(2,2)],[(0,0),(1,0),(1,1),(2,1),(2,2)]]
λ>
-}
data Tree a
= Leaf a
| Branch (Tree a) (Tree a)
deriving (Show)

View File

@@ -0,0 +1,15 @@
{-
https://projecteuler.net/problem=16
2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
What is the sum of the digits of the number 2^1000?
-}
module Main where
main :: IO ()
main = print ans
ans :: Integer
ans = sum $ map (\c -> read [c] :: Integer) $ show (2^1000)

View File

@@ -0,0 +1,50 @@
import Debug.Trace (trace)
small :: [[Integer]]
small = [
[3],
[7,4],
[2,4,6],
[1000,5,9,3]
]
triangle :: [[Integer]]
triangle = [
[75],
[95,64],
[17,47,82],
[18,35,87,10],
[20,04,82,47,65],
[19,01,23,75,03,34],
[88,02,77,73,07,63,67],
[99,65,04,28,06,16,70,92],
[41,41,26,56,83,40,80,70,33],
[41,48,72,33,47,32,37,16,94,29],
[53,71,44,65,25,43,91,52,97,51,14],
[70,11,33,28,77,73,17,78,39,68,17,57],
[91,71,52,38,17,14,91,43,58,50,27,29,48],
[63,66,04,68,89,53,67,30,73,16,69,87,40,31],
[04,62,98,27,23,09,70,98,73,93,38,53,60,04,23]
]
maxPath t i j = (t !! i !! j) +
(if i + 1 < length t
then max (maxPath t (i + 1) j) (maxPath t (i + 1) (j + 1))
else 0)
-- This max path doesn't consider the entire path,
-- it only considers the two numbers directly below the index
newMaxPath t i j = (t !! i !! j) +
(if i + 1 < length t
then newMaxPath t i' j'
else 0)
where
a = t !! i' !! j
b = t !! i' !! (j+1)
i' = i+1
j' = trace (show a) $ if a > b then j else j+1
main :: IO ()
main = print ans
ans :: Integer
ans = maxPath small 0 0

View File

@@ -0,0 +1,64 @@
{-
https://projecteuler.net/problem=19
You are given the following information, but you may prefer to do some research for yourself.
- 1 Jan 1900 was a Monday.
- Thirty days has September, April, June and November.
- All the rest have thirty-one,
- Saving February alone,
- Which has twenty-eight, rain or shine.
- And on leap years, twenty-nine.
A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
-}
daysInMonth :: [Int]
daysInMonth =
[ 31 -- Jan
, 28 -- Feb
, 31 -- Mar
, 30 -- Apr
, 31 -- May
, 30 -- Jun
, 31 -- Jul
, 31 -- Aug
, 30 -- Sep
, 31 -- Oct
, 30 -- Nov
, 31 -- Dec
]
isLeapYear :: Int -> Bool
isLeapYear yyyy
| yyyy `isDivBy` 400 = True
| yyyy `isDivBy` 100 = False
| otherwise = yyyy `isDivBy` 4
where
isDivBy yyyy n = yyyy `rem` n == 0
daysOfWeek :: [Int]
daysOfWeek = cycle
[ 1 -- Sun
, 0 -- Mon
, 0 -- Tue
, 0 -- Wed
, 0 -- Thu
, 0 -- Fri
, 0 -- Sat
]
daysInYear :: Int -> Int
daysInYear yyyy =
if isLeapYear yyyy
then 366
else 365
years :: [Int]
years = [1901..2000]
ans :: Int
ans = sum $ drop 2 $ take (sum $ map daysInYear years) daysOfWeek
-- 5217

View File

@@ -0,0 +1,16 @@
{-
https://projecteuler.net/problem=2
Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89,...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.
-}
module Main where
main :: IO ()
main = print ans
ans = sum $ filter even $ takeWhile(< 4_000_000) fibs
fibs = 1 : 2 : zipWith (+) fibs (tail fibs)

View File

@@ -0,0 +1,18 @@
{-
n! means n x (n - 1) x ... x 3 x 2 x 1.
For example, 10! = 10 x 9 x ... x 3 x 2 x 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.
Find the sum of the digits in the number 100!.
-}
import Data.Char (digitToInt)
read' :: Integer -> String
read' = show
main :: IO ()
main = do
print $ "Answer: " <> show ans
ans :: Int
ans = sum $ map digitToInt $ read' $ product [1..100]

View File

@@ -0,0 +1,34 @@
{-
https://projecteuler.net/problem=3
The prime factors of 13195 are 5, 7, 13, and 29.
What is the largest prime factor of the number 600851475143?
-}
module Main where
import Math.NumberTheory.Primes (Prime (unPrime),
UniqueFactorisation (factorise),
primes)
main :: IO ()
main = print ans
ans :: Int
ans = last $ filter (isFactor bigNum) primes'
primes' :: [Int]
primes' = takeWhile (< sqrt') $ map unPrime primes
where
sqrt' = floor $ sqrt (toEnum bigNum)
bigNum :: Int
bigNum = 600851475143
isFactor :: Int -> Int -> Bool
isFactor x n = x `rem` n == 0
ans' :: [Int]
ans' = map (unPrime . fst) $ factorise (fromEnum bigNum)
-- [(Prime 71,1),(Prime 839,1),(Prime 1471,1),(Prime 6857,1)]
-- [71,839,1471,6857]

View File

@@ -1,21 +1,30 @@
-- https://projecteuler.net/problem=4
{-
https://projecteuler.net/problem=4
A palindromic number reads the same both ways.
The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.
Find the largest palindrome made from the product of two 3-digit numbers.
-}
import Debug.Trace (trace)
twoDigitProducts :: [Integer]
twoDigitProducts = [ n*m | n <- [10..99], m <- [n..99] ]
threeDigitProducts :: [Integer]
threeDigitProducts = [ n*m | n <- [100..999], m <- [n..999] ]
isPalindrome :: Integer -> Bool
isPalindrome n = all (== True) $ zipWith (==) half half'
where
(half, half'') = splitAt h n'
(half, half'') = splitAt l n'
half' = reverse half''
h = length n' `div` 2
l = length n' `div` 2
n' = show n
-- n' = trace (show n) $ show n
solve :: Integer
solve = maximum $ filter isPalindrome twoDigitProducts
solve = maximum $ filter isPalindrome threeDigitProducts
main :: IO ()
main = print solve

View File

@@ -63,3 +63,5 @@ test = map (filter . multipleOf) [1..10]
-- lol
solve = foldl1 lcm [1..20]
main = print solve

View File

@@ -13,16 +13,29 @@ Find the difference between the sum of the squares
of the first one hundred natural numbers
and the square of the sum.
-}
upperRange = 100
upperRange :: Integer
upperRange = 1_000_000
square :: Num a => a -> a
square n = n^2
squares :: [Integer]
squares = map square [1..upperRange]
sum' :: [Integer] -> Integer
sum' = go 0
where
go acc [] = acc
go acc (x:xs) = go (acc+x) xs
sumOfSquares = sum' squares
sumOfSquares :: Integer
sumOfSquares = sum squares
squareOfTheSum = (sum [1..upperRange])^2
squareOfTheSum :: Integer
squareOfTheSum = sum [1..upperRange] ^2
solution :: Integer
solution = squareOfTheSum - sumOfSquares
main :: IO ()
main = print solution

View File

@@ -0,0 +1,40 @@
-- https://projecteuler.net/problem=7
-- Find the 10_001 prime number
-- import Data.Numbers.Primes (primes)
import Math.NumberTheory.Primes (primes)
primes1 :: [Integer]
primes1 = 2:3:prs
where
1:p:candidates = [6*k+r | k <- [0..], r <- [1,5]]
prs = p : filter isPrime candidates
isPrime n = not (any (divides n) (takeWhile (\p -> p*p <= n) prs))
divides n p = n `mod` p == 0
primes2 = 2:([3..] `minus` composites)
where
composites = union [multiples p | p <- primes2]
multiples n = map (n*) [n..]
(x:xs) `minus` (y:ys) | x < y = x:(xs `minus` (y:ys))
| x == y = xs `minus` ys
| x > y = (x:xs) `minus` ys
union = foldr merge [ ]
where
merge (x:xs) ys = x:merge' xs ys
merge' (x:xs) (y:ys) | x < y = x:merge' xs (y:ys)
| x == y = x:merge' xs ys
| x > y = y:merge' (x:xs) ys
primes3 = sieve [2..]
where
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

View File

@@ -0,0 +1,74 @@
{-
The four adjacent digits in the 1000-digit number that have the greatest product are 9 x 9 x 8 x 9 = 5832.
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product.
What is the value of this product?
-}
module Main where
import Data.Char (ord)
import Data.Foldable (maximumBy)
import Data.List (sort)
import Data.List.Split (splitOn)
thousandDigitNum :: Integer
thousandDigitNum = 7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
digits :: Integer -> [Integer]
digits = go []
where
go acc 0 = acc
go acc n = go (digit:acc) rest
where
digit = n `rem` 10
rest = n `div` 10
main :: IO ()
main = print ans
ans :: ([Integer], Integer)
ans = (l, p)
where
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?
-- why ask it like that???
-- doesn't have 0
-- otherwise is the largest number in the larger 1000-digit number
chunksWithoutZero :: Int -> [String]
chunksWithoutZero n = (filter (\str -> length str >= n) . filter (/= "") . splitOn "0" . show) thousandDigitNum
windowsOf :: Int -> [a] -> [[a]]
windowsOf n = drop (n-1) . go []
where
go acc [] = acc
go acc lst = go (lst':acc) (tail lst)
where
lst' = take n lst

View File

@@ -0,0 +1,130 @@
import Debug.Trace (trace)
import Graphics.Rendering.Chart.Backend.Cairo
import Graphics.Rendering.Chart.Easy
{-
Special Pythagorean Triplet
Problem 9
A Pythagorean triplet is a set of three natural numbers, `a < b < c`, for which,
`a^2 + b^2 = c^2`.
For example, `3^2 + 4^2 = 9 + 16 = 25 = 5^2`.
There exists exactly one Pythagorean triplet for which `a + b + c = 1000`.
Find the product `abc`.
-}
main :: IO ()
main = do
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 :: [Integer]
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 x = takeWhile (\(a,b,c) -> a + b + c == 1000) $ primitiveTriplesUnder x
euclid'sFormula :: Num c => (c, c) -> (c, c, c)
euclid'sFormula (m, n) = (a,b,c)
where
a = m^2 - n^2
b = 2*m*n
c = m^2 + n^2
listOfMNs :: Integer -> [(Integer, Integer)]
listOfMNs x =
[ (m,n)
| n <- [2,4..x] -- one of them is even
, m <- [n+1,n+3..x]
, gcd m n == 1 -- coprime
]
listOfMNs' :: Integer -> [(Integer, Integer)]
listOfMNs' x =
[ (m,n)
| n <- [2,4..] -- one of them is even
, m <- [n+1,n+3..]
, gcd m n == 1 -- coprime
, a m n + b m n + c m n <= x
] where
a m n = m^2 - n^2
b m n = 2*m*n
c m n = m^2 + n^2
primitiveTriplesUnder :: Integer -> [(Integer, Integer, Integer)]
primitiveTriplesUnder = map euclid'sFormula . listOfMNs
test :: [(Integer, Integer, Integer)]
test = [ (a,b,c)
| a <- [3..],
b <- take 10 [a+1..],
c <- takeWhile (\c -> a^2 + b^2 <= c^2) [b+1..]
]
ls :: [(Integer, Integer)]
ls = filter (\(m,n) -> gcd m n == 1) $ zip [5,9..] [2,4..]
diags :: Integer -> [(Integer, Integer)]
diags n = [(x,y) | x<-[0..n], y<-[0..n]]
graph :: IO ()
graph = toFile def "test.png" $ do
layout_title .= "Points"
plot (line "points" [ [ (x,y) | (x,y) <- listOfMNs 30] ])
-- main'' = print ans'
ans' :: Integer -> [(Integer, Integer, Integer)]
ans' limit = [(a, b, c)
| a <- [1 .. limit]
, b <- [a + 1 .. limit]
, c <- [limit - a - b]
, b < c
]
{-
- Solution to Project Euler problem 9
- Copyright (c) Project Nayuki. All rights reserved.
-
- https://www.nayuki.io/page/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.
-- perim = 1000
-- main = putStrLn (show ans)
-- ans = head [a * b * (perim - a - b) | a <- [1..perim], b <- [a+1..perim], isIntegerRightTriangle a b]
-- isIntegerRightTriangle a b = a < b && b < c
-- && a * a + b * b == c * c
-- where c = perim - a - b

28
src/python/2.py Normal file
View File

@@ -0,0 +1,28 @@
fibs2 = [1, 2, 3, 5, 8, 13]
i = 1
j = 2
b = 0
n = 4000000
fibs = []
fibs.append(i)
fibs.append(j)
while b < n:
b = i + j
if b < n:
fibs.append(b)
else:
fibs
i = j
j = b
count = 0
for fib in fibs:
if (fib % 2) == 0:
count += fib
else:
count += 0
print(count)