Tråd: Open AI
View Single Post
Meningsløst medlem
Quakecry's Avatar
Sitat av Cheese Vis innlegg
Litt som jeg nevnte i posten min over, dette er et script som ikke vil kjøre i blender. Det er knapt nok et skjellet. Har ikke prøvd å kjøre det, men som jeg leser det så vil det lage en kube, en sylinder og en bakgrunn, uten noe mer form enn det, det gjøres også et forsøk på animering.

Her finnes det også avhengigheter, ser blant annet at det refereres til en bildefil i bakgrunnen.

Definitivt et godt utgangspunkt hvis det ikke hadde krevd for mye å fikse scriptet.
Vis hele sitatet...
Ja, som nevnt var det bare noe jeg kjapt stilte et spørsmål om. Hvordan man stiller spørsmålet, og eventuelle oppfølgingsspørsmål er viktig for utfallet.

Sitat av robhol Vis innlegg
Jeg er nysgjerrig, men selv om Blender-eksempelet virker stripped-down nok til å være en ganske marginal ståkarakter i beste fall, kan jeg ikke nok om Blender til å si det sikkert. Hvis noen gidder å kjøre disse, så kan vi kjøre code review...
Selv kom jeg også så langt som til "telefon?? fuck det" under registrering.
Vis hele sitatet...
1a
Vis hele sitatet...
på 1a svarte den følgende når jeg spurte:

Kode

using System;
using System.Collections.Generic;

public interface INumberGenerator
{
    IEnumerable<int> Generate();
}

public class FibonacciGenerator : INumberGenerator
{
    public IEnumerable<int> Generate()
    {
        int a = 0, b = 1;

        while (true)
        {
            yield return a;
            (a, b) = (b, a + b);
        }
    }
}

public class TriangularNumberGenerator : INumberGenerator
{
    public IEnumerable<int> Generate()
    {
        int n = 1, sum = 0;

        while (true)
        {
            sum += n;
            yield return sum;
            n++;
        }
    }
}

public class CustomNumberGenerator : INumberGenerator
{
    private readonly Func<int, int> _generator;

    public CustomNumberGenerator(Func<int, int> generator)
    {
        _generator = generator;
    }

    public IEnumerable<int> Generate()
    {
        int n = 0;

        while (true)
        {
            yield return _generator(n);
            n++;
        }
    }
}

public class NumberGenerator
{
    private readonly INumberGenerator _numberGenerator;

    public NumberGenerator(INumberGenerator numberGenerator)
    {
        _numberGenerator = numberGenerator;
    }

    public IEnumerable<int> Generate(int count)
    {
        int i = 0;
        foreach (var number in _numberGenerator.Generate())
        {
            if (i >= count) break;

            yield return number;
            i++;
        }
    }
}

public static class Program
{
    public static void Main()
    {
        var fibonacciGenerator = new NumberGenerator(new FibonacciGenerator());
        var triangularNumberGenerator = new NumberGenerator(new TriangularNumberGenerator());

        var customGenerator = new NumberGenerator(new CustomNumberGenerator(n => n * n));

        foreach (var number in fibonacciGenerator.Generate(10))
        {
            Console.WriteLine(number);
        }

        Console.WriteLine();

        foreach (var number in triangularNumberGenerator.Generate(10))
        {
            Console.WriteLine(number);
        }

        Console.WriteLine();

        foreach (var number in customGenerator.Generate(10))
        {
            Console.WriteLine(number);
        }
    }
}
"The program defines an interface INumberGenerator with a single method Generate that returns an enumerable of integers. It also defines three classes that implement the interface: FibonacciGenerator, TriangularNumberGenerator, and CustomNumberGenerator. The first two generate sequences of fibonacci numbers and triangular numbers, respectively, while the third allows a developer to pass in a custom generator function as a parameter.

The NumberGenerator class takes an INumberGenerator as a parameter in its constructor and stores it in a private field. It has a Generate method that takes an integer count as a parameter and returns an enumerable of integers. It does this by calling the Generate method on the INumberGenerator object stored in the private field, and then yielding each number in the sequence until count numbers have been yielded.

In the Main method, we create instances of the NumberGenerator class for each of the three implemented generator types: FibonacciGenerator, TriangularNumberGenerator, and CustomNumberGenerator. We then use a foreach loop to iterate over the generated sequences and print each number to the console.

This program allows a developer to easily switch between generating different types of sequences by simply creating a new instance of the NumberGenerator class with the desired generator type, and it also allows for the implementation of custom generator functions using the CustomNumberGenerator class."

1b (hvis den ikke allerede spytter ut noe OOP-basert)
Vis hele sitatet...
Her svarte den dette:

Kode

using System;

// Abstract class for generating a sequence of numbers
abstract class NumberGenerator
{
    // Method for generating the next number in the sequence
    public abstract int Next();

    // Method for resetting the generator to its initial state
    public abstract void Reset();
}

// Concrete class for generating Fibonacci numbers
class FibonacciGenerator : NumberGenerator
{
    private int a = 0;
    private int b = 1;

    public override int Next()
    {
        int c = a + b;
        a = b;
        b = c;
        return c;
    }

    public override void Reset()
    {
        a = 0;
        b = 1;
    }
}

// Concrete class for generating triangular numbers
class TriangularGenerator : NumberGenerator
{
    private int current = 0;
    private int next = 1;

    public override int Next()
    {
        int result = current + next;
        current = next;
        next++;
        return result;
    }

    public override void Reset()
    {
        current = 0;
        next = 1;
    }
}

// Program class that allows the user to switch between generator functions
class Program
{
    static void Main(string[] args)
    {
        // Initialize the generator to the Fibonacci sequence
        NumberGenerator generator = new FibonacciGenerator();

        // Generate and print the first 10 numbers in the sequence
        for (int i = 0; i < 10; i++)
        {
            Console.WriteLine(generator.Next());
        }

        // Switch to the triangular number generator
        generator = new TriangularGenerator();

        // Generate and print the first 10 numbers in the sequence
        for (int i = 0; i < 10; i++)
        {
            Console.WriteLine(generator.Next());
        }
    }
}
"This program defines an abstract NumberGenerator class that has two abstract methods: Next and Reset. The Next method generates the next number in the sequence, and the Reset method resets the generator to its initial state.

The program also defines two concrete classes that inherit from NumberGenerator: FibonacciGenerator and TriangularGenerator. These classes implement the Next and Reset methods to generate Fibonacci numbers and triangular numbers, respectively.

Finally, the Program class allows the user to switch between the two generator functions by creating instances of the FibonacciGenerator and TriangularGenerator classes and assigning them to a NumberGenerator variable. The program then generates and prints the first 10 numbers in the sequence using the Next method."
På spørsmål nr.2 ba jeg den fortsette og den sa følgende:

"To allow a developer to implement custom generator functions, you could add a NumberGenerator factory class that has a method for creating instances of NumberGenerator subclasses. For example:

Kode

// Factory class for creating NumberGenerator instances
class NumberGeneratorFactory
{
    // Method for creating a NumberGenerator instance based on the given type
    public static NumberGenerator Create(Type type)
    {
        if (!typeof(NumberGenerator).IsAssignableFrom(type))
        {
            throw new ArgumentException("Type must be a subclass of NumberGenerator");
        }

        return (NumberGenerator)Activator.CreateInstance(type);
    }
}
This factory class has a Create method that takes a Type object as an argument and returns a new instance of that type. It checks that the given type is a subclass of NumberGenerator using the IsAssignableFrom method, and throws an exception if it is not.

To use this factory class, a developer can pass the type of the desired NumberGenerator subclass to the Create method. For example:

Kode

// Create a FibonacciGenerator instance using the factory
NumberGenerator generator = NumberGeneratorFactory.Create(typeof(FibonacciGenerator));

// Generate and print the first 10 numbers in the sequence
for (int i = 0; i < 10; i++)
{
    Console.WriteLine(generator.Next());
}
This allows developers to easily create instances of NumberGenerator subclasses without having to use the new keyword directly, which makes it easier to switch between different generator functions at runtime."

På den tredje svarte den dette:

Kode

using System;
using System.Collections.Generic;

namespace DiceGame
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initialize a list to hold the dice values
            List<int> diceValues = new List<int>();

            // Roll the dice
            Random random = new Random();
            for (int i = 0; i < 6; i++)
            {
                diceValues.Add(random.Next(1, 7));
            }

            // Calculate the points based on the dice values
            int points = 0;
            if (AreAllDiceEqual(diceValues))
            {
                points = 4000;
            }
            else if (AreAllDiceDifferent(diceValues))
            {
                points = 2000;
            }
            else if (AreThreeOrMoreDiceSharingOneValue(diceValues, out int value))
            {
                if (value == 1)
                {
                    points = 1000;
                }
                else
                {
                    points = 100 * value;
                }
            }
            else
            {
                foreach (int die in diceValues)
                {
                    if (die == 1)
                    {
                        points += 100;
                    }
                    else if (die == 5)
                    {
                        points += 50;
                    }
                }
            }

            // Print the points
            Console.WriteLine("Points: " + points);
        }

        // Returns true if all dice in the list have the same value, false otherwise
        static bool AreAllDiceEqual(List<int> diceValues)
        {
            for (int i = 1; i < diceValues.Count; i++)
            {
                if (diceValues[i] != diceValues[0])
                {
                    return false;
                }
            }
            return true;
        }

        // Returns true if all dice in the list have different values, false otherwise
        static bool AreAllDiceDifferent(List<int> diceValues)
        {
            for (int i = 0; i < diceValues.Count; i++)
            {
                for (int j = i + 1; j < diceValues.Count; j++)
                {
                    if (diceValues[i] == diceValues[j])
                    {
                        return false;
                    }
                }
            }
            return true;
        }

        // Returns true if three or more dice in the list share the same value, and sets the value variable to the shared value
        static bool AreThreeOrMoreDiceSharingOneValue(List<int> diceValues, out int value)
        {
            value = 0;
            foreach (int die in diceValues)
            {
                int count = 0;
                foreach (int otherDie in diceValues)
                {
                    if (die == otherDie)
                    {
                        count++;
                    }
                }
                if (count >= 3)
                {
                    value = die;
                    return true;
                }
            }
            return false;
        }
    }
}
"The program starts by rolling the dice and storing the values in a list. It then calculates the points by checking the different conditions in the following order:

If all dice have the same value, it awards 4000 points.
If all dice are different, it awards 2000 points.
If three or more dice share one value, it awards 1000 points if the value is 1, and 100 points multiplied by the value if the value is not 1.
If none of the previous conditions are met, it awards 100 points for each die with a value of 1, and 50 points for each die with a value of 5.
The program uses several helper functions to check the conditions:

AreAllDiceEqual returns true if all dice in the list have the same value, and false otherwise.
AreAllDiceDifferent returns true if all dice in the list have different values, and false otherwise.
AreThreeOrMoreDiceSharingOneValue returns true if three or more dice in the list share the same value, and sets the value variable to the shared value.
Finally, the program prints the points to the console."

Er spent på hva du synes!
Sist endret av Quakecry; 28. desember 2022 kl. 14:15. Grunn: Automatisk sammenslåing med etterfølgende innlegg.