Data update

This commit is contained in:
Ingy döt Net 2025-08-12 11:43:10 -07:00
parent 4924dd0264
commit cb74b7914d
10 changed files with 60 additions and 11 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
/*.ys
/Cache/
/Meta/
/rosettacode.log

View File

@ -0,0 +1 @@
../../Task/Luhn-test-of-credit-card-numbers/YAMLScript

View File

@ -0,0 +1 @@
../../Task/Validate-International-Securities-Identification-Number/YAMLScript

View File

@ -1,8 +1,9 @@
!YS-v0
defn main(input):
say: read-string(input)
.map(best-shuffle):vec
defn main(*inputs):
each input inputs: !:say
apply format '%s, %s, (%d)':
best-shuffle(input)
defn best-shuffle(s):
ref =: s:group-indices:cycles

View File

@ -1,6 +1,7 @@
!YS-v0
defn main(x):
if x:even?:
say: "$x is even"
say: "$x is odd"
defn main(*xs):
each x xs:
if x:even?:
say: "$x is even"
say: "$x is odd"

View File

@ -1,7 +1,10 @@
!YS-v0
defn main(n=10):
say: "$n! -> $factorial(n)"
defn main(*ns):
each n ns:
say: "$n! -> $factorial(n)"
defn factorial(x):
2 .. x: .mul(*)
if x <= 2:
(x ||| 1)
(2 .. x).mul(*)

View File

@ -0,0 +1,13 @@
proc multiply { a b args } {
set product 1
foreach m [list $a $b {*}$args] {
set product [expr {$product * $m}]
}
return $product
}
puts stdout [multiply 3 4 7 9 -2 -5 ]

View File

@ -17,7 +17,7 @@ gcd(a,b)
printGCD(a,b)
{
console.printLineFormatted("GCD of {0} and {1} is {2}", a, b, gcd(a,b))
Console.printLineFormatted("GCD of {0} and {1} is {2}", a, b, gcd(a,b))
}
public program()

View File

@ -0,0 +1,10 @@
!YS-v0
defn main(*nums):
each cc nums:
say: "$cc - $if(cc:luhn? 'valid' 'invalid')"
defn luhn?(cc):
map(mul cc:digits:reverse [1 2]:cycle)
.map(\(I(_ / 10) + (_ % 10))):sum
.mod(10):zero?

View File

@ -0,0 +1,18 @@
!YS-v0
defn main(*nums):
each isin nums:
say: "$isin - $if(isin:isin? 'valid' 'invalid')"
defn isin?(isin):
isin.re-matches(/[A-Z]{2}[A-Z0-9]{9}[0-9]/) &&
isin.map(b36-10).apply(str):luhn?
defn b36-10(c):
c =: c:I - 48
if c > 9: (c - 7) c
defn luhn?(cc):
map(mul cc:digits:reverse [1 2]:cycle)
.map(\(I(_ / 10) + (_ % 10))):sum
.mod(10):zero?