tinycodinglm / misc /misc-0312.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame
2.79 kB
opencode trace
System You are an expert competitive programmer. You solve problems by analyzing requirements, designing algorithms, and writing clean, efficient code. When solving problems, explain your reasoning step by step before providing...

You are an expert competitive programmer. You solve problems by analyzing requirements, designing algorithms, and writing clean, efficient code. When solving problems, explain your reasoning step by step before providing the final solution.

User

Definition

Strong number is the number that the sum of the factorial of its digits is equal to number itself.

For example: 145, since

markdown
1! + 4! + 5! = 1 + 24 + 120 = 145

So, 145 is a Strong number.


Task

Given a number, Find if it is Strong or not.


Warm-up (Highly recommended)

Playing With Numbers Series


Notes

  • Number passed is always Positive.
  • Return the result as String

Input >> Output Examples

markdown
strong_num(1) ==> return "STRONG!!!!"

Explanation:

Since , the sum of its digits' factorial of (1) is equal to number itself (1) , Then its a Strong .


markdown
strong_num(123) ==> return "Not Strong !!"

Explanation:

Since the sum of its digits' factorial of 1! + 2! + 3! = 9 is not equal to number itself (123) , Then it's Not Strong .


markdown
strong_num(2)  ==>  return "STRONG!!!!"

Explanation:

Since the sum of its digits' factorial of 2! = 2 is equal to number itself (2) , Then its a Strong .


markdown
strong_num(150) ==> return "Not Strong !!"

Explanation:

Since the sum of its digits' factorial of 1! + 5! + 0! = 122 is not equal to number itself (150), Then it's Not Strong .




Playing with Numbers Series

Playing With Lists/Arrays Series

For More Enjoyable Katas


ALL translations are welcomed

Enjoy Learning !!

Zizou

Starter code:
def strong_num(number):

Assistant

def strong_num(number):
# Precompute factorials for digits 0-9
factorials = [1] * 10
for i in range(1, 10):
factorials[i] = factorials[i-1] * i

markdown
sum_fact = 0
for d in str(number):
    sum_fact += factorials[int(d)]

return "STRONG!!!!" if sum_fact == number else "Not Strong !!"