This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fact(n: Int) : Int = n match { | |
case 0 => 1 | |
case _ => n * fact(n-1) | |
} | |
println(fact(100).toString.map(_.toInt).sum) | |
# 48 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
println((BigInt(1) to 100).product.toString map{_.asDigit} sum) | |
# 648 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(:+) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test for daily coding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cpan -l 2>/dev/null | cut -f1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
perl -MConfig -e 'print $Config{archname}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmd_push() { | |
parse_remote_name "$@" | |
if [ -z "$REMOTE" ]; then | |
REMOTE="$ORIGIN" | |
fi | |
name_or_current | |
# sanity checks | |
require_clean_working_tree | |
require_branch "$BRANCH" |