Skip to content

Instantly share code, notes, and snippets.

View marcoonroad's full-sized avatar
🦋
the Future() has been CANCELLED and we .Restart() the DEAD Event[] from the past

Marco Aurélio da Silva marcoonroad

🦋
the Future() has been CANCELLED and we .Restart() the DEAD Event[] from the past
View GitHub Profile
/*
[DESAFIO / LANGUAGE WAR] Implemente um programa na sua linguagem favorita onde o usuário digita um número x, e o programa calcula o somatório dos x primeiros números pares da sequência fibonacci, e imprime a soma dos algarismos desse número.
Por exemplo, quando x = 5, a resposta é 17, pois:
1. A sequência fibonacci é 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,...
2. Os 5 primeiros números pares são 0, 2, 8 e 34, 144.
3. O somatório disso é 188.
4. Somando os algarismos, 1+8+8 = 17
@marcoonroad
marcoonroad / JustLangWar-Perl6.pl6
Last active August 29, 2015 14:06
Lento porém elegante, tente algo como "$ perl6 ThisScript.pl6 15" no terminal...
#!/usr/bin/perl6
use v6;
sub MAIN ($x) {
([+] ([+] ((^2, * + * ... *).grep(* %% 2))[^$x]).comb).say;
}
# [DESAFIO / LANGUAGE WAR]
#
module Fib using: Platform where
open Platform Prelude expose [+, parse, as-string, ~]
open Platform List expose [zip:using:, map:, take:, filter:, sum]
open Platform IO expose [read-line, print]
-- Typing things is currently cumbersome, but the type inference algorithm should catch 90% of this
let (Num a) => String -> a ::
x as-number = x parse
@marcoonroad
marcoonroad / cpl.pl6
Last active August 29, 2015 14:06
Jogo de caça-palavras aleatório.
#!/usr/bin/perl6
use v6;
# caça-palavras em P6
"Só um outro jogo de caça-palavras...".say;
"Diga o número de === colunas ~ linhas ===.".say;
my $limite = prompt "Qual o limite que você quer?" ~ " ";
my @numeros = ^$limite;
@marcoonroad
marcoonroad / multimutual.pl
Last active August 29, 2015 14:06
Only a experiment on Perl version 5.20...
#!/home/usuario/localperl/bin/perl
# multidispatch functions
use v5.20;
use feature qw/ say signatures /;
use strict;
use warnings;
#------------------------------------------------#
@marcoonroad
marcoonroad / fact.s
Created September 26, 2014 06:54
Recursive Factorial using ARM Stack as a Return Stack mixed with Data Stack...
.text
.macro dec reg, cond
sub\cond \reg, \reg, #1
.endm
.macro push reg, cond
str\cond \reg, [sp], #-4
.endm
@marcoonroad
marcoonroad / LinkedList.pl
Last active August 29, 2015 14:06
Just another Lisp/Prolog-like lists test.
#!/home/user/localperl/bin/perl
use v5.20;
use strict;
use warnings;
# linked lists test
use feature qw| say signatures |;
use Data::Dumper;
@marcoonroad
marcoonroad / fib.fth
Created October 5, 2014 23:21
Fibonacci written in Forth.
\ == recursive version ==
: fib
dup 2 <= if
drop 1
else
dup 1 - recurse
swap 2 - recurse +
then ;
@marcoonroad
marcoonroad / fib.s
Last active July 9, 2020 03:02
Fibonacci written in ARM GNU Assembler.
.text
.global _start
_start:
@ call the fib(10)
mov r0, #10
bl _fib
@ clear registers
@marcoonroad
marcoonroad / multi.pl
Created October 12, 2014 04:35
Um simples teste de funções com múltiplo despacho e recursão...
#!/home/user/localperl/bin/perl
use v5.20;
use strict;
use warnings;
use feature qw| say signatures |;
my %multi;
sub def ($name, $param, $lambda) {