Skip to content

Instantly share code, notes, and snippets.

@dluciano
Created July 25, 2017 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dluciano/cdd1d6827583c6205dcb0aa1a440de93 to your computer and use it in GitHub Desktop.
Save dluciano/cdd1d6827583c6205dcb0aa1a440de93 to your computer and use it in GitHub Desktop.
Recipe with base 2 in c#
using System;
public class Test
{
public static void Main()
{
int[] recetas = {1,2,4,8,16,32,64,128};
int X = 17;
Console.Write("Tenemos una receta de: ");
for(var z = X; z >= 1; ){
int log_2X = (int)Math.Log(z, 2);
int ingrediente = recetas[log_2X];
z = Math.Abs(z - ingrediente);
string result="";
switch(ingrediente)
{
case 1:
result = "cafe";break;
case 2:
result = "mantequilla";break;
case 4:
result = "arroz";break;
case 8:
result = "habichuela";break;
case 16:
result = "platanos";break;
case 32:
result = "lasaña";break;
case 64:
result = "te";break;
case 128:
result = "langosta";break;
}
Console.Write(result);
if(z >= 1)
Console.Write(", ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment