Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
4658 connectés 

 


Dernière réponse
Sujet : [TOUS LANGAGES] montrez vos codes
TBone le temps d'acheter des piles pour mon HP48...
 
je propose (avec gestion d'erreur très basique):
 
demande un string en entrée sur la pile.
[pre]
<<  
"" "" ""  
1 5 PICK SIZE
FOR I  
  PICK HEAD DUP
  IF "G" ==
  THEN DROP ROT "G" + ROT ROT  
  ELSE DUP
    IF "D" ==
    THEN DROP SWAP "D" + SWAP
    ELSE SWAP +  
    END
  END
  4 ROLL TAIL 4 ROLLD
NEXT  
ROT ROT +
ROT DROP SWAP "Err:" SWAP +
>>
 
[/pre]

Votre réponse
Nom d'utilisateur    Pour poster, vous devez être inscrit sur ce forum .... si ce n'est pas le cas, cliquez ici !
Le ton de votre message                        
                       
Votre réponse


[b][i][u][strike][spoiler][fixed][cpp][url][email][img][*]   
 
   [quote]
 

Options

 
Vous avez perdu votre mot de passe ?


Vue Rapide de la discussion
TBone le temps d'acheter des piles pour mon HP48...
 
je propose (avec gestion d'erreur très basique):
 
demande un string en entrée sur la pile.
[pre]
<<  
"" "" ""  
1 5 PICK SIZE
FOR I  
  PICK HEAD DUP
  IF "G" ==
  THEN DROP ROT "G" + ROT ROT  
  ELSE DUP
    IF "D" ==
    THEN DROP SWAP "D" + SWAP
    ELSE SWAP +  
    END
  END
  4 ROLL TAIL 4 ROLLD
NEXT  
ROT ROT +
ROT DROP SWAP "Err:" SWAP +
>>
 
[/pre]
Mara's dad J'aime bien les fonctions monolignes illisibles !
 
Mais seulement quand çà sert à rien  :D
minooye

Mara's dad a écrit a écrit :

Une autre en PHP :
 

Code :
  1. <?php
  2. function ToGD( $in ){ return( str_repeat("G", substr_count( $in, "G" ) ) . str_repeat("D", substr_count( $in, "D" ) ) ); }
  3. echo ToGD( "GDGGDGDGDGDGGDGDGDGDGGGDDG" );
  4. ?>

 




Joli :)

Mara's dad Une autre en PHP :
 

Code :
  1. <?php
  2. function ToGD( $in ){ return( str_repeat( "G", substr_count( $in, "G" ) ) . str_repeat( "D", substr_count( $in, "D" ) ) ); }
  3. echo ToGD( "GDGGDGDGDGDGGDGDGDGDGGGDDG" );
  4. ?>

 

[jfdsdjhfuetppo]--Message édité par Mara's dad--[/jfdsdjhfuetppo]

Ventilo En basic:

Code :
  1. Dim GD As String
  2.     Dim Gauche As String, Droite As String, Resulta As String
  3.     Dim i As Long
  4.    
  5.     GD = "GDGGDGDGDGDGGDGDGDGDGGGDDG"
  6.     For i = 1 To Len(GD)
  7.         If Mid(GD, i, 1) = "G" Then
  8.             'ok
  9.         ElseIf Mid(GD, i, 1) = "D" Then
  10.             'ok
  11.         Else
  12.             MsgBox "La chaine contien autre chose que G ou D", vbInformation
  13.         End If
  14.     Next i
  15.     For i = 1 To Len(GD)
  16.         If Mid(GD, i, 1) = "D" Then
  17.             Gauche = Gauche & Mid(GD, i, 1)
  18.         ElseIf Mid(GD, i, 1) = "G" Then
  19.             Droite = Droite & Mid(GD, i, 1)
  20.         Else
  21.             Exit Sub
  22.         End If
  23.     Next i
  24.     Resulta = Gauche & Droite
  25.     MsgBox Resulta, vbInformation

 

[jfdsdjhfuetppo]--Message édité par Ventilo--[/jfdsdjhfuetppo]

LeGreg

juju_le_barbare a écrit a écrit :

 
EN C++ :
#include <string.h>
#include <iostream.h>
 
char *classer(char *pasclasse)
{
int g=0, d=0;
char *classe;
for (int i=0; i<sizeof(pasclasse); i++)
 if (pasclasse[i] = 'G')
  g++;
 else
  d++;
for (i=0; i<g; i++)
 strcat(classe, "G" );
for (i=0; i<d; i++)
 strcat(classe, "D" );
return classe;
}
 
void main()
{
cout << classer("GDGGDGDGDGDGGDGDGDGDGGGDDG" );
}




 
Marche pas ton code..
 
LEGREG

matafan En perl :

Code :
  1. $_=<>;while(s/DG/GD/){};print


 
Ou bien, en plus performant mais plus long :

Code :
  1. $l=length($_=<> );$g=tr/G//;print "G"x$g."D"x($l-$g)


 
Bien sûr ces 2 programmes prennent la chaine sur l'entrée standard.

 

[jfdsdjhfuetppo]--Message édité par matafan--[/jfdsdjhfuetppo]

minooye Et hop, un ti coup de php :D
<?
$chaine= "GDGGDGDGDGDGGDGDGDGDGGGDDG";
$a= Strlen($chaine);
$chaine= str_replace("D","",$chaine);
$b= $a-Strlen($chaine);
for($i=1;$i<=$b;$i++){$chaine=$chaine."D";}
echo $chaine;
?>
bjone a ba non c pas ça :D
a taleur

 

[jfdsdjhfuetppo]--Message édité par bjone--[/jfdsdjhfuetppo]

LeGreg

juju_le_barbare a écrit a écrit :

c'est pas très dur ça lecture écriture dans un fichier...
Plutôt une fonction qui a comme paramètre "GDGGDGDGDGDGGDGDGDGDGGGDDG", et qui renvoie 1 chaine avec tous les G à gauche, et tous les D à droite...




 
un code qui marche sans lib externe.
 

Code :
  1. void trie(const char* src, char *dst) {
  2.   int cpt=0; const char *ptr = src;
  3.   while (*ptr!='\0') (*ptr++=='G')?(dst[cpt++]='G'):0;
  4.   while (src[cpt]!='\0') dst[cpt++]= 'D';
  5.   dst[cpt] = '\0';
  6. }
  7. int main() {
  8.   char src[] = "GDGGDGDGDGDGGDGDGDGDGGGDDG";
  9.   char dst[sizeof(src)];
  10.   trie (src, dst);
  11.   return 0;
  12. }


 
A+
LEGREG
edit : remaniement du code

 

[jfdsdjhfuetppo]--Message édité par legreg--[/jfdsdjhfuetppo]

Cherrytree Arrgh ! Dommage.
LeGreg

Cherrytree a écrit a écrit :

LEGREG >  J'imagine que tu en as d'autres des comme ça. Tu peux nous gratifier d'une URL s'il te plait ?  




euh non c'est juste une des blagues qui atterrissent
parfois dans ma boite mail.
 
LEGREG

Aricoh pour ceux qui ne connaissent pas, y a ce truc de ouf' :
 
http://www2.latech.edu/~acm/HelloWorld.shtml
Cherrytree LEGREG >  J'imagine que tu en as d'autres des comme ça. Tu peux nous gratifier d'une URL s'il te plait ?
Harkonnen Eh, LEGREG, t'as oublié le cas du hacker complètement déjanté qui veut à tout prix optimiser son prog !!
 
Hello SEGMENT
      ORG 100h
      ASSUME CS:Hello
 
Go    JMP Debut
 
Texte DB 'Hello World$'
 
Debut MOV DX, OFFSET Texte
      PUSH AX
      MOV AH,09h
      INT 21h
      POP AX
      INT 20h
 
Hello ENDS
      END Debut
 
 :lol:  :lol:  :lol:
C_Po_Ma_Faute LEGREG > vraiment lolant, j'ai faillit me pisser dessus
 
:lol: :lol: :lol: :lol: :lol:
Bloodymary_ LEGREG :  :lol:  :lol:  :lol:  :lol:  :lol:  :lol:  :lol:  
 
Du grand art !
Aricoh legreg : BRUTE !!! :ouch::benetton::crazy:

 

[jfdsdjhfuetppo]--Message édité par Aricoh--[/jfdsdjhfuetppo]

Jar Jar

kadreg a écrit a écrit :

C'est pas la façon la plus efficace, il y a pas de verif de la chaine d'entrée, mais au moins elle montre des caractéristiques interressantes du langage :


Euuuuh, et c'est quel langage ?

vapo Legred  :lol:  :lol:  :lol:  :lol:  
Trop fort !
Et c'est tellement vrai !
J'adore vraiment très fort...
gfive Allez, en Java :  
 
class Truc {
 
  public static String Trie(String s) {
     char[] ca = s.toCharArray();
     StringBuffer gbuffer = new StringBuffer();
     StringBuffer dbuffer = new StringBuffer();
 
     for (int i = 0; i < s.length; i++) {
         switch ca[i] {
             case 'G':
                 gbuffer.append(ca[i]);
                 break;
             case 'D':
                 dbuffer.append(ca[i]);
                 break;
              default:
                 System.out.println("J'ai dit des G ou des D, banane!" );
                 break;
         }
         System.out.println(dbuffer.toString()+gbuffer.toString());
     }
 
     public static void usage() {
         System.out.println("Truc [serie de G et de D]" );
     }
     
     public static void Main(String[] args) {
        if (args.lengh == 1) {          
          Trie(args[0]);
        } else {
           usage();
        }
     }
}
kadreg C'est pas la façon la plus efficace, il y a pas de verif de la chaine d'entrée, mais au moins elle montre des caractéristiques interressantes du langage :
 

Code :
  1. String machaine="GDGGDGDGDGDGGDGDGDGDGGGDDG" ;
  2.     String result;
  3.     machaine.substitute ("G", "G:" );
  4.     machaine.substitute ("D", "D:" );
  5.     machaine.strip (":" );
  6.     machaine.segment (":" ) {
  7.         if (self == "G" ) {
  8.             result.prepend (self);
  9.         } else {
  10.             result.strcat (self);
  11.         }
  12.     }
  13.     StdOut.write (result + NL);

 

[jfdsdjhfuetppo]--Message édité par kadreg--[/jfdsdjhfuetppo]

ITM legreg : LOL  :D  
Sauf pour la terminale:
10 PRINT "Hello World"
20 END
 
JE suis en terminale, mais je ne suis pas tombé si bas quand même...  ;)
Sh@rdar legreg >>>  :lol:  :lol:
Jar Jar En Python :
 

Code :
  1. machaine="GDGGDGDGDGDGGDGDGDGDGGGDDG"
  2. def trier(chaine):
  3.    return chaine.count("G" )*"G"+chaine.count("D" )*"D"
  4. print trier(machaine)

 

[jfdsdjhfuetppo]--Message édité par Jar Jar--[/jfdsdjhfuetppo]

LeGreg Le but de la manipulation est d'écrire un programme qui
Affichera "HELLO WORLD" à l'écran.
 

Code :
  1. Terminale
  2. -----------------------------------------------------
  3. 10 PRINT "HELLO WORLD"
  4. 20 END
  5. DUT 1ère année
  6. -----------------------------------------------------
  7. program HELLO(input, output)
  8. begin
  9. writeln('HELLO WORLD')
  10. end
  11. DUT 2ème année
  12. -----------------------------------------------------
  13. (defun HELLO
  14. (print
  15. (cons 'HELLO (list 'WORLD))
  16. )
  17. )
  18. Fraîchement sorti de l'école
  19. -----------------------------------------------------
  20. #include
  21. void main(void) {
  22. char *message[] = {"HELLO ", "WORLD"};
  23. int i;
  24. for(i = 0; i < 2; ++i)
  25. printf("%s", message[i]);
  26. printf("\n" );
  27. }
  28. Professionnel très expérimenté
  29. -----------------------------------------------------
  30. #include
  31. #include
  32. class string {
  33. private:
  34. int size;
  35. char *ptr;
  36. public:
  37. string() : size(0), ptr(new char('\0')) {}
  38. string(const string &s) : size(s.size) {
  39. ptr = new char[size + 1];
  40. strcpy(ptr, s.ptr);
  41. }
  42. ~string() {
  43. delete [] ptr;
  44. }
  45. friend ostream &operator <<(ostream &, const string
  46. &);
  47. string &operator=(const char *);
  48. };
  49. ostream &operator<<(ostream &stream, const string &s) {
  50. return(stream << s.ptr);
  51. }
  52. string &string::operator=(const char *chrs) {
  53. if (this != &chrs) {
  54. delete [] ptr;
  55. size = strlen(chrs);
  56. ptr = new char[size + 1];
  57. strcpy(ptr, chrs);
  58. }
  59. return(*this);
  60. }
  61. int main() {
  62. string str;
  63. str = "HELLO WORLD";
  64. cout << str << endl;
  65. return(0);
  66. }
  67. Professionnel vraiment très très expérimenté
  68. --------------------------------------------------
  69. -------------
  70. -----------
  71. --------------------------------
  72. [
  73. uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
  74. ]
  75. library LHello
  76. {
  77. // bring in the master library
  78. importlib("actimp.tlb" );
  79. importlib("actexp.tlb" );
  80. // bring in my interfaces
  81. #include "pshlo.idl"
  82. [
  83. uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
  84. ]
  85. cotype THello
  86. {
  87. interface IHello;
  88. interface IPersistFile;
  89. };
  90. };
  91. [
  92. exe,
  93. uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
  94. ]
  95. module CHelloLib
  96. {
  97. // some code related header files
  98. importheader();
  99. importheader();
  100. importheader();
  101. importheader("pshlo.h" );
  102. importheader("shlo.hxx" );
  103. importheader("mycls.hxx" );
  104. // needed typelibs
  105. importlib("actimp.tlb" );
  106. importlib("actexp.tlb" );
  107. importlib("thlo.tlb" );
  108. [
  109. uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
  110. aggregatable
  111. ]
  112. coclass CHello
  113. {
  114. cotype THello;
  115. };
  116. };
  117. #include "ipfix.hxx"
  118. extern HANDLE hEvent;
  119. class CHello : public CHelloBase
  120. {
  121. public:
  122. IPFIX(CLSID_CHello);
  123. CHello(IUnknown *pUnk);
  124. ~CHello();
  125. HRESULT __stdcall PrintSz(LPWSTR pwszString);
  126. private:
  127. static int cObjRef;
  128. };
  129. #include
  130. #include
  131. #include
  132. #include
  133. #include "thlo.h"
  134. #include "pshlo.h"
  135. #include "shlo.hxx"
  136. #include "mycls.hxx"
  137. int CHello::cObjRef = 0;
  138. CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
  139. {
  140. cObjRef++;
  141. return;
  142. }
  143. HRESULT __stdcall CHello::PrintSz(LPWSTR pwszString)
  144. {
  145. printf("%ws\n", pwszString);
  146. return(ResultFromScode(S_OK));
  147. }
  148. CHello::~CHello(void)
  149. {
  150. // when the object count goes to zero, stop the server
  151. cObjRef--;
  152. if( cObjRef == 0 )
  153. PulseEvent(hEvent);
  154. return;
  155. }
  156. #include
  157. #include
  158. #include "pshlo.h"
  159. #include "shlo.hxx"
  160. #include "mycls.hxx"
  161. HANDLE hEvent;
  162. int _cdecl main(int argc, char * argv[]) {
  163. ULONG ulRef;
  164. DWORD dwRegistration;
  165. CHelloCF *pCF = new CHelloCF();
  166. hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  167. // Initialize the OLE libraries
  168. CoInitializeEx(NULL, COINIT_MULTITHREADED);
  169. CoRegisterClassObject(CLSID_CHello, pCF,
  170. CLSCTX_LOCAL_SERVER,
  171. REGCLS_MULTIPLEUSE, &dwRegistration);
  172. // wait on an event to stop
  173. WaitForSingleObject(hEvent, INFINITE);
  174. // revoke and release the class object
  175. CoRevokeClassObject(dwRegistration);
  176. ulRef = pCF->Release();
  177. // Tell OLE we are going away.
  178. CoUninitialize();
  179. return(0);
  180. }
  181. extern CLSID CLSID_CHello;
  182. extern UUID LIBID_CHelloLib;
  183. CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-
  184. 00AA00342820 */
  185. 0x2573F891,
  186. 0xCFEE,
  187. 0x101A,
  188. { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  189. };
  190. UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-
  191. 00AA00342820 */
  192. 0x2573F890,
  193. 0xCFEE,
  194. 0x101A,
  195. { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  196. };
  197. #include
  198. #include
  199. #include
  200. #include
  201. #include
  202. #include "pshlo.h"
  203. #include "shlo.hxx"
  204. #include "clsid.h"
  205. int _cdecl main(int argc, char * argv[]) {
  206. HRESULT hRslt;
  207. IHello *pHello;
  208. ULONG ulCnt;
  209. IMoniker * pmk;
  210. WCHAR wcsT[_MAX_PATH];
  211. WCHAR wcsPath[2 * _MAX_PATH];
  212. // get object path
  213. wcsPath[0] = '\0';
  214. wcsT[0] = '\0';
  215. if( argc 1) {
  216. mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
  217. wcsupr(wcsPath);
  218. } else {
  219. fprintf(stderr, "Object path must be specified\n" );
  220. return(1);
  221. }
  222. // get print string
  223. if(argc 2)
  224. mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
  225. else
  226. wcscpy(wcsT, L"Hello World" );
  227. printf("Linking to object %ws\n", wcsPath);
  228. printf("Text String %ws\n", wcsT);
  229. // Initialize the OLE libraries
  230. hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);
  231. if(SUCCEEDED(hRslt)) {
  232. hRslt = CreateFileMoniker(wcsPath, &pmk);
  233. if(SUCCEEDED(hRslt))
  234. hRslt = BindMoniker(pmk, 0, IID_IHello,
  235. (void **)&pHello);
  236. if(SUCCEEDED(hRslt)) {
  237. // print a string out
  238. pHello->PrintSz(wcsT);
  239. Sleep(2000);
  240. ulCnt = pHello->Release();
  241. } else
  242. printf("Failure to connect, status: %lx",
  243. hRslt);
  244. // Tell OLE we are going away.
  245. CoUninitialize();
  246. }
  247. return(0);
  248. }
  249. Administrateur Système
  250. -----------------------------------------------------
  251. #include
  252. main() {
  253. char *tmp;
  254. int i=0;
  255. /* on y va bourin */
  256. tmp=(char *)malloc(1024*sizeof(char));
  257. while (tmp[i]="HELLO WORLD"[i++]);
  258. /* Ooopps y'a une infusion ! */
  259. i=(int)tmp[8];
  260. tmp[8]=tmp[9];
  261. tmp[9]=(char)i;
  262. printf("%s\n",tmp);
  263. }
  264. Apprenti Hacker
  265. -----------------------------------------------------
  266. #!/usr/local/bin/perl
  267. $msg="HELLO, WORLD.\n";
  268. if ($#ARGV >= 0) {
  269. while(defined($arg=shift(@ARGV))) {
  270. $outfilename = $arg;
  271. open(FILE, ">" . $outfilename) || die "Can't write
  272. $arg: $!\n";
  273. print (FILE $msg);
  274. close(FILE) || die "Can't close $arg: $!\n";
  275. }
  276. } else {
  277. print ($msg);
  278. }
  279. 1;
  280. Hacker expérimenté
  281. -----------------------------------------------------
  282. #include
  283. #define S "HELLO, WORLD\n"
  284. main(){exit(printf(S) == strlen(S) ? 0 : 1);}
  285. Hacker très expérimenté
  286. -----------------------------------------------------
  287. % cc -o a.out ~/src/misc/bv/bv.c
  288. % a.out
  289. Gourou des Hackers
  290. -----------------------------------------------------
  291. % cat
  292. HELLO, WORLD.
  293. ^D
  294. Directeur junior
  295. -----------------------------------------------------
  296. 10 PRINT "HELLO WORLD"
  297. 20 END
  298. Directeur
  299. -----------------------------------------------------
  300. mail -s "HELLO, WORLD." bob@b12
  301. Henri, pourrais-tu m'écrire un programme qui écrit "HELLO,
  302. WORLD." À l'écran?
  303. J'en ai besoin pour demain.
  304. ^D
  305. Directeur sénior
  306. -----------------------------------------------------
  307. % zmail Jean
  308. J'ai besoin d'un programme "HELLO, WORLD." Pour cette
  309. après-midi.
  310. Président Directeur Général
  311. -----------------------------------------------------
  312. % letter
  313. letter: Command not found.
  314. % mail
  315. To: ^X ^F ^C
  316. % help mail
  317. help: Command not found.
  318. % damn!
  319. !: Event unrecognized
  320. % logout


 
LEGREG

Aricoh

juju_le_barbare a écrit a écrit :

et c'est ce que tu voulais ?



ce que je voulais, c'est voir comment, selon les langages, on peut obtenir le même résultat
 
Mon truc n'avait pas pour autre but que ça, comme si j'avais demandé "dites, comment vous faites le programme Hello, World" dans votre langage ?

juju_le_barbare pardon  :crazy:  
 
http://forum.hardware.fr/forum2.ph [...] ic=&trash=
darklord

juju_le_barbare a écrit a écrit :

et c'est ce que tu voulais ?
 
et mon problème sur software, kkun a une idée ???  




 
si tu filais le lien ...

juju_le_barbare et c'est ce que tu voulais ?
 
et mon problème sur software, kkun a une idée ???
Aricoh en PERL :
 
my $G;
my $D;
my $chaine = "GDGGDGDGDGDGGDGDGDGDGGGDDG";
 
while ($chaine) {
    $_ = chop($chaine);
    $G .= $_ if ($_ =~ /G/);
    $D .= $_ if ($_ =~ /D/);
}
print "$G$D";
juju_le_barbare c'est pas très dur ça lecture écriture dans un fichier...
Plutôt une fonction qui a comme paramètre "GDGGDGDGDGDGGDGDGDGDGGGDDG", et qui renvoie 1 chaine avec tous les G à gauche, et tous les D à droite...
 
EN C++ :
 
 
#include <string.h>
#include <iostream.h>
 
char *classer(char *pasclasse)
{
int g=0, d=0;
char *classe;
for (int i=0; i<sizeof(pasclasse); i++)
 if (pasclasse[i] = 'G')
  g++;
 else
  d++;
for (i=0; i<g; i++)
 strcat(classe, "G" );
for (i=0; i<d; i++)
 strcat(classe, "D" );
return classe;
}
 
void main()
{
cout << classer("GDGGDGDGDGDGGDGDGDGDGGGDDG" );
}
 
 
Très loin d'être optimisée (pas de vérification qu'il y ait que des G et des D en entrée, etc...), mais c'est juste pour montrer ce qu'on doit faire...
pis là j'ai un pb très important et j'attends la réponse sur software et réseau !!! HELP ME !!! :cry:  :cry:
 
 :hello:  
 
elle est dans l'esprit de ce que tu cherche mon idée ?

 

[jfdsdjhfuetppo]--Message édité par juju_le_barbare--[/jfdsdjhfuetppo]

darklord bin vas y balance .. :)
Aricoh oui je sais, c'est bête comme topic
 
Le but du jeu : à partir d'un petit cas concrèt, vous montrez le code que vous aurez fait en indiquant le langage utilisé.
 
Qui propose un petit cas concrèt ? Heu, pas un truc de 50 lignes, je sais po moa, un petit exo avec lecture/écriture dans un fichier ?
 
Qui s'y colle ?
 
Zo fait, ma spécialité c'est PERL et j'vous préviens tt de suite : j'va vous perler la têteuuuuu :lol:

Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)