CARVIEW |
Select Language
HTTP/2 200
date: Sat, 11 Oct 2025 10:36:25 GMT
content-type: text/html; charset=UTF-8
server: cloudflare
x-frame-options: DENY
x-content-type-options: nosniff
x-xss-protection: 1;mode=block
vary: accept-encoding
cf-cache-status: DYNAMIC
content-encoding: gzip
set-cookie: _csrf-frontend=fb78cf141855d268fd7aa9cbc5edd87fad7f211e00752d139752e7768f694874a%3A2%3A%7Bi%3A0%3Bs%3A14%3A%22_csrf-frontend%22%3Bi%3A1%3Bs%3A32%3A%22A-wTgVrHOOyIYKDlKcdTZxM84uS56cX_%22%3B%7D; HttpOnly; Path=/
cf-ray: 98cdb7614fd8c1b5-BLR
Project Euler, Problem #9, Haskell - Pastebin.com
SHARE
TWEET

Project Euler, Problem #9, Haskell
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 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.
- -- A more efficient solution
- ac :: Integral t => t -> [t]
- ac c =
- [ a * b * c
- | a <- [1 .. div (1000 - c) 2 - 1]
- , let b = (1000 - c) - a
- , a ^ 2 + b ^ 2 == c ^ 2
- ]
- main :: IO ()
- main = print $ head $ concatMap ac [997,996 .. 3]
- -- 31875000
- -- real 0m0,330s
- -- user 0m0,317s
- -- sys 0m0,012s
- -- ################################################################################################
- -- A less efficient solution
- main :: IO ()
- main =
- print $
- head
- [ x * y * z
- | x <- [1 .. 1000]
- , y <- [1 .. 1000]
- , let z = 1000 - (x + y)
- , x + y + z == 1000
- , x ^ 2 + y ^ 2 == z ^ 2
- , x < y && y < z
- ]
- -- 31875000
- -- real 0m0,782s
- -- user 0m0,777s
- -- sys 0m0,004s
Advertisement
Add Comment
Please, Sign In to add comment
-
⭐✅ MAKE $2500 IN 15 MIN ✅ NEVER SEEN BEFORE ⭐...
JavaScript | 26 sec ago | 0.24 KB
-
⭐ ✅ Free Products Method ✅ ✅ NEVER SEEN BEFOR...
JavaScript | 37 sec ago | 0.24 KB
-
⭐ G2A Bug ⭐ (Get more on BTC swaps) ✅ NEVER S...
JavaScript | 46 sec ago | 0.24 KB
-
⭐✅ Jack's Profit Method ✅ NEVER SEEN BEF...
JavaScript | 55 sec ago | 0.24 KB
-
⭐✅ Online Marketplace Exploit ✅ NEVER SEEN BE...
JavaScript | 1 min ago | 0.24 KB
-
⭐✅ Trading Profit Method ✅ NEVER SEEN BEFORE...
JavaScript | 1 min ago | 0.24 KB
-
⭐ Instant BTC Profit Method ✅ NEVER SEEN BEFO...
JavaScript | 1 min ago | 0.24 KB
-
Free Crypto Method (NEVER SEEN BEFORE)⭐⭐ 5
JavaScript | 1 min ago | 0.24 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand