»»» 18:07 ««« [ Moumou ] !shadok 231 »»» 18:07 ««« [ Moumou ] meuzobumeu
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
void shadok(unsigned int n)
{
char *output, *tmp;
int size;
size = (int)(floor(log(n)/log(4)) + 1);
output = malloc(size*3 + 1); // 3 caractères pour 'meu'
if(!output)
return;
tmp = output + size*3;
*tmp-- = '\0';
while(n) {
switch(n%4) {
case 0: // ga
*tmp-- = 'a';
*tmp-- = 'g';
break;
case 1: // bu
*tmp-- = 'u';
*tmp-- = 'b';
break;
case 2: // zo
*tmp-- = 'o';
*tmp-- = 'z';
break;
case 3: // meu
*tmp-- = 'u';
*tmp-- = 'e';
*tmp-- = 'm';
break;
default:
break;
}
n /= 4;
}
printf("%s\n", ++tmp);
free(output);
}
unsigned int humain(char *chaine)
{
unsigned int n;
char c;
n = 0;
while((c = *chaine)) {
n *= 4;
switch(c) {
case 'g': // ga
if(*(chaine+1) != 'a')
goto error;
break;
case 'b': // bu
if(*(chaine+1) == 'u')
n += 1;
else
goto error;
break;
case 'z': // zo
if(*(chaine+1) == 'o')
n += 2;
else
goto error;
break;
case 'm':
if(*(chaine+1) == 'e' &&
*(chaine+2) == 'u') {
n += 3;
chaine++;
}
else
goto error;
break;
default: error:
fprintf(stderr, "[Erreur] C'est pas du shadok : %s", chaine);
exit(-1);
}
chaine += 2;
}
return n;
}
int main(int argc, char *argv[])
{
// stuff1(argc, argv);
char *a;
a = malloc(1024);
if(!a) {
fprintf(stderr, "Pas assez de mémoire! :|");
exit(-2);
}
a[1023] = '\0';
if(argc < 2) {
printf("Renvoie le nombre suivant en shadok: ");
fscanf(stdin, "%s", a);
}
else // argc >= 2
strncpy(a, argv[1], 1023);
shadok(humain(a) + 1);
system("Pause");
return 0;
}

alias shadok {
if ($remove($1,0,1,2,3,4,5,6,7,8,9) !== $null || $1 == $null) { halt }
var %nombre = $1
%nombre = $base(%nombre,10,4)
%nombre = $replace(%nombre,0,ga)
%nombre = $replace(%nombre,1,bu)
%nombre = $replace(%nombre,2,zo)
%nombre = $replace(%nombre,3,meu)
return %nombre
}
alias unshadok {
var %shadok = $1
%shadok = $replace(%shadok,ga,0)
%shadok = $replace(%shadok,bu,1)
%shadok = $replace(%shadok,zo,2)
%shadok = $replace(%shadok,meu,3)
if ($remove(%shadok,0,1,2,3,4,5,6,7,8,9) !== $null || $1 == $null) { halt }
return $base(%shadok,4,10)
}
on 1:TEXT:!shadok *:#:{
msg $chan $shadok($2-)
}
on 1:TEXT:!unshadok *:#:{
msg $chan $unshadok($2-)
}
on 1:INPUT:#:{
if ($1 == !shadok) { say $shadok($2-) }
if ($1 == !unshadok) { say $unshadok($2-) }
}
let alias chiffre =
match chiffre with
| 0 -> "ga"
| 1 -> "bu"
| 2 -> "zo"
| _ -> "meu";;
let shdk nombre =
let resultat = ref "" in
let nbre = ref nombre in
while !nbre <> 0 do
begin
resultat := (alias (!nbre mod 4)) ^ !resultat;
nbre := !nbre / 4;
end
done;
!resultat;;
let shadok nombre =
match nombre with
| 0 -> "ga"
| _ when nombre > 0 -> shdk nombre
| _ -> "- " ^ (shdk (- nombre));;


let shadok =
let alias = function
0 -> "ga"
| 1 -> "bu"
| 2 -> "zo"
| _ -> "meu"
in let rec aux = function
0 -> ""
| nombre -> aux (nombre / 4) ^ alias (nombre mod 4)
in function
0 -> "ga"
| n when n > 0 -> aux n
| n -> "- " ^ aux (-n)

alias(chiffre) Func If chiffre=0:Return "ga" If chiffre=1:Return "bu" If chiffre=2:Return "zo" Return "meu" EndFunc shdk(nombre) Func Local resultat ""»resultat While nombre=/=0 alias(mod(nombre,4))&resultat»resultat int(nombre/4)»nombre EndWhile Return resultat EndFunc shadok(nombre) Func If nombre=0:Return "ga" If nombre>0:Return shdk(nombre) Return "- "&shdk(-nombre) EndFunc

Moumou :
Sally > Ok ok, le récursif c'est plus joli ... Mais le zéro me faisait chierMais en fait en impératif aussi il fallait distinguer le cas, j'avoue, j'ai merdouillé :/
)
type mot = Ga | Bu | Zo | Meu
type nombre_complexe = {nb_objets : mot; nb_poubelles : nombre}
and nombre = Chiffre of mot | Beaucoup of nombre_complexe
exception Y_a_plus_de_mots
let origine = Chiffre Ga
let rec string_of_nombre =
let string_of_mot = function
Ga -> "ga"
| Bu -> "bu"
| Zo -> "zo"
| Meu -> "meu"
in function
Chiffre c -> string_of_mot c
| Beaucoup n -> string_of_nombre n.nb_poubelles ^ string_of_mot n.nb_objets
let rec suivant n =
let jette_tout () =
Beaucoup
{nb_objets = Ga;
nb_poubelles = match n with
Chiffre _ -> Chiffre Bu
| Beaucoup n -> suivant n.nb_poubelles}
in let suivant = function
Ga -> Bu
| Bu -> Zo
| Zo -> Meu
| _ -> raise Y_a_plus_de_mots
in try
match n with
Chiffre c -> Chiffre (suivant c)
| Beaucoup n -> Beaucoup
{nb_objets = suivant n.nb_objets;
nb_poubelles = n.nb_poubelles}
with Y_a_plus_de_mots -> jette_tout ()
let nombre_of_int n =
let ( * ) a b c = a (b c) in
let f = ref (function x -> x) in
for i = 1 to n do
f := suivant * !f
done;
!f origine
let shadok n = print_endline (string_of_nombre (nombre_of_int n))