@jjmerelo
| git.io/raku-fosdem20
cc-by-sa
function isελληνικά(input) {
const rελληνικά = /^\p{Script=Greek}$/u
return rελληνικά.test(input)
}
console.log(isελληνικά('π'));
(def elipsis (fn [n] (print "... ", n ) ))
(defn to-zero [n]
(if (> n 0)
(do
(elipsis [n])
(to-zero (dec n))
)
)
)
(to-zero 3)
data class Result (val result: Int, val treasure: Boolean)
fun main(args: Array<String>) {
val search = fun(attempt: Int): Result
{
val things = listOf( 3, 33, 333, 42, 1, 1, 111 )
if ( attempt == 4 ) {
return Result( 42, true )
} else {
return Result( things[attempt], false )
}
}
val (value1, prize1) = search( 2 )
println( "2 returns " + value1 + prize( prize1 ) )
val (value2, prize2) = search( 4 )
println( "4 returns " + value2 + prize( prize2 ) )
}
if
cascadesval points = (card: String) => {
card match {
case "Ace" => 11
case "3" => 10
case "J" => 2
case "Q" => 3
case "K" => 4
case _ => 0
}
}
println("Ace ", points("Ace"))
println("7 ", points("7"))
@enum Suit ♣ ♦ ♥ ♠
@enum Palo Bastos Espadas Oros Copas
toString( n::Int, s::Suit ) = string( n, " ", s )
toString( n::Int, p::Palo ) = string( n, " de ", p )
println( toString( 3, ♦) )
println( toString( 7, Bastos ) )
let horadam =
(0.0f, 1.0f)
|> Seq.unfold (fun (x, y) -> let z = 0.25f*x + 0.75f*y in Some(z, (y, z)))
|> Seq.append [0.0f; 1.0f]
let seq_15 = horadam |> Seq.take 15
printfn "First 15 %A" seq_15
struct Card { value: String, suit: &'static str }
trait Lookup {
fn lookup(self ) -> String;
}
impl Lookup for Card {
fn lookup(self ) -> String {
self.value + " of " + self.suit
}
}
fn main() {
let ace_of_clubs = Card { value: "Ace".to_string(),
suit: "♣"
};
println!( "Card → {}", ace_of_clubs.lookup() );
}
@jjmerelo
github.com/JJ
multi sub collatz( 1 ) { return [1] }
multi sub collatz( Int $a where $a %% 2 ) { return collatz( ($a/2).Int ).prepend( $a )}
multi sub collatz( $a where not $a %% 2 ) { return collatz( $a*3 + 1 ).prepend($a)}
my @collatz = lazy gather for ١..١٠٠٠ { take collatz( $_ ); }
1..100 ==> map( { @collatz[ $_ ] }) ==> grep( *.elems > 15 ) ==> my @long-chains;
sub prefix:<⇈> ( $𝒾 ) {
given @collatz[ $𝒾 ].elems {
when $_ > 15 { return @collatz[ $𝒾 ] but "15-Collatz", @collatz[ $𝒾 ].elems }
default { @collatz[ $𝒾 ], @collatz[ $𝒾 ].elems }
}
}
for ^10 -> $þ {
my ($seq, $elems) = ⇈$þ;
say "Sequence with $þ ", $seq.?Str eq "Collatz" ?? " is " !! " is not " , "15-Collatz";
}