chatGPT writes and executes Harbour code !!!

chatGPT writes and executes Harbour code !!!

Postby Antonio Linares » Tue Dec 06, 2022 12:28 pm

https://chat.openai.com/chat

And not only writes it and fixes it, if required, but also is able to execute the code and let you know the results...
Code: Select all  Expand view
#include "hbapi.h"
#include "hbmath.h"

// Constant for the number of days in a year
#define DAYS_PER_YEAR 365.24

// Structure to represent a planet
typedef struct {
    char *name;
    double distance_from_sun; // in millions of kilometers
    double year_length; // in Earth days
} planet_t;

// Array of planets in the solar system
planet_t planets[] = {
    { "Mercury", 57.9, 87.97 },
    { "Venus", 108.2, 224.68 },
    { "Earth", 149.6, 365.24 },
    { "Mars", 227.9, 686.98 },
    { "Jupiter", 778.6, 4332.82 },
    { "Saturn", 1427.0, 10759.22 },
    { "Uranus", 2871.0, 30688.5 },
    { "Neptune", 4497.1, 60182.0 }
};

// Function to calculate the position of a planet
// given the number of days since the start of the year
double calculate_position(planet_t planet, double days_since_start_of_year) {
    double orbit_fraction = days_since_start_of_year / planet.year_length;
    return fmod(orbit_fraction, 1.0) * 360.0;
}

HB_FUNC( PLANETS ) {
    // Check for the correct number of arguments
    if ( hb_pcount() != 2 ) {
        hb_retc( "Usage: PLANETS( <month>, <day> )" );
        return;
    }

    // Parse the month and day from the command line arguments
    int month = hb_parni( 1 );
    int day = hb_parni( 2 );

    // Calculate the number of days since the start of the year
    double days_since_start_of_year = (month - 1) * 30.4 + day;

    // Create a string to hold the output
    char *output = (char*) hb_xgrab( 1024 );
    sprintf( output, "Planet\t\tPosition\n" );

    // Calculate the positions of the planets
    for (int i = 0; i < sizeof(planets) / sizeof(planet_t); i++) {
        double position = calculate_position(planets[i], days_since_start_of_year);
        sprintf( output + strlen( output ), "%s\t\t%.2f degrees\n", planets[i].name, position );
    }

    // Return the output string
    hb_retc( output );
    hb_xfree( output );
}
 

> write the result for the above call to Planets( 12, 6 )
Planet Position
Mercury 35.99 degrees
Venus 211.38 degrees
Earth 347.00 degrees
Mars 56.32 degrees
Jupiter 175.49 degrees
Saturn 132.94 degrees
Uranus 286.76 degrees
Neptune 212.01 degrees
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: chatGPT writes and executes Harbour code !!!

Postby Antonio Linares » Tue Dec 06, 2022 12:30 pm

it also translates code from one language to another...

Wow :-D

First I asked for this:
> write a C code to calculate the planets positions given a date
after getting the result I told it:
> translate the above code to Harbour code
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: chatGPT writes and executes Harbour code !!!

Postby Cgallegoa » Wed Dec 07, 2022 5:19 pm

Connecting FiveWin / xHarbour with OpenAI API :D

Image

Code: Select all  Expand view
#include "FiveWin.ch"

#define EM_LIMITTEXT 197


Function Main()
   LOCAL oDlg, oGet1, cVar1 := "Hola OpenAI, cómo estás ? Me llamo Carlos, tú tienes nombre ?"
   LOCAL oGet2, cVar2 := Space(2048)
   LOCAL oFont1, oFont2, oBtn1, oSay1, oSay2
   LOCAL nChars := 2048
   TBtnBmp():lLegacyLookLeftRight := .T.
   
   cVar1 := "Puedes mostrarme el código de un programa escrito en lenguaje Harbour que en la function main tenga un Alert que diga 'Hola Mundo' ?"
   
   DEFINE FONT oFont1 NAME "Verdana" SIZE 0,-12 BOLD
   DEFINE FONT oFont2 NAME "Verdana" SIZE 0,-12
   DEFINE DIALOG oDlg FROM 0,0 TO 39,107 TRUEPIXEL TITLE "Taking with OPENAI API"
   
       @ 10,270 SAY "Talking with OPENAI API" OF oDlg FONT oFont1 SIZE 300,15PIXEL CENTER
       @ 28,20 SAY "You:" OF oDlg FONT oFont1 SIZE 50,15 PIXEL
   
       @ 28,680 SAY oSay1 VAR "Caracteres: 0 / "+cValToChar(nChars) OF oDlg PIXEL;
                        SIZE 120,15 UPDATE CENTER
   
       @ 45,20 GET oGet1 VAR cVar1 OF oDlg PIXEL SIZE 800,200 MEMO FONT oFont2;
               ON CHANGE(SB_LimitText(oGet1, oSay1, nChars))
            oGet1:bGotfocus := {||oGet1:SetSel(0,0)}
   
       @ 250,345 BTNBMP PROMPT "Submit" OF oDlg PIXEL ACTION Api_OpenAI(cVar1, oGet2) SIZE 150,45;
             FILE "openai24x24.png" LEFT NOBORDER 2007
   
       @ 300,20 SAY "OPENAI:" OF oDlg FONT oFont1 SIZE 70,15 PIXEL
   
       @ 317,20 GET oGet2 VAR cVar2 OF oDlg PIXEL SIZE 800,200 MEMO FONT oFont2
            oGet2:bGotfocus := {||oGet2:SetSel(0,0)}
   
       @ 535,620 BTNBMP PROMPT "Close" OF oDlg PIXEL ACTION oDlg:End() SIZE 150,45;
             FILE "exit24x24.png" LEFT NOBORDER 2007
   
       oDlg:bInit := {|| oGet1:SetFocus(),;
                          oGet1:LimitText(nChars),;
                          oSay1:VarPut("Caracteres: " + cValToChar(LEN( ALLTRIM( oGet1:cText ) )) + " / " + cValToChar(nChars)),;
                          oSay1:Refresh()}
   
   ACTIVATE DIALOG oDlg CENTERED ON PAINT oGet1:SetPos(0)
   
Return(NIL)
//------------------------------------------------------------//


Function Api_OpenAI(cPrompt, oGet2)
   LOCAL oSoap := CreateObject( "MSXML2.ServerXMLHTTP.6.0")
   LOCAL cUrl   := "https://api.openai.com/v1/engines/text-davinci-003/completions"
   LOCAL cToken := "sk-nxnxnxnxnxnxnxnxnxnxnxnxnxnxnxnxxnxnxnxnxnx"
   LOCAL cJSon, cRespApi, hResp := {=>}, cResp
   
   TEXT INTO cJson
        {
            "prompt": "cPrompt_empty",
            "temperature": 0,
            "max_tokens": 2048
        }
   ENDTEXT
   
   cPrompt := AllTrim(cPrompt)
   cJson := StrTran(cJson, "cPrompt_empty", cPrompt)
   
   oSoap:SetTimeouts(30000,30000,30000,30000)
   TRY
      oSoap:Open( "POST" , cUrl , .F. )
      oSoap:SetRequestHeader( "Content-Type", "application/json; charset=utf-8" )
      oSoap:setRequestHeader("Authorization", "Bearer "+cToken )
      oSoap:Send(cJson)
   
      cRespApi := Alltrim(oSoap:responseText)
      hb_jsondecode(cRespApi,@hResp)
   
      cResp := hResp["choices"][1]["text"]
      cResp := StrTran(cResp, Chr(10), Chr(13)+Chr(10))
      oGet2:VarPut( AllTrim(cResp) )
      oGet2:Refresh()
   
     // MsgInfo( oSoap:Status )
   
   CATCH
      msginfo("Mensaje en el CATCH"+CRLF+CRLF+ "No hay conexión con el servidor de Rindegastos."+CRLF+ "  Por favor vuelva a intentarlo.","Intente Nuevamente")
   
   END
   
Return(oSoap)
//------------------------------------------------------------//


FUNCTION SB_LimitText( oGet, oSay, nLimObserv )
   ///////////////////////////////////////////////////////////////////////////
   // Autor..........: Peguei no Forum FiveWin Brasil                       //
   // Modificaçoes...: Ale SB - Soft Camus                                  //
   // Descricao......: Restringe o Tamanho de um Texto.                     //
   // Parametros ==>                                                        //
   //  - oGet  : oBjeto Get.                                                //
   //  - nSize : Tamanho que deve ter o Texto.                              //
   // Dependencias ==>                                                      //
   // Retorno ==> nil                                                       //
   ///////////////////////////////////////////////////////////////////////////
   LOCAL nTam, nSize
   DEFAULT nSize := nLimObserv  // 19  // 99 // maximo e 100 caracteres
   nTam := LEN( ALLTRIM( oGet:cText ) )
   IF nTam > nSize
      Msginfo( "Lo siento, no puedo continuar, el tamaño máximo " + ;
               "ha excedido el límite permitido.", "Atención por favor." )
      oGet:cText := Substr(oGet:cText, 1, nTam-1)
      RETURN( .F. )
   ENDIF
   oSay:VarPut("Caracteres: " + cValToChar(nTam) + " / " + cValToChar(nLimObserv))
     oSay:Refresh()
RETURN( .T. )
//------------------------------------------------------------//
 
Last edited by Cgallegoa on Wed Dec 07, 2022 8:55 pm, edited 1 time in total.
Saludos,

Carlos Gallego

*** FWH-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Cgallegoa
 
Posts: 492
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: chatGPT writes and executes Harbour code !!!

Postby karinha » Wed Dec 07, 2022 6:37 pm

Good Afternoon Carlos Gallego, how do I get a key (password) to test your beautiful example? Thanks.

{
"error": {
"message": "You didn't provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you're accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://beta.openai.com.
"type": "invalid_request_error",
"param": null,
"code": null
}
}

Code: Select all  Expand view

// C:\FWH..\SAMPLES\OPENAPI.PRG

#include "FiveWin.ch"

#define EM_LIMITTEXT 197

FUNCTION Main()

   LOCAL oDlg, oGet1, cVar1 := "Hola OpenAI, cómo estás ? Me llamo Carlos, tú tienes nombre ?"
   LOCAL oGet2, cVar2 := Space( 2048 )
   LOCAL oFont1, oFont2, oBtn1, oSay1, oSay2
   LOCAL nChars := 2048

   SkinButtons()

   IF FWVERSION >= "FWHX 19.06"

      TBtnBmp():lLegacyLookLeftRight := .T.

   ENDIF

   cVar1 := "Puedes mostrarme el código de un programa escrito en " + ;
            "lenguaje Harbour que en la function main tenga un "    + ;
            "Alert que diga 'Hola Mundo' ?"

   DEFINE FONT oFont1 NAME "Verdana" SIZE 0, - 12 BOLD
   DEFINE FONT oFont2 NAME "Verdana" SIZE 0, - 12

   DEFINE DIALOG oDlg FROM 0, 0 TO 39, 107 TRUEPIXEL ;
      TITLE "Taking with OPENAI API"

   oDlg:lHelpIcon := .F.

   @ 10, 270 SAY "Talking with OPENAI API" OF oDlg FONT oFont1 SIZE 300, 15  ;
      PIXEL CENTER

   @ 28, 20 SAY "You:" OF oDlg FONT oFont1 SIZE 50, 15 PIXEL

   @ 28, 680 SAY oSay1 VAR "Caracteres: 0 / " + cValToChar( nChars ) ;
      OF oDlg PIXEL SIZE 120, 15 UPDATE CENTER

   @ 45, 20 GET oGet1 VAR cVar1 OF oDlg PIXEL SIZE 800, 200 MEMO FONT oFont2 ;
      ON CHANGE( SB_LimitText( oGet1, oSay1, nChars ) )

   oGet1:bGotfocus := {|| oGet1:SetSel( 0, 0 ) }

   @ 250, 345 BTNBMP PROMPT "Submit" OF oDlg PIXEL   ;
      ACTION Api_OpenAI( cVar1, oGet2 ) SIZE 150, 45 ;
      FILE "openai24x24.png" LEFT NOBORDER 2007

   @ 300, 20 SAY "OPENAI:" OF oDlg FONT oFont1 SIZE 70, 15 PIXEL

   @ 317, 20 GET oGet2 VAR cVar2 OF oDlg PIXEL SIZE 800, 200 MEMO FONT oFont2

   oGet2:bGotfocus := {|| oGet2:SetSel( 0, 0 ) }

   @ 535, 620 BTNBMP PROMPT "Close" OF oDlg PIXEL ;
      ACTION oDlg:End() SIZE 150, 45              ;
      FILE "exit24x24.png" LEFT NOBORDER 2007

   oDlg:bInit := {|| oGet1:SetFocus(),                   ;
   oGet1:LimitText( nChars ),                            ;
   oSay1:VarPut( "Caracteres: " +                        ;
   cValToChar( Len( AllTrim( oGet1:cText ) ) ) + " / " + ;
   cValToChar( nChars ) ),                               ;
   oSay1:Refresh() }

   ACTIVATE DIALOG oDlg CENTERED ON PAINT( oGet1:SetPos( 0 ) )

   oFont1:End()
   oFont2:End()

RETURN NIL

FUNCTION Api_OpenAI( cPrompt, oGet2 )

   LOCAL oSoap  // := CreateObject( "MSXML2.ServerXMLHTTP.6.0" )
   LOCAL cUrl   := "https://api.openai.com/v1/engines/text-davinci-003/completions"
   LOCAL cToken := "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"
   LOCAL cJSon, cRespApi, hResp := { => }, cResp

   TEXT INTO cJson
      {
         "prompt": "cPrompt_empty",
         "temperature": 0,
         "max_tokens": 2048
      }
   ENDTEXT

   cPrompt := AllTrim( cPrompt )
   cJson   := StrTran( cJson, "cPrompt_empty", cPrompt )

   #ifdef __XHARBOUR__  // xHarbour

      Try

         oSoap := CreateObject( "MSXML2.ServerXMLHTTP.6.0" )

      Catch

         MsgInfo( "xHarbour: errore connessione msxml2, uso microsoft " )

         RETURN NIL

      End

   #else //Harbour

      Try

         oSoap := win_OleCreateObject( "MSXML2.ServerXMLHTTP.5.0" )

      Catch

         MsgInfo( "Harbour: errore connessione msxml2, uso microsoft " )

         RETURN NIL

      End

   #endif

   oSoap:SetTimeouts( 30000, 30000, 30000, 30000 )

   TRY

      oSoap:Open( "POST", cUrl, .F. )
      oSoap:SetRequestHeader( "Content-Type", "application/json; charset=utf-8" )
      oSoap:setRequestHeader( "Authorization", "Bearer " + cToken )
      oSoap:Send( cJson )

      cRespApi := AllTrim( oSoap:responseText )

      hb_jsonDecode( cRespApi, @hResp )

      cResp := hResp[ "choices" ][ 1 ][ "text" ]
      cResp := StrTran( cResp, Chr( 10 ), Chr( 13 ) + Chr( 10 ) )

      oGet2:VarPut( AllTrim( cResp ) )
      oGet2:Refresh()

      // MsgInfo( oSoap:Status )

   CATCH

      MsgInfo( "Mensaje en el CATCH" + CRLF + CRLF + ;
               "No hay conexión con el servidor de Rindegastos." + CRLF + ;
               "  Por favor vuelva a intentarlo.", "Intente Nuevamente" )

   END

Return( oSoap )

FUNCTION SB_LimitText( oGet, oSay, nLimObserv )

   // /////////////////////////////////////////////////////////////////////////
   // Autor..........: Peguei no Forum FiveWin Brasil                       //
   // Modificaçoes...: Ale SB - Soft Camus                                  //
   // Descricao......: Restringe o Tamanho de um Texto.                     //
   // Parametros ==>                                                        //
   // - oGet  : oBjeto Get.                                                //
   // - nSize : Tamanho que deve ter o Texto.                              //
   // Dependencias ==>                                                      //
   // Retorno ==> nil                                                       //
   // /////////////////////////////////////////////////////////////////////////
   LOCAL nTam, nSize

   DEFAULT nSize := nLimObserv  // 19  // 99 // maximo e 100 caracteres

   nTam := Len( AllTrim( oGet:cText ) )

   IF nTam > nSize

      MsgInfo( "Lo siento, no puedo continuar, el tamaño máximo " + ;
               "ha excedido el límite permitido.", "Atención por favor." )

      oGet:cText := SubStr( oGet:cText, 1, nTam - 1 )

      RETURN( .F. )

   ENDIF

   oSay:VarPut( "Caracteres: " + cValToChar( nTam ) + " / " + ;
      cValToChar( nLimObserv ) )

   oSay:Refresh()

RETURN( .T. )

// FIN / END
 


Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
karinha
 
Posts: 7824
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil

Re: chatGPT writes and executes Harbour code !!!

Postby Cgallegoa » Wed Dec 07, 2022 8:54 pm

Hi João,

You must register in https://openai.com/api/.

Next, you can read https://beta.openai.com/docs/api-reference/introduction in order to generate your own token and how to use the Api.

Best regards,
Saludos,

Carlos Gallego

*** FWH-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Cgallegoa
 
Posts: 492
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: chatGPT writes and executes Harbour code !!!

Postby Otto » Sun Dec 11, 2022 7:47 am

Dear Antonio,
I tried to create "keywords" from texts using one of the examples.
The results are good.
I would be interested in the costs.
If I understand it correctly, one page (letter-size) would cost about 1 €.
Can that be right?
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: chatGPT writes and executes Harbour code !!!

Postby Antonio Linares » Sun Dec 11, 2022 8:05 am

Dear Otto,

good morning

I am subscribed to chatGPT (previously I was using davinci 2 from OpenAI too) and up to now, they have not asked me for any money :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: chatGPT writes and executes Harbour code !!!

Postby Otto » Sun Dec 11, 2022 9:38 am

Dear Antonio,
I made several requests to OpenAI and then the message came that my daily tokens were used up.

I will try chatGPT.

Can I make the requests from FIVEWIN (webview2) to chatGPT?

Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: chatGPT writes and executes Harbour code !!!

Postby Antonio Linares » Sun Dec 11, 2022 9:40 am

Dear Otto,

> Can I make the requests from FIVEWIN (webview2) to chatGPT?

Yes, Carlos has posted in this same thread the FWH code to do it :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: chatGPT writes and executes Harbour code !!!

Postby Otto » Sun Dec 11, 2022 9:42 am

Dear Antonio,
how is the link to chatGPT .
I always get results from Google for OpenAI.
Thank you in advance
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6332
Joined: Fri Oct 07, 2005 7:07 pm

Re: chatGPT writes and executes Harbour code !!!

Postby Antonio Linares » Sun Dec 11, 2022 12:28 pm

regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42099
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: chatGPT writes and executes Harbour code !!!

Postby Silvio.Falconi » Tue Dec 13, 2022 11:29 am

Antonio,
Incredible!!!!

I ask
(Italian)
Mi puoi mostrare il codice di un programma scritto in linguaggio Harbour che crea un array di 3 numeri dal 1 al 90 dove la somma è uguale alla distanza ciclometrica ?

(Espanol)
¿Me puede mostrar el código de un programa escrito en lenguaje Harbour que crea una matriz de 3 números del 1 al 90 donde la suma es igual a la distancia ciclométrica?

the chat give me this

Code: Select all  Expand view
// Inizializzazione dell'array
aArray := Array( 3 )

// Ciclo per generare i numeri
FOR nIndex := 1 TO 3
   // Generazione di un numero casuale
   nRandom := Rand( 1, 90 )
   // Controllo se il numero Š gi… presente nell'array
   IF NOT InArray( nRandom, aArray )
      // Aggiunta del numero all'array
      aArray[ nIndex ] := nRandom
   ELSE
      // Generazione di un nuovo numero
      nIndex := nIndex - 1
   ENDIF
NEXT

// Calcolo della distanza ciclometrica
nSum := 0
FOR nIndex := 1 TO 3
   nSum := nSum + aArray[ nIndex ]
NEXT

// Controllo se la somma Š uguale alla distanza ciclometrica
IF nSum == 90
   // Stampa dell'array
   FOR nIndex := 1 TO 3
      ? aArray[ nIndex ]
   NEXT
ENDIF


No puedo creerlo, es impresionante!!!
pero como se hace?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: chatGPT writes and executes Harbour code !!!

Postby Silvio.Falconi » Tue Dec 13, 2022 11:41 am

Another question

( Italian)
Code: Select all  Expand view
Mi puoi mostrare il codice di un programma scritto in linguaggio Harbour che combina 10 numeri in ambi,terzine,quartine,cinquine,sestine,ottine,novine e decine con la possibilità che l'utente possa selezionare i numeri da combinare?


Espanol
Code: Select all  Expand view
¿Me puede mostrar el código de un programa escrito en lenguaje Harbour que combina 10 números en ambs, trillizos, cuatrillos, cincos, _, octs, novines y decenas con la posibilidad de que el usuario pueda seleccionar los números a combinar?


first REsult

Code: Select all  Expand view
// Questo programma Harbour combina 10 numeri in ambi, terzine, quartine, cinquine, sestine, ottine, novine e decine con la possibilit… che l'utente possa selezionare i numeri da combinare.

// Definizione delle variabili
LOCAL aNum[10] // Array per contenere i numeri selezionati dall'utente
LOCAL nNum // Numero di numeri selezionati dall'utente
LOCAL nComb // Numero di combinazioni generate

// Funzione principale
FUNCTION Main()
  // Richiedi all'utente di selezionare i numeri
  nNum := InputNum()
  // Genera le combinazioni
  nComb := GenerateCombinations(aNum, nNum)
  // Mostra le combinazioni generate
  ShowCombinations(aNum, nComb)
RETURN

// Funzione per richiedere all'utente di selezionare i numeri
FUNCTION InputNum()
  LOCAL nNum // Numero di numeri selezionati dall'utente
  // Richiedi all'utente di selezionare i numeri
  nNum := 0
  WHILE nNum < 10
    aNum[nNum] := InputBox("Inserisci un numero", "Inserisci un numero da 1 a 90")
    IF aNum[nNum] > 0 AND aNum[nNum] < 91
      nNum := nNum + 1
    ENDIF
  END
  RETURN nNum
RETURN

// Funzione per generare le combinazioni
FUNCTION GenerateCombinations(aNum, nNum)
  LOCAL nComb // Numero di combinazioni generate
  LOCAL aComb[10] // Array per contenere le combinazioni generate
  LOCAL nIndex // Indice per scorrere l'array aNum
  LOCAL nCount // Contatore per le combinazioni generate
  // Genera le combinazioni
  nComb := 0
  FOR nIndex := 0 TO nNum - 1
    FOR nCount := nIndex + 1 TO nNum - 1
      aComb[nComb] := aNum[nIndex] + "-" + aNum[nCount]
      nComb := nComb + 1
    NEXT
  NEXT
  RETURN nComb
RETURN

// Funzione per mostrare le combinazioni generate
FUNCTION ShowCombinations(aNum, nComb)
  LOCAL nIndex // Indice per scorrere l'array aComb
  // Mostra le combinazioni generate
  FOR nIndex := 0 TO nComb - 1
    MsgBox(aComb[nIndex], "Combinazione")
  NEXT
RETURN

// Chiamata alla funzione principale
Main()




Second Result

Code: Select all  Expand view
//Inizializzazione del programma
SET STEP TO 10
SET DEFAULT TO 10

//Inizializzazione dell'array
DIMENSION aCombinazioni[10]

//Inserimento dei numeri da combinare
FOR i = 1 TO 10
    aCombinazioni[i] = INPUTBOX("Inserisci il numero da combinare:")
END

//Combinazione degli elementi dell'array
FOR i = 1 TO 10
    FOR j = i + 1 TO 10
        PRINT aCombinazioni[i], aCombinazioni[j]
    NEXT
NEXT

//Combinazione di terzine
FOR i = 1 TO 8
    FOR j = i + 1 TO 9
        FOR k = j + 1 TO 10
            PRINT aCombinazioni[i], aCombinazioni[j], aCombinazioni[k]
        NEXT
    NEXT
NEXT

//Combinazione di quartine
FOR i = 1 TO 7
    FOR j = i + 1 TO 8
        FOR k = j + 1 TO 9
            FOR l = k + 1 TO 10
                PRINT aCombinazioni[i], aCombinazioni[j], aCombinazioni[k], aCombinazioni[l]
            NEXT
        NEXT
    NEXT
NEXT

//Combinazione di cinquine
FOR i = 1 TO 6
    FOR j = i + 1 TO 7
        FOR k = j + 1 TO 8
            FOR l = k + 1 TO 9
                FOR m = l + 1 TO 10
                    PRINT aCombinazioni[i], aCombinazioni[j], aCombinazioni[k], aCombinazioni[l], aCombinazioni[m]
                NEXT
            NEXT
        NEXT
    NEXT
NEXT

//Combinazione di sestine
FOR i = 1 TO 5
    FOR j = i + 1 TO 6
        FOR k = j + 1 TO 7
            FOR l = k + 1 TO 8
                FOR m = l + 1 TO 9
                    FOR n = m + 1 TO 10
                        PRINT aCombinazioni[i], aCombinazioni[j], aCombinazioni[k], aCombinazioni[l], aCombinazioni[m], aCombinazioni[n]
                    NEXT
                NEXT
            NEXT
        NEXT
    NEXT
NEXT

//Combinazione di ottine
FOR i = 1 TO 4
    FOR j = i + 1 TO 5
        FOR k = j + 1 TO 6
            FOR l = k + 1 TO 7
                FOR m = l + 1 TO 8
                    FOR n = m + 1 TO 9
                        FOR o = n + 1 TO 10
                            PRINT aCombinazioni[i], aCombinazioni[j], aCombinazioni[k], aCombinazioni[l], aCombinazioni[m], aCombinazioni[n], aCombinazioni[o]
                        NEXT
                    NEXT
                NEXT
            NEXT
        NEXT
    NEXT
NEXT

//Combinazione di novine
FOR i = 1 TO 3
    FOR j = i + 1 TO 4
        FOR k = j + 1 TO 5
            FOR l = k + 1 TO 6
                FOR m = l + 1 TO 7
                    FOR n = m + 1 TO 8
                        FOR o = n + 1 TO 9
                            FOR p = o + 1 TO 10
                                PRINT aCombinazioni[i], aCombinazioni[j], aCombinazioni[k], aCombinazioni[l], aCombinazioni[m], aCombinazioni[n], aCombinazioni[o], aCombinazioni[p]
                            NEXT
                        NEXT
                    NEXT
                NEXT
            NEXT
        NEXT
    NEXT
NEXT

//Combinazione di decine
FOR i = 1 TO 2
    FOR j = i + 1 TO 3
        FOR k = j + 1 TO 4
            FOR l = k + 1 TO 5
                FOR m = l + 1 TO 6
                    FOR n = m + 1 TO 7
                        FOR o = n + 1 TO 8
                            FOR p = o + 1 TO 9
                                FOR q = p + 1 TO 10
                                    PRINT aCombinazioni[i], aCombinazioni[j], aCombinazioni[k], aCombinazioni[l], aCombinazioni[m], aCombinazioni[n], aCombinazioni[o], aCombinazioni[p], aCombinazioni[q]
                                NEXT
                            NEXT
                        NEXT
                    NEXT
                NEXT
            NEXT
        NEXT
    NEXT
NEXT

¡Literalmente me caí de la silla aquí en la escuela!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: chatGPT writes and executes Harbour code !!!

Postby Silvio.Falconi » Tue Dec 13, 2022 12:04 pm

Yo queria ser mas mala, sinceramente queria joderlo para volverlo loco y en cambio el gano
I wanted to be meaner, honestly I wanted to screw him to drive him crazy and instead he won

esta vez le pregunte....

Code: Select all  Expand view
¿Me puede mostrar el código de un programa escrito en lenguaje Harbour que combina 90 números, sin repetición, en una matriz de tres números, que respetan 4 posibilidades, es decir, suma ciclométrica, distancia ciclométrica, suma matemática y distancia matemática y que puede seleccionar el usuario una de las 4 posibilidades?


Can you show me the code of a program written in Harbor language which combines 90 numbers, without repetition, in an array of three numbers, which respect 4 possibilities i.e. the cyclometric sum, the cyclometric distance, the mathematical sum and the mathematical distance and which can the user select one of the 4 possibilities?

Result
Code: Select all  Expand view

FUNCTION Main()
  LOCAL aArray[90], nSumCyclo, nDistCyclo, nSumMath, nDistMath, nChoice
 
  // Generate 90 random numbers
  FOR nIndex := 0 TO 89
    aArray[nIndex] := Rnd(1, 90)
  NEXT
 
  // Calculate cyclometric sum and distance
  nSumCyclo := 0
  nDistCyclo := 0
  FOR nIndex := 0 TO 89
    nSumCyclo := nSumCyclo + aArray[nIndex]
    nDistCyclo := nDistCyclo + ABS(aArray[nIndex] - aArray[nIndex + 1])
  NEXT
 
  // Calculate mathematical sum and distance
  nSumMath := 0
  nDistMath := 0
  FOR nIndex := 0 TO 89
    nSumMath := nSumMath + aArray[nIndex]
    nDistMath := nDistMath + ABS(aArray[nIndex] - aArray[nIndex + 1])
  NEXT
 
  // Ask user to choose one of the 4 possibilities
  nChoice := InputBox("Choose one of the 4 possibilities: 1. Cyclometric sum, 2. Cyclometric distance, 3. Mathematical sum, 4. Mathematical distance")
 
  // Output the 3 numbers
  IF nChoice = 1 THEN
    FOR nIndex := 0 TO 2
      PRINT aArray[nIndex]
    NEXT
  ELSEIF nChoice = 2 THEN
    FOR nIndex := 0 TO 2
      PRINT aArray[nIndex]
    NEXT
  ELSEIF nChoice = 3 THEN
    FOR nIndex := 0 TO 2
      PRINT aArray[nIndex]
    NEXT
  ELSEIF nChoice = 4 THEN
    FOR nIndex := 0 TO 2
      PRINT aArray[nIndex]
    NEXT
  ENDIF
 
  RETURN
END


 



Imposible... me encanta
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Re: chatGPT writes and executes Harbour code !!!

Postby Silvio.Falconi » Tue Dec 13, 2022 12:26 pm

la funcion generada no funciona aqui es el truco!!!
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7061
Joined: Thu Oct 18, 2012 7:17 pm

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 35 guests