elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Ingresar Registrarse
12 Octubre 2008, 11:55  



  Mostrar Mensajes
Páginas: [1]
1  Programación / Ejercicios / Re: Ejercicios C# en: 21 Agosto 2008, 11:37
respecto al metodo Fibonacci. ArcheritONE le dio un bonito toque, sin embargo esta incorrecto. Al igual que el mio en parte, explico:
si n=0 en el problema de Fibonacci tenemos que la sucecion no tiene solucion. Y es facilmente demostrable.
Luego si n<=2 el resultado siempre sera 1 como corresponde.
Quedaria entonces de la siguiente manera.
   public static long Fibonacci(int n)
        {
            if (n == 0) throw new InvalidOperationException();
            else return (n <= 2) ? 1 : Fibonacci(n - 2) + Fibonacci(n - 1);
        }
saludos
2  Programación / Ejercicios / Re: Ejercicios C# en: 10 Julio 2008, 08:22
Ejercicio #7 Mi solucion recursiva no debe ser la mas optima. Pero he tenido que pensarla unos cuantos dias para hacerla. Asi que buena o mala aqui esta. El algoritmo recursivo para toda la cadena sale en 3 lineas pero para un numero espesifico de caracteres es un poco mas complicado. En este caso mi codigo les permite espesificar el numero de caracteres a combinar con todos los caracteres de un array de caracteres. El constructor te pide el archivo a crear o guardar el index, que son la cantidad de caracteres a combinar y finalmente un array de caracteres como referencia. Agradecimientos especiales al primo William UH, ya que sin el no hubiera esclarecido algunas dudas respecto a la combinatoria en general.
Citar
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ECDundy.Programmer
{
    class ECDundy_Combinatorial
    {
        static void Main(string[] args)
        {

            char[] arr = new char[26] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
            Combinatorial p = new Combinatorial(@"c:\Combinations.txt", 4, arr);
            p.Create();

        }

    }
class Combinatorial
    {
        private  char[] Elements;
        private  string Result, FileName;
        private  List<string> _List;
        private  int Count,Index;
        StreamWriter writer;
        public  Combinatorial(string FileName, int Index, params char[] Elements)
        {
            this.FileName = FileName;
            this.Elements = Elements;
            this.Index = Index;
            writer = new StreamWriter(FileName);
            Count=-1;
            Result = "";
            _List = new List<string>();
         
        }
        public void Create() { Combining_Characters(Elements, Result, _List, Index); writer.Close(); }
        private  void Combining_Characters(char[] Elements, string Result, List<string> _List, int Index)
        {
            char[] temp = new Char[Index];
            string temp2 = "";

            if (Result.Length == Elements.Length)
            {
                Count++;
                for (int i = Elements.Length - 1, k = 0; i > (Elements.Length) - Index - 1; i--, k++)
                {
                    temp[k] = Result;
                }
                temp2 = new string(temp);
                if (!_List.Contains(temp2))
                {
                    _List.Add(temp2);
                   
                    Write_Text(temp2);
                }
            }
            else
            {
                for (int i = 0; i < Elements.Length; i++)
                {
                    if (Count == _List.Count) break;
                    else Combining_Characters(Elements, Result + Elements, _List, Index);
                }
            }
        }
        private  void Write_Text(string str)
        {
            try
            {
                        writer.WriteLine(str);
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex);
            }

        }
    }
}
3  Programación / Ejercicios / Re: Ejercicios C# en: 28 Junio 2008, 12:02
Respuesta al ejercicio #8
         public static void Write_Text(string str,string FileName)
        {

            try
            {
                if (File.Exists(FileName))
                {
                    using (StreamWriter writer = new StreamWriter(FileName))
                    {
                        string[] Separated = str.Split(' ');
                        foreach (string k in Separated)
                        {
                            writer.WriteLine(k);
                        }
                        writer.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error" + ex);
            }

        }
4  Programación / Ejercicios / Re: Ejercicios C# en: 15 Junio 2008, 02:53
Respuesta al ej #6using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace letras_a_numeros
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(enletras(Console.ReadLine()));
            Console.ReadLine();
        }

        public static string enletras(string nu)
        {

            string res, dec = "";

            Int64 int_s;

            int tens;

            double nro;

            try
            {

                nro = Convert.ToDouble(num);

            }

            catch
            {

                return "";

            }

            int_s = Convert.ToInt64(Math.Truncate(nro));

            tens = Convert.ToInt32(Math.Round((nro - int_s) * 100, 2));

            if (tens > 0)
            {

                dec = " CON " + tens.ToString() + "/100";

            }

            res = toText(Convert.ToDouble(int_s)) + dec;

            return res;

        }

        private static string toText(double value)
        {

            string Num2Text = "";

            value = Math.Truncate(value);

            if (value == 0) Num2Text = "CERO";

            else if (value == 1) Num2Text = "UNO";

            else if (value == 2) Num2Text = "DOS";

            else if (value == 3) Num2Text = "TRES";

            else if (value == 4) Num2Text = "CUATRO";

            else if (value == 5) Num2Text = "CINCO";

            else if (value == 6) Num2Text = "SEIS";

            else if (value == 7) Num2Text = "SIETE";

            else if (value == 8) Num2Text = "OCHO";

            else if (value == 9) Num2Text = "NUEVE";

            else if (value == 10) Num2Text = "DIEZ";

            else if (value == 11) Num2Text = "ONCE";

            else if (value == 12) Num2Text = "DOCE";

            else if (value == 13) Num2Text = "TRECE";

            else if (value == 14) Num2Text = "CATORCE";

            else if (value == 15) Num2Text = "QUINCE";

            else if (value < 20) Num2Text = "DIECI" + toText(value - 10);

            else if (value == 20) Num2Text = "VEINTE";

            else if (value < 30) Num2Text = "VEINTI" + toText(value - 20);

            else if (value == 30) Num2Text = "TREINTA";

            else if (value == 40) Num2Text = "CUARENTA";

            else if (value == 50) Num2Text = "CINCUENTA";

            else if (value == 60) Num2Text = "SESENTA";

            else if (value == 70) Num2Text = "SETENTA";

            else if (value == 80) Num2Text = "OCHENTA";

            else if (value == 90) Num2Text = "NOVENTA";

            else if (value < 100) Num2Text = toText(Math.Truncate(value / 10) * 10) + " Y " + toText(value % 10);

            else if (value == 100) Num2Text = "CIEN";

            else if (value < 200) Num2Text = "CIENTO " + toText(value - 100);

            else if ((value == 200) || (value == 300) || (value == 400) || (value == 600) || (value == 800)) Num2Text = toText(Math.Truncate(value / 100)) + "CIENTOS";

            else if (value == 500) Num2Text = "QUINIENTOS";

            else if (value == 700) Num2Text = "SETECIENTOS";

            else if (value == 900) Num2Text = "NOVECIENTOS";

            else if (value < 1000) Num2Text = toText(Math.Truncate(value / 100) * 100) + " " + toText(value % 100);

            else if (value == 1000) Num2Text = "MIL";

            else if (value < 2000) Num2Text = "MIL " + toText(value % 1000);

            else if (value < 1000000)
            {

                Num2Text = toText(Math.Truncate(value / 1000)) + " MIL";

                if ((value % 1000) > 0) Num2Text = Num2Text + " " + toText(value % 1000);

            }

            else if (value == 1000000) Num2Text = "UN MILLON";

            else if (value < 2000000) Num2Text = "UN MILLON " + toText(value % 1000000);

            else if (value < 1000000000000)
            {

                Num2Text = toText(Math.Truncate(value / 1000000)) + " MILLONES ";

                if ((value - Math.Truncate(value / 1000000) * 1000000) > 0) Num2Text = Num2Text + " " + toText(value - Math.Truncate(value / 1000000) * 1000000);

            }

            else if (value == 1000000000000) Num2Text = "UN BILLON";

            else if (value < 2000000000000) Num2Text = "UN BILLON " + toText(value - Math.Truncate(value / 1000000000000) * 1000000000000);

            else
            {

                Num2Text = toText(Math.Truncate(value / 1000000000000)) + " BILLONES";

                if ((value - Math.Truncate(value / 1000000000000) * 1000000000000) > 0) Num2Text = Num2Text + " " + toText(value - Math.Truncate(value / 1000000000000) * 1000000000000);

            }

            return Num2Text;

        }

    }

}
5  Programación / Ejercicios / Re: msdos(ayuda comandos) en: 01 Mayo 2008, 01:58
1- start (*.exe)
2- skill (proceso)
3- start telnet
4- telnet o ip
6  Programación / Ejercicios / Re: ejercicio en c#/tipo consola en: 01 Mayo 2008, 01:21
Estos son los errores que me da en .net 2003
C:\Class1.cs Line (236): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (18): Operator '>' cannot be applied to operands of type 'int[]' and 'int'
C:\Class1.cs Line (20): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (21): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (35): Operator '<' cannot be applied to operands of type 'int[]' and 'int'
C:\Class1.cs Line (37): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (38): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (53): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (54): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (67): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (68): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (172): Operator '<' cannot be applied to operands of type 'int[]' and 'int'
C:\Class1.cs Line (180): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (181): Cannot implicitly convert type 'int' to 'int[]'
C:\Class1.cs Line (199): Operator '>' cannot be applied to operands of type 'int[]' and 'int'
C:\Class1.cs Line (207): Cannot implicitly convert type 'int[]' to 'int'
C:\Class1.cs Line (208): Cannot implicitly convert type 'int' to 'int[]'

Tienes demasiado codigo iterado un codigo recursivo en la mayoria de los casos resolveria mucho mas rapido el problema
7  Programación / Ejercicios / Re: Ejercicios C# en: 01 Mayo 2008, 01:12
Esta es mi solucion recursiva al ejercicio #5(En particular este ejercicio me ah dejado dudas en cuanto a si mi codigo esta suficientemente optimisado) Espero que lo disfruten tal como yo:

using System;

namespace piramide
{
   class Class1
   {
      static void Main(string[] args)
      {      
for (int i=0;i<80;i++)
{
   Piramide p = new Piramide();
   p.Show (i);
}
      }
      

   }
   class Piramide
   {
      bool flag;
      int val,val1;
      public void Show(int n)
      {
         string esp=" ";
         string ast="*";
         if(n==0&&!flag)Console.WriteLine();
         else if (n==1&&!flag)Console.WriteLine(ast);
         else if (n==2&&!flag)Console.WriteLine(ast+ast);
         else
         {
            if(!flag)
            {
               val1=n;
               val=(n-1)/2;
               flag=true;
            }
            for (int i=0;i<val-1;i++)esp+=" ";
            for (int k=1;k<val1-2*(esp.Length);k++)ast+="*";
            Console.Write(esp+ast);
            Console.WriteLine();
            val--;
            if(esp.CompareTo(" ")!=0)Show(val);
            else
            {
               for(int j=0; j<val1;j++)Console.Write("*");
               Console.WriteLine ();
            }
         }
      }
   }
}

8  Programación / Ejercicios / Re: Ejercicios C# en: 30 Abril 2008, 10:30
esta es mi solucion recursiva al ej 4
public static int fibonacci(int k)
      {
         int fib;
         if (k<=2)
         {
            fib =1;
         }
         else
         {
            fib= fibonacci(k-1)+ fibonacci(k-2);
         }
         return fib;
      }
Páginas: [1]






Consolas     La Web de Goku     MilW0rm     MundoDivx

Hispabyte     Truzone     TodoReviews     ZonaPhotoshop

hard-h2o modding    Foros de ayuda    Yashira.org    Videojuegos    indetectables.net   

Noticias Informatica    Seguridad Informática    ADSL    Foros en español    eNYe Sec

Todas las webs afiliadas están libres de publicidad engañosa.

Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC
Free counter and web stats