Bonjour à tous,
Les jeunes enfants suédois apprennent un langage SUPER SECRET, le Rövarspråket !
Le Rövarspråket n'est pas très compliqué, vous prenez un mot et vous remplacez les consonnes par la consonne doublé avec un o au milieu. Le b devient bob, le r devient ror, ect... Les voyelles ne sont pas modifié, c'est fait pour le Suédois mais cela fonctionne pour le Français.
ATTENTION, C'est un code secret Suèdois, si vous le partagez vous serez obligé de manger du Surströmming.
INPUT
"Bonjour ca va"
OUTPUT
"boboujojouror coca vova"
BONUS
Faire le décodage aussi !
#include <stdio.h>
#include <stdlib.h>
int is_cons(int c) {
return isalpha(c) && c != 'A' && c != 'E' && c != 'I' && c != 'O' && c != 'U' && c != 'Y'
&& c != 'a' && c != 'e' && c != 'i' && c != 'o' && c != 'u' && c != 'y';
}
int main() {
int c;
while(!feof(stdin) && !ferror(stdin) && c != '\n') {
c = fgetc(stdin);
if(is_cons(c))
printf("%co", c);
printf("%c", c);
}
}
import System.IO
isConsonant :: Char -> Bool
isConsonant = (`elem` "bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ")
rovarspraket :: String -> String -> String
rovarspraket [] out = out
rovarspraket (x:xs) out =
rovarspraket xs $ out ++ if isConsonant x then [ x, 'o', x ] else [ x ]
main :: IO ()
main = do
putStr "Saisissez une chaine : "
hFlush stdout
input <- getLine
let a = rovarspraket input ""
putStr a
putStr "\n"
open Char
let voyelle c =
match lowercase c with
| 'a' | 'e' | 'i' | 'o' | 'u' | 'y' -> true
| _ -> false
let consonne c =
match lowercase c with
| 'a' .. 'z' when not (voyelle c) -> true
| _ -> false
let soc c =
String.make 1 c
let swe_of_fr c =
if (consonne c) then (soc c)^"o"^(soc (lowercase c)) else (soc c)
let rajkcqoinoqeiufbi s =
let rec loop ns i =
if i < String.length s then loop (ns^(swe_of_fr s.[i])) (i+1) else ns
in loop "" 0
Pour tester le code de @dead, ajoutez à la fin du fichier :
let _ = print_string (rajkcqoinoqeiufbi "Bonjour ca va")
Une version en io pour le fun (directement traduit du code Haskell) :
isConsonant := method(chr,
"bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ" findSeq(chr) isNil not)
standardIO := File standardInput
rovarspraket := method(string, output,
if(string isEmpty,
output,
firstChar := string at(0) asCharacter
tailString := string exSlice(1)
rovarspraket(tailString, output ..
if(isConsonant(firstChar),
firstChar .. "o" .. firstChar,
firstChar))))
main := method(
"Saisissez une chaine : " println
input := standardIO readLine
a := rovarspraket(input, "")
a println)
main
Et la version Bootmonkey (directement traduit du code Haskell) :
use stdio as io
Bool isConsonant(Char chr) {
return chr in "bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ"
}
String rovarspraket(String input, output = "") {
if input.isEmpty() {
return output
} else {
Char firstChar = input.charAt(0)
String tailInput = input.slice(1)
String newSubString = firstChar.toString()
if isConsonant(firstChar) {
newSubString = firstChar + 'o' + firstChar
}
return rovarspraket(tailInput, output + newSubString)
}
}
Void main() {
io.println("Saisissez une chaine : ")
String input = io.readLine()
String a = rovarspraket(input)
io.println(a)
}
Bien sûr, puisque le langage n'existe pas... j'imagine la librairie standard.
Vous devez être inscrit pour répondre à ce sujet.