What programming language you start with really all depends on where you want to go with programming/coding. The great thing about this field is that there are an absolute abundance of smaller fields that you can go into, all using programming in their own unique ways. For web applications, a good start would be with HTML and later moving your way through CSS, JavaScript, JQuery, PHP, SQL, and any of the JavaScript libraries. Ruby is also a popular choice, so I would recommend checking that out too. For more scientific fields or areas with more machine learning and A.I., Python is generally a great place to start as it is widely used in that field of study. C++ is also a very useful language to know for that, but it can be a little more challenging for beginners. For game and application design, languages such as C#, C, Swift, Kotlin, and Java are most often used for that.
Description
It's Thanksgiving eve and you're expecting guests over for dinner tomorrow. Unfortunately, you were browsing memes all day and cannot go outside to buy the ingredients needed to make your famous pies. You find some spare ingredients, and make do with what you have. You know only two pie recipes, and they are as follows:
Pumpkin Pie
1 scoop of synthetic pumpkin flavouring (Hey you're a programmer not a cook)
3 eggs
4 cups of milk
3 cups of sugar
Apple Pie
1 apple
4 eggs
3 cups of milk
2 cups of sugar
Your guests have no preference of one pie over another, and you want to make the maximum number of (any kind) of pies possible with what you have. You cannot bake fractions of a pie, and cannot use fractions of an ingredient (So no 1/2 cup of sugar or anything like that)
Input Format
You will be given a string of 4 numbers separated by a comma, such as 10,14,10,42,24. Each number is a non-negative integer. The numbers represent the number of synthetic pumpkin flavouring, apples, eggs, milk and sugar you have (In the units represented in the recipes).
For instance, in the example input 10,14,10,42,24, it would mean that you have
10 scoops of synthetic pumpkin flavouring
14 apples
10 eggs
42 cups of milk
24 cups of sugar
Output Format
Display the number of each type of pie you will need to bake. For the example input, an output would be
3 pumpkin pies and 0 apple pies
Challenge Inputs
10,14,10,42,24
12,4,40,30,40
12,14,20,42,24
Challenge Outputs
3 pumpkin pies and 0 apple pies
5 pumpkin pies and 3 apple pies
5 pumpkin pies and 1 apple pies
Solution
in Python
pump = (1, 0, 3, 4, 3)
pie = (0, 1, 4, 3, 2)
recipes = {pump: "pumpkin", pie: "apple"}
def can_bake(ing, recipe):
return not any(i < j for i, j in zip(ing, recipe))
def bake(ing, recipe):
return tuple(i - j for i, j in zip(ing, recipe))
def solve(ing, hist=[]):
possible = []
for r in recipes:
if can_bake(ing, r):
testIng = bake(ing, r)
possible.append(solve(testIng, hist + [r]))
if possible:
return max(possible, key=lambda x: (len(x[1]), sum(x[0])))
return (ing, hist)
def pretty_output(hist):
for i in set(hist):
print("%d %s pies" % (hist.count(i), recipes[i]))
print()
pretty_output(solve((10, 14, 10, 42, 24))[1])
It's Thanksgiving eve and you're expecting guests over for dinner tomorrow. Unfortunately, you were browsing memes all day and cannot go outside to buy the ingredients needed to make your famous pies. You find some spare ingredients, and make do with what you have. You know only two pie recipes, and they are as follows:
Pumpkin Pie
1 scoop of synthetic pumpkin flavouring (Hey you're a programmer not a cook)
3 eggs
4 cups of milk
3 cups of sugar
Apple Pie
1 apple
4 eggs
3 cups of milk
2 cups of sugar
Your guests have no preference of one pie over another, and you want to make the maximum number of (any kind) of pies possible with what you have. You cannot bake fractions of a pie, and cannot use fractions of an ingredient (So no 1/2 cup of sugar or anything like that)
Input Format
You will be given a string of 4 numbers separated by a comma, such as 10,14,10,42,24. Each number is a non-negative integer. The numbers represent the number of synthetic pumpkin flavouring, apples, eggs, milk and sugar you have (In the units represented in the recipes).
For instance, in the example input 10,14,10,42,24, it would mean that you have
10 scoops of synthetic pumpkin flavouring
14 apples
10 eggs
42 cups of milk
24 cups of sugar
Output Format
Display the number of each type of pie you will need to bake. For the example input, an output would be
3 pumpkin pies and 0 apple pies
Challenge Inputs
10,14,10,42,24
12,4,40,30,40
12,14,20,42,24
Challenge Outputs
3 pumpkin pies and 0 apple pies
5 pumpkin pies and 3 apple pies
5 pumpkin pies and 1 apple pies
Solution
in Python
pump = (1, 0, 3, 4, 3)
pie = (0, 1, 4, 3, 2)
recipes = {pump: "pumpkin", pie: "apple"}
def can_bake(ing, recipe):
return not any(i < j for i, j in zip(ing, recipe))
def bake(ing, recipe):
return tuple(i - j for i, j in zip(ing, recipe))
def solve(ing, hist=[]):
possible = []
for r in recipes:
if can_bake(ing, r):
testIng = bake(ing, r)
possible.append(solve(testIng, hist + [r]))
if possible:
return max(possible, key=lambda x: (len(x[1]), sum(x[0])))
return (ing, hist)
def pretty_output(hist):
for i in set(hist):
print("%d %s pies" % (hist.count(i), recipes[i]))
print()
pretty_output(solve((10, 14, 10, 42, 24))[1])
Comments
Post a Comment