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
sub getHammingNumbers(int $howMany, boolean $all --> List[BigInteger]) { | |
my $three = BigInteger.Parse("3"); | |
my $five = BigInteger.Parse("5"); | |
my $completedNumbers = List[BigInteger].new; | |
my $frontierSet = SortedSet[BigInteger].new; | |
$completedNumbers.Add(BigInteger.One); | |
$frontierSet.Add(BigInteger.op_LeftShift(BigInteger.One, 1)); | |
$frontierSet.Add(BigInteger.One * $three); | |
$frontierSet.Add(BigInteger.One * $five); | |
loop (my $count = 1; $count < $howMany; $count++) { |
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
my $three = BigInteger.Parse("3"); | |
my $five = BigInteger.Parse("5"); | |
sub updateFrontier(BigInteger $value, SortedSet[BigInteger] $frontierSet) { | |
$frontierSet.Add(BigInteger.op_LeftShift($value, 1)); | |
$frontierSet.Add($value * $three); | |
$frontierSet.Add($value * $five) | |
} | |
sub getHammingNumbers(int $howMany, boolean $all --> List[BigInteger]) { |
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
my $limit = 32; | |
sub powers_of ($radix) { 1,[\*] $radix xx * } | |
my @hammings = | |
( powers_of(2)[^ $limit ] X* | |
( powers_of(3)[^($limit * 2/3)] X* | |
powers_of(5)[^($limit * 1/2)] | |
) | |
).sort; |
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
sub getHammingNumbers(int $howMany, boolean $all --> List[BigInteger]) { | |
my $three = BigInteger.Parse("3"); | |
my $five = BigInteger.Parse("5"); | |
my $completedNumbers = List[BigInteger].new; | |
my $frontierSet = SortedSet[BigInteger].new; | |
$completedNumbers.Add(BigInteger.One); | |
$frontierSet.Add(BigInteger.op_LeftShift(BigInteger.One, 1)); | |
$frontierSet.Add(BigInteger.One * $three); | |
$frontierSet.Add(BigInteger.One * $five) | |
loop (my $count = 1; $count < $howMany; $count++) { |
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
class knapsackItem{ | |
has string $!name; has int $!weight;has int $!unit | |
method ToString(-->string) { | |
return self.name ~ ' ' ~ self.weight ~ ' ' ~ self.unit | |
} | |
} | |
sub makeItem(string $n, int $w, int $u --> knapsackItem) { | |
my $i = knapsackItem.new; | |
$i.name = $n; $i.weight = $w; $i.unit = $u; | |
return $i |
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
my $count = 0; | |
my Int64 $i = 1; | |
loop (; $i <= 100000;) { | |
my $sqr = $i * $i; | |
my $sqrStr = "$sqr"; | |
loop (my $j = 0; $j < $sqrStr.Length; $j=$j+1) { | |
my $left = $sqrStr.Substring(0, $j); | |
if ($left == "") { $left = "0"; } | |
my $firstNum = Int64.Parse($left); | |
my $secNum = Int64.Parse($sqrStr.Substring($j)); |
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
sub kaprekar( Int $n ) { | |
my $sq = $n ** 2; | |
for 0 ^..^ $sq.chars -> $i { | |
my $x = +$sq.substr(0, $i); | |
my $y = +$sq.substr($i) || return; | |
return True if $x + $y == $n; | |
} | |
False; | |
} | |
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
using Niecza; | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.IO; | |
public partial class Builtins { | |
public static Variable sprintf(Variable[] args) { |
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
using Niecza; | |
using System; | |
using System.Collections.Generic; | |
using System.Diagnostics; | |
using System.IO; | |
public partial class Builtins { | |
public static Variable sprintf(Variable[] args) { |
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 strict; | |
use warnings; | |
package Troller; | |
use JSON::XS; # yum install perl-JSON-XS | |
use File::Slurp; # yum install perl-File-Slurp | |
use DirHandle; | |
use FileHandle; | |
use Time::Local; |