From 1580cc33b6ff198e66b15aab797318618bb83161 Mon Sep 17 00:00:00 2001 From: Charles Date: Sun, 18 Aug 2019 10:39:20 +0200 Subject: haskell problem 63 (brute force) --- haskell/wip/063-powerful_digit_counts.hs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 haskell/wip/063-powerful_digit_counts.hs (limited to 'haskell/wip') diff --git a/haskell/wip/063-powerful_digit_counts.hs b/haskell/wip/063-powerful_digit_counts.hs new file mode 100644 index 0000000..31f8912 --- /dev/null +++ b/haskell/wip/063-powerful_digit_counts.hs @@ -0,0 +1,20 @@ +-- Powerful digit counts +-- +-- Problem 63 +-- The 5-digit number, 16807=7^5, is also a fifth power. Similarly, the 9-digit number, +-- 134217728=8^9, is a ninth power. +-- +-- How many n-digit positive integers exist which are also an nth power? + + +-- when should i stop ? (maybe stop searching when x ^ y has more than y digits) +main = do + -- print (numbers) + print (length numbers) + +numbers = [x ^ y| x <- [1..200], y <- [1..x], digitCount (x ^ y) == y] + +digitCount :: Integer -> Integer +digitCount n + | n < 10 = 1 + | otherwise = 1 + digitCount (n `div` 10) -- cgit