loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.8231598291822741","path":"main.cs","file":{"path":"main.cs","content":{"asEncoding":{"base64":"dXNpbmcgU3lzdGVtOwoKY2xhc3MgRnJhY2Npb24KewogICAgLy9GdW5jaW9uIHBhcmEgY2FsY3VsYXIgZWwgbcOtbmltbyBjb23Dum4gZGVub21pbmFkb3IKICAgIHByaXZhdGUgaW50IENhbGN1bGFybWluaW1vQ29tdW5EZW5vbWluYWRvcihpbnQgTnVtZXJhZG9yLCBpbnQgRGVub21pbmFkb3IpCiAgICB7CiAgICAgICAgaW50IHUgPSBNYXRoLkFicyhOdW1lcmFkb3IpOwogICAgICAgIGludCB2ID0gTWF0aC5BYnMoRGVub21pbmFkb3IpOwogICAgICAgIGlmICh2ID09IDApCiAgICAgICAgewogICAgICAgICAgICByZXR1cm4gdTsKICAgICAgICB9CiAgICAgICAgaW50IHI7CiAgICAgICAgd2hpbGUgKHYgIT0gMCkKICAgICAgICB7CiAgICAgICAgICAgIHIgPSB1ICUgdjsKICAgICAgICAgICAgdSA9IHY7CiAgICAgICAgICAgIHYgPSByOwogICAgICAgIH0KICAgICAgICByZXR1cm4gdTsKICAgIH0KCiAgICAvL0NvbnN0cnVjdG9yCiAgICBwdWJsaWMgRnJhY2Npb24oaW50IE51bWVyYWRvciwgaW50IERlbm9taW5hZG9yKQogICAgewogICAgICAgIHZhciBkaXZpZGlyRW50cmUgPSBDYWxjdWxhcm1pbmltb0NvbXVuRGVub21pbmFkb3IoTnVtZXJhZG9yLCBEZW5vbWluYWRvcik7CiAgICAgICAgdGhpcy5OdW1lcmFkb3IgPSBOdW1lcmFkb3IgLyBkaXZpZGlyRW50cmU7CiAgICAgICAgdGhpcy5EZW5vbWluYWRvciA9IERlbm9taW5hZG9yIC8gZGl2aWRpckVudHJlOwogICAgfQoKICAgIC8vUHJvcGllZGFkZXMKICAgIHB1YmxpYyBpbnQgTnVtZXJhZG9yIHsgZ2V0OyB9CiAgICB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OzbgogICAgRnJhY2Npb24gZGl2ID0gZnJhYzEgLyBmcmFjMjsKICAgIENvbnNvbGUuV3JpdGVMaW5lKCJEaXZpc2nDs246ICIgKyBkaXYuVG9TdHJpbmcoKSk7CgogICAgLy9OZWdhY2nDs24KICAgIEZyYWNjaW9uIG5lZ2FkYSA9IC1mcmFjMTsKICAgIENvbnNvbGUuV3JpdGVMaW5lKCJOZWdhY2nDs24gZnJhYzE6ICIgKyBuZWdhZGEpOwoKICAgIC8vQ29tcGFyYW5kbyBjb24gY29tcGFyYWNpw7NuIGltcGzDrWNpdGEKICAgIENvbnNvbGUuV3JpdGVMaW5lKCLCv2ZyYWMxID4gZnJhYzI/OiAiICsgKGZyYWMxPmZyYWMyKSk7CiAgICBDb25zb2xlLldyaXRlTGluZSgiwr9mcmFjMSA8IGZyYWMyPzogIiArIChmcmFjMTxmcmFjMikpOwogIH0KfQo="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;

class Fraccion
{
    //Funcion para calcular el mínimo común denominador
    private int CalcularminimoComunDenominador(int Numerador, int Denominador)
    {
        int u = Math.Abs(Numerador);
        int v = Math.Abs(Denominador);
        if (v == 0)
        {
            return u;
        }
        int r;
        while (v != 0)
        {
            r = u % v;
            u = v;
            v = r;
        }
        return u;
    }

    //Constructor
    public Fraccion(int Numerador, int Denominador)
    {
        var dividirEntre = CalcularminimoComunDenominador(Numerador, Denominador);
        this.Numerador = Numerador / dividirEntre;
        this.Denominador = Denominador / dividirEntre;
    }

    //Propiedades
    public int Numerador { get; }
    public int Denominador { get; }

    //Overrides
    public override string ToString()
    {
        return $"{Numerador}/{Denominador}";
    }

    //Conversiones implícitas
    public static implicit operator double(Fraccion frac)
    {
        return Convert.ToDouble(frac.Numerador) / Convert.ToDouble(frac.Denominador);
    }
    public static implicit operator Fraccion(int escalar)
    {
        return new Fraccion(escalar, 1);
    }

    //Sobrecarga de operadores matemáticos
    //Suma
    public static Fraccion operator +(Fraccion frac1, Fraccion frac2)
    {
        var nuevoNumerador = frac1.Numerador * frac2.Denominador + frac2.Numerador * frac1.Denominador;
        var nuevoDenominador = frac1.Denominador * frac2.Denominador;
        return new Fraccion(nuevoNumerador, nuevoDenominador);
    }
    //Resta
    public static Fraccion operator -(Fraccion frac1, Fraccion frac2)
    {
        var nuevoNumerador = frac1.Numerador * frac2.Denominador - frac2.Numerador * frac1.Denominador;
        var nuevoDenominador = frac1.Denominador * frac2.Denominador;
        return new Fraccion(nuevoNumerador, nuevoDenominador);
    }
    //Negacion
    public static Fraccion operator -(Fraccion frac1)
    {
        return -1 * frac1;
    }
    //Multiplicación
    public static Fraccion operator *(Fraccion frac1, Fraccion frac2)
    {
        var nuevoNumerador = frac1.Numerador * frac2.Numerador;
        var nuevoDenominador = frac1.Denominador * frac2.Denominador;
        return new Fraccion(nuevoNumerador, nuevoDenominador);
    }
    //División
    public static Fraccion operator /(Fraccion frac1, Fraccion frac2)
    {
        var nuevoNumerador = frac1.Numerador * frac2.Denominador;
        var nuevoDenominador = frac1.Denominador * frac2.Numerador;
        return new Fraccion(nuevoNumerador, nuevoDenominador);
    }
}

class MainClass {
  public static void Main (string[] args) {
    Fraccion frac1 = new Fraccion(1,2);  //Representa 1/2, o sea 0.5
    Console.WriteLine("frac1: " +  frac1.ToString());
    Fraccion frac2 = new Fraccion(1,4);  //Representa 1/4, o sea 0.25
    Console.WriteLine("frac2: " +  frac2.ToString());

    //Suma
    Fraccion suma = frac1 + frac2;
    Console.WriteLine("Suma: " + suma.ToString());

    //Resta
    Fraccion resta = frac1 - frac2;
    Console.WriteLine("Resta: " + resta.ToString());

    //Multiplicación
    Fraccion multip = frac1 * frac2;
    Console.WriteLine("Multiplicación: " + multip.ToString());

    //Divisón
    Fraccion div = frac1 / frac2;
    Console.WriteLine("División: " + div.ToString());

    //Negación
    Fraccion negada = -frac1;
    Console.WriteLine("Negación frac1: " + negada);

    //Comparando con comparación implícita
    Console.WriteLine("¿frac1 > frac2?: " + (frac1>frac2));
    Console.WriteLine("¿frac1 < frac2?: " + (frac1<frac2));
  }
}