Created
July 25, 2017 15:49
-
-
Save dluciano/cdd1d6827583c6205dcb0aa1a440de93 to your computer and use it in GitHub Desktop.
Recipe with base 2 in c#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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