Project Euler/20

From Esolang
Jump to navigation Jump to search

Back to User:ProjectEuler

Project Euler Problem 20 is a problem related to factorial. Find the "digit sum" of the factorial of 100. To learn more about "digit sum", click here.

This article is not detailed enough and needs to be expanded. Please help us by adding some more information.

Implementations

Aheui

The decimal multiplication algorithm has been improved and now it works for an arbitrarily large number multiplied by any number below a million in any integer base below a million.

밤발발따따빠박따뿌터너벌
ㅇㅇㅇ쑥너벌벌머차바싹볼
희ㅇㅇ뿌터너벌벌서
몽다석차바싼숙머오쎤석러더벌벌썩ㅇㅇ너
ㅇㅇㅇㅇ무선빠사빠싹삭따싼산다빠발발도
ㅇㅇ먀썩뻐ㅇㅇㅇ요

C

#include <stdio.h>
int a[320]={1},k,l,r;

void flow(int d[]){
    int i;
    for(i=0;i<319;++i){
        d[i+1]+=d[i]/10;
        d[i]%=10;
    }
}
int main(){
	for(k=1;k<=100;++k){
		for(l=0;l<320;++l){
            	 a[l]*=k;
        	}
        	flow(a);
	}
	for(l=0;l<320;++l){
		r+=a[l];
	}
	printf("%d",r);
    return 0;
}

I fuck, you fuck

There's a fucker named a
There's a fucker named b
Fuck b 100 times
while b is fucked
b fucks a again
I unfuck b
end fuck
There's a fucker named c
while a is fucked
c unfucks c
Fuck c 10 times
a unfucks c over and over
c fucks b
c unfucks c
Fuck c 10 times
a unfucks c again
a unfucks a
c fucks a
end fuck
b fucks you

Python

# Euler Problem 20
# by Europe2048

import math
def sumdigits(n):
	sum = 0
	for i in str(n):
		sum = sum + int(i)
	return sum
print(sumdigits(math.factorial(100)))

Alternate implenentation (shorter), by None1:

print(sum(map(int,str(__import__("math").factorial(100)))))

Version by Xi-816:

print(sum([int(i)for i in __import__("math").factorial(100)]))

External resources

  • A004152, a related sequence on OEIS. The 101st term is the solution.
  • Problem 20 on Project Euler Official Website (not available)
  • Problem 20 on Project Euler Mirror