Skip to content

Instantly share code, notes, and snippets.

View yuuki's full-sized avatar

Yuuki TSUBOUCHI yuuki

View GitHub Profile
def fact(n: Int) : Int = n match {
case 0 => 1
case _ => n * fact(n-1)
}
println(fact(100).toString.map(_.toInt).sum)
# 48
println((BigInt(1) to 100).product.toString map{_.asDigit} sum)
# 648
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(:+)
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
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 $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
test for daily coding
@yuuki
yuuki / perl-module-list.sh
Created December 16, 2012 06:24
Perlのモジュール一覧
cpan -l 2>/dev/null | cut -f1
@yuuki
yuuki / perl_arch.sh
Created December 18, 2012 16:52
Perl内部でもってるアーキテクチャ名
perl -MConfig -e 'print $Config{archname}'
cmd_push() {
parse_remote_name "$@"
if [ -z "$REMOTE" ]; then
REMOTE="$ORIGIN"
fi
name_or_current
# sanity checks
require_clean_working_tree
require_branch "$BRANCH"