Skip to content

Instantly share code, notes, and snippets.

@jechtom
Last active December 4, 2022 13:21
Show Gist options
  • Save jechtom/730e0affc65147d16eb7acab6e8c0c48 to your computer and use it in GitHub Desktop.
Save jechtom/730e0affc65147d16eb7acab6e8c0c48 to your computer and use it in GitHub Desktop.
Test code generation OpenAI
// Write C# code that find longest line of text in directory.
using System;
using System.IO;
public class Program
{
public static void Main()
{
string directoryPath = @"C:\";
string longestLine = "";
//Get all the files in the specified directory
string[] files = Directory.GetFiles(directoryPath);
//Loop through the files
foreach (string file in files)
{
//Read the file
string[] lines = File.ReadAllLines(file);
//Loop through the lines in the file
foreach (string line in lines)
{
//Check if the line is longer than the current longest line
if (line.Length > longestLine.Length)
{
longestLine = line;
}
}
}
//Output the longest line
Console.WriteLine("The longest line in the directory is:");
Console.WriteLine(longestLine);
}
}
// Write C# code that find longest line of text in directory. Don't use arrays.
string longestLine = string.Empty;
string directoryPath = @"C:\directory";
foreach (string file in Directory.EnumerateFiles(directoryPath, "*.*"))
{
using (StreamReader sr = new StreamReader(file))
{
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (line.Length > longestLine.Length)
{
longestLine = line;
}
}
}
}
Console.WriteLine(longestLine);
// Write C# code that find in directory with longest line of text. Use funny variable names with Star Wars references.
string hanSolo = @"C:\";
string longestLine = string.Empty;
DirectoryInfo lukeSkywalker = new DirectoryInfo(hanSolo);
FileInfo[] chewbacca = lukeSkywalker.GetFiles();
foreach(FileInfo c3po in Chewbacca)
{
string r2d2 = File.ReadAllText(c3po.FullName);
if(r2d2.Length > longestLine.Length)
{
longestLine = r2d2;
}
}
Console.WriteLine($"The longest line of text is {longestLine}");
// Write C# code that find in directory with longest line of text. Make code compact.
string maxLine = string.Empty;
string path = @"C:\myDir";
foreach (string file in Directory.EnumerateFiles(path, "*.txt"))
{
StreamReader reader = File.OpenText(file);
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.Length > maxLine.Length)
{
maxLine = line;
}
}
}
Console.WriteLine(maxLine);
// Write C# code that find in directory with longest line of text. Make code impossible to read by human.
int n=0;string s="";string t="";for(int i=0;i<Directory.GetFiles("C:/").Length;i++){foreach(string l in File.ReadAllLines(Directory.GetFiles("C:/")[i])){if(l.Length>n){n=l.Length;s=l;t=Directory.GetFiles("C:/")[i];}}}Console.WriteLine($"Longest line is {s} in {t}");
// Write C# code that find in directory with longest line of text. And add some comments. Each comment must contain at least one interjection.
// Woah! Let's find the longest line of text in a directory!
string longestLine = "";
// Holy cow! Let's loop through all the files in the directory.
foreach (string file in Directory.EnumerateFiles(@"myDirectory"))
{
// Whoa! Now let's loop through all the lines of the file.
foreach (string line in File.ReadLines(file))
{
// Oh wow! Is this line longer than the previous one?
if (line.Length > longestLine.Length)
{
longestLine = line;
}
}
}
// Unbelievable! We've found the longest line of text.
Console.WriteLine(longestLine);
@ank-s2k
Copy link

ank-s2k commented Dec 4, 2022

It gets crazier. The interjection in comments, variable names and variants and many more.

And all the typos as a human !! lol

Here's an attempt to combine some with some deep stuff

Prompt: write an advanced machine learning model with emotional modulation c# code and cmment every line with atleast one interjection and name all variables from marvel characters and use iron man for output simulation example code block

// Oh boy, here we go! Let's create an advanced machine learning model with emotional modulation in C#!

using System;
using System.Linq;
using System.Collections.Generic;

namespace MarvelML
{
    // Let's name our class after the brilliant mind behind Iron Man, Tony Stark!
    public class TonyStark
    {
        // We'll need a list of emotions for our model to choose from
        private static List<string> emotions = new List<string>{"happy", "sad", "angry", "excited"};

        // Our model will take in input data and output a prediction with emotional modulation
        public string Predict(List<string> inputData, string ironManInput)
        {
            // First, we'll use the Linq library to randomly select an emotion from our list
            string emotion = emotions.OrderBy(x => Guid.NewGuid()).First();

            // Next, we'll create a new list to store our modified input data
            List<string> modifiedInputData = new List<string>();

            // Now, we'll loop through each piece of input data and modify it based on the selected emotion
            foreach (string data in inputData)
            {
                switch (emotion)
                {
                    case "happy":
                        // If the emotion is happy, we'll add an exclamation point to the end of the input data
                        modifiedInputData.Add(data + "!");
                        break;
                    case "sad":
                        // If the emotion is sad, we'll add a sad face emoji to the end of the input data
                        modifiedInputData.Add(data + " :(");
                        break;
                    case "angry":
                        // If the emotion is angry, we'll add ALL CAPS to the input data
                        modifiedInputData.Add(data.ToUpper());
                        break;
                    case "excited":
                        // If the emotion is excited, we'll add three exclamation points to the end of the input data
                        modifiedInputData.Add(data + "!!!");
                        break;
                }
            }

            // Finally, we'll use the modified input data and the Iron Man input to generate a prediction
            return "Prediction: " + string.Join(", ", modifiedInputData) + " Iron Man says: " + ironManInput;
        }
    }
}

// Now, let's test our model with some input data and Iron Man's famous quote: "I am Iron Man"
TonyStark model = new TonyStark();
List<string> inputData = new List<string>{"input1", "input2", "input3"};
string prediction = model.Predict(inputData, "I am Iron Man");

// Woo hoo! Our model has made a prediction with emotional modulation!
Console.WriteLine(prediction);

and another iteration yielded

Prompt: write an advanced machine learning model with emotional modulation c# code and cmment every line with atleast one interjection and name all variables from marvel characters and use iron man only for output simulation example code block

// This is an advanced machine learning model with emotional modulation

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdvancedMLModel
{
    // Create a class to represent the model
    public class TonyStark
    {
        // Create variables to hold the model's parameters
        private float[] thor;
        private float[] captainAmerica;
        private float[] hulk;
        private float[] blackWidow;

        // Create a variable to hold the model's emotional state
        private float emotionalState;

        // Create a constructor to initialize the model
        public TonyStark(float[] thor, float[] captainAmerica,
                         float[] hulk, float[] blackWidow,
                         float emotionalState)
        {
            // Assign the input variables to the class variables
            this.thor = thor;
            this.captainAmerica = captainAmerica;
            this.hulk = hulk;
            this.blackWidow = blackWidow;
            this.emotionalState = emotionalState;
        }

        // Create a method to make predictions based on the model's parameters
        public float MakePrediction()
        {
            // Initialize a variable to hold the predicted value
            float prediction = 0;

            // Calculate the predicted value using the model's parameters and emotional state
            for (int i = 0; i < thor.Length; i++)
            {
                prediction += thor[i] * captainAmerica[i] * hulk[i] * blackWidow[i];
            }
            prediction = prediction * emotionalState;

            // Return the predicted value
            return prediction;
        }

        // Create a method to update the model's emotional state
        public void UpdateEmotionalState(float newEmotionalState)
        {
            // Update the model's emotional state
            emotionalState = newEmotionalState;
        }
    }

    // Create a class to simulate using the model
    public class IronMan
    {
        // Create a method to simulate making a prediction with the model
        public static void Predict()
        {
            // Create the model's parameters
            float[] thor = { 0.5f, 0.3f, 0.8f };
            float[] captainAmerica = { 0.2f, 0.9f, 0.1f };
            float[] hulk = { 0.7f, 0.5f, 0.2f };
            float[] blackWidow = { 0.1f, 0.4f, 0.6f };

            // Initialize the model with the parameters and an emotional state of 1
            TonyStark model = new TonyStark(thor, captainAmerica, hulk, blackWidow, 1);

            // Make a prediction with the model
            float prediction = model.MakePrediction();

            // Output the predicted value
            Console.WriteLine("Iron Man predicts a value of " + prediction);
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment