@jjmerelo
cc-by-sa
function isελληνικά(input) {
const rελληνικά = /^\p{Script=Greek}$/u
return rελληνικά.test(input)
}
console.log(isελληνικά('π'));
from functools import reduce;
def fib(n):
return reduce( lambda prev,this: prev+[ prev[-2]+prev[-1] ], \
range(1,n+1), \
[1,1] )
print(fib(12))
val no = "me cambies"
(defn hasta-cero [n]
(if (> n 0)
(do
(print n, "... ")
(hasta-cero (dec n))
)
)
)
(hasta-cero 3)
let secondNeedle: number =
3
let firstNeedle = "Hey"
let find = function ( needle, haystack ) {
for (let i of haystack) {
if ( needle === i ) {
return true
}
}
return false;
}
let randomList = ["Hey", 3]
let firstNeedle = "Hey"
let secondNeedle: number = 3
console.log( find( firstNeedle, randomList ) )
console.log( find( secondNeedle, randomList ) )
data class Resultado (val resultado: Int, val tesoro: Boolean)
fun main(args: Array<String>) {
val busca = fun(intento: Int): Resultado
{
val cosas = listOf( 3, 33, 333, 42, 1, 1, 111 )
if ( intento == 4 ) {
return Resultado( 42, true )
} else {
return Resultado( cosas[intento], false )
}
}
val (valor1, premio1) = busca( 2 )
println( "2 devuelve " + valor1 + " y tiene premio " + premio1 )
val (valor2, premio2) = busca( 4 )
println( "4 devuelve " + valor2 + " y tiene premio " + premio2 )
}
if
val puntos = (carta: String) => {
carta match {
case "As" => 11
case "3" => 10
case "J" => 2
case "Q" => 3
case "K" => 4
case _ => 0
}
}
println("As ", puntos("A"))
println("7 ", puntos("7"))
resultado = 1..100
|> Enum.filter(fn a -> rem(a,2) == 0 end)
|> Enum.map(fn a -> :math.pow(a,2) end)
|> Enum.reduce( &(&1 + &2) )
IO.puts resultado
@enum Suit ♣ ♦ ♥ ♠
@enum Palo Bastos Espadas Oros Copas
cadena( n::Int, s::Suit ) = string( n, " ", s )
cadena( n::Int, p::Palo ) = string( n, " de ", p )
println( cadena( 3, ♦) )
println( cadena( 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 "Primeros 15 %A" seq_15
struct Carta { figura: String, palo: &'static str }
trait Mira {
fn mira(self ) -> String;
}
impl Mira for Carta {
fn mira(self ) -> String {
self.figura + " de " + self.palo
}
}
fn main() {
let as_de_bastos = Carta { figura: "As".to_string(),
palo: "Bastos"
};
println!( "Carta → {}", as_de_bastos.mira() );
}
@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 "Collatz", @collatz[ $𝒾 ].elems }
default { @collatz[ $𝒾 ], @collatz[ $𝒾 ].elems }
}
}
for ^10 -> $þ {
my ($seq, $elems) = ⇈$þ;
say "Secuencia con $þ ", $seq.?Str eq "Collatz" ?? " es " !! " no es " , "Collatz";
}