Skip to content

Instantly share code, notes, and snippets.

View yuuki's full-sized avatar

Yuuki TSUBOUCHI yuuki

View GitHub Profile
use 5.010;
use List::Util qw(sum);
my $digit = 1;
while (10**$digit <= 9**5*$digit) { ++$digit; };
say sum(grep { my $n = $_; $n eq sum(map { $_**5 } split(//, $n)) } 2..9**5*$digit);
# => 443839
use 5.010;
use Math::BigInt;
my @list = map { my $b = $_; map { Math::BigInt->new($_) ** $b } 2..100 } 2..100;
say scalar do { my %s; grep { !$s{$_}++ } @list }; # uniq
# 9183
use 5.010;
use List::Util qw(sum);
my @maxs = map { $_ ** 2 } map { 2 * $_ - 1 } 1 .. 501;
my $step = sub { my $i = shift; ($i + 1) * 2; };
say sum(map { $maxs[$_] * 4 + $step->($_) * 6 } 0 .. ($#maxs-1)) + $maxs[$#maxs];
# 669171001
def d(n)
t = (2..Math.sqrt(n).floor).select{|i| n % i == 0}
([1] + t + t.map{|i| n/i}).inject(:+)
end
amicable_num = (2...10000).select do |a|
b = d(a)
a == d(b) and a != b
end
puts amicable_num.inject(:+)
println((BigInt(1) to 100).product.toString map{_.asDigit} sum)
# 648
def fact(n: Int) : Int = n match {
case 0 => 1
case _ => n * fact(n-1)
}
println(fact(100).toString.map(_.toInt).sum)
# 48
use 5.010;
# チート
use Date::Simple ('ymd');
use Date::Range;
my $range = Date::Range->new(ymd(1901, 1, 1), ymd(2000, 12, 31));
my @dates = grep { $_->day == 1 and $_->day_of_week == 0 } $range->dates;
say $#dates + 1;
data = %w/
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
print(sum((int(s) for s in list(str(2**1000)))))
# 1366
digits = Enumerator.new do |y|
n = 2**1000
while n > 0 do
y << n % 10
n /= 10
end
end
puts digits.inject(:+)
# 1366