diff options
| -rw-r--r-- | challenge-051/yet-ebreo/perl/ch-1.pl | 50 | ||||
| -rw-r--r-- | challenge-051/yet-ebreo/perl/ch-2.pl | 457 |
2 files changed, 507 insertions, 0 deletions
diff --git a/challenge-051/yet-ebreo/perl/ch-1.pl b/challenge-051/yet-ebreo/perl/ch-1.pl new file mode 100644 index 0000000000..5a2139d31b --- /dev/null +++ b/challenge-051/yet-ebreo/perl/ch-1.pl @@ -0,0 +1,50 @@ +#!/usr/bin/perl + +# Given an array @Lof integers. +# Write a script to find all unique triplets such +# that a + b + c is same as the given target T. Also make sure a <= b <= c. +# Here is wiki page for more information. +# Example: +# @L = (-25, -10, -7, -3, 2, 4, 8, 10); +# One such triplet for target 0 i.e. -10 + 2 + 8 = 0. + +use strict; +use warnings; +use feature 'say'; + +#Solution from the wikipage +sub get_triplets { + my ($list, $target) = @_; + + my @sorted = sort { $a - $b } @{$list}; + + for my $i (0..@sorted-2) { + my $a = $sorted[$i]; + my $start = $i + 1; + my $end = @sorted - 1; + + while ($start < $end) { + my $b = $sorted[$start]; + my $c = $sorted[$end]; + + if ($a + $b + $c == $target) { + say "$a $b $c"; + $start++; + $end--; + } elsif ($a + $b + $c > $target) { + $end--; + } else { + $start++; + } + } + } +} +my @L = [25, -10, -7, -3, 2, 4, 8, 10]; +my $target = 0; +get_triplets(@L, $target); + +=begin +perl .\ch-1.pl +-10 2 8 +-7 -3 10 +=cut
\ No newline at end of file diff --git a/challenge-051/yet-ebreo/perl/ch-2.pl b/challenge-051/yet-ebreo/perl/ch-2.pl new file mode 100644 index 0000000000..1642d3b8c6 --- /dev/null +++ b/challenge-051/yet-ebreo/perl/ch-2.pl @@ -0,0 +1,457 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use feature 'say'; + + +sub is_colorful { + my @digits = pop =~ /./g; + my @seq = (@digits, $digits[0] * $digits[1], $digits[1]* $digits[2], $digits[0] * $digits[1] * $digits[2]); + return "@seq "!~ /(\d+ )\1/ +} + +say "List of 3-digit colorful numbers:"; +for my $n (100..999) { + is_colorful ($n) && say $n; +} + +=begin +perl .\ch-2.pl +List of 3-digit colorful numbers: +213 +214 +215 +216 +217 +218 +219 +231 +234 +235 +237 +238 +239 +241 +243 +245 +246 +247 +249 +251 +253 +254 +256 +257 +258 +259 +261 +263 +264 +265 +267 +268 +269 +271 +273 +274 +275 +276 +278 +279 +281 +283 +284 +285 +286 +287 +289 +291 +293 +294 +295 +296 +297 +298 +312 +314 +315 +316 +317 +318 +319 +321 +324 +325 +327 +328 +329 +341 +342 +345 +346 +347 +348 +349 +352 +354 +356 +357 +358 +359 +361 +362 +364 +365 +367 +368 +369 +371 +372 +374 +375 +376 +378 +379 +381 +382 +384 +385 +386 +387 +389 +391 +392 +394 +395 +396 +397 +398 +412 +413 +415 +416 +417 +418 +419 +421 +423 +425 +426 +427 +429 +431 +432 +435 +436 +437 +438 +439 +451 +452 +453 +456 +457 +458 +459 +461 +462 +463 +465 +467 +468 +469 +471 +472 +473 +475 +476 +478 +479 +481 +482 +483 +485 +486 +487 +489 +491 +492 +493 +495 +496 +497 +498 +512 +513 +514 +516 +517 +518 +519 +521 +523 +524 +526 +527 +528 +529 +531 +532 +534 +536 +537 +538 +539 +541 +542 +543 +546 +547 +548 +549 +561 +562 +563 +564 +567 +568 +569 +571 +572 +573 +574 +576 +578 +579 +581 +582 +583 +584 +586 +587 +589 +591 +592 +593 +594 +596 +597 +598 +612 +613 +614 +615 +617 +618 +619 +623 +624 +625 +627 +628 +629 +631 +632 +634 +635 +637 +638 +639 +642 +643 +645 +647 +648 +649 +651 +652 +653 +654 +657 +658 +659 +671 +672 +673 +674 +675 +678 +679 +682 +683 +684 +685 +687 +689 +691 +692 +693 +694 +695 +697 +698 +712 +713 +714 +715 +716 +718 +719 +721 +723 +724 +725 +726 +728 +729 +731 +732 +734 +735 +736 +738 +739 +741 +743 +745 +746 +748 +749 +752 +753 +754 +756 +758 +759 +761 +762 +763 +764 +765 +768 +769 +781 +782 +783 +784 +785 +786 +789 +791 +792 +793 +794 +795 +796 +798 +812 +813 +814 +815 +816 +817 +819 +821 +824 +825 +826 +827 +829 +831 +832 +834 +835 +836 +837 +839 +841 +842 +843 +845 +846 +847 +849 +851 +852 +853 +854 +856 +857 +859 +861 +862 +863 +864 +865 +867 +869 +871 +872 +873 +874 +875 +876 +879 +891 +892 +893 +894 +895 +896 +897 +912 +913 +914 +915 +916 +917 +918 +921 +923 +925 +926 +927 +928 +931 +932 +934 +935 +936 +937 +938 +941 +942 +943 +945 +946 +947 +948 +952 +953 +954 +956 +957 +958 +961 +962 +963 +964 +965 +967 +968 +971 +972 +973 +974 +975 +976 +978 +981 +982 +983 +984 +985 +986 +987 +=cut
\ No newline at end of file |
