Can't see emoji? Click here.
You will simulate a vending machine. The items are 56 different emojis, which can be represented as two surrogate UTF-8 characters, from: 🍅(U+D83C U+DF45) to 🍼 (U+D83C U+DF7C). In HTML these emojis can be represented in UTF-16 form as 🍅 through 🍼. In base 10 the first UTF-8 character has value 55356. The value of the second character ranges from 57157 to 57212. Here is a CJam program that generates all the relevant emojis. To avoid confusion, this challenge will be scored in characters, not bytes. Some emojis are 2 characters, some are 3. http://www.lettercount.com will give you an accurate count for this challenge.
Pricing 💵💵💵
There are 8 different price categories:
- $1.00 : 🍅🍆🍇🍈🍉🍊🍋
- $1.50 : 🍌🍍🍎🍏🍐🍑🍒
- $2.00 : 🍓🍔🍕🍖🍗🍘🍙
- $2.50 : 🍚🍛🍜🍝🍞🍟🍠
- $3.00 : 🍡🍢🍣🍤🍥🍦🍧
- $3.50 : 🍨🍩🍪🍫🍬🍭🍮
- $4.00 : 🍯🍰🍱🍲🍳🍴🍵
- $4.50 : 🍶🍷🍸🍹🍺🍻🍼
Displaying the Vending Machine
This is what the user sees when the program starts and after making a purchase. You can use regular numbers instead of emoji numbers, but emoji numbers have the benefit of being the same width as other emojis. If you use emoji numbers you can subtract 14 characters from your score, because emoji numbers are 3 characters each.
1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣
A 🍅🍆🍇🍈🍉🍊🍋
B 🍌🍍🍎🍏🍐🍑🍒
C 🍓🍔🍕🍖🍗🍘🍙
D 🍚🍛🍜🍝🍞🍟🍠
E 🍡🍢🍣🍤🍥🍦🍧
F 🍨🍩🍪🍫🍬🍭🍮
G 🍯🍰🍱🍲🍳🍴🍵
H 🍶🍷🍸🍹🍺🍻🍼
If the user enters G5
that selects 🍳. Entering E6
selects 🍦.
Adding Cash 💸💸💸
To add money, the user should input /
and then the code for a coin or bill. The coins are (N)ickel ($0.05), (D)ime ($0.10), and (Q)uarter ($0.25). The bills are (O)ne ($1.00), (F)ive ($5.00), (T)en ($10.00). Every time the user adds a bill or coin, the program should output Balance: [New Balance]
. Only one bill or coin can be added each time.Here is an example containing three lines of input:
/D
Balance: $0.10
/Q
Balance: $0.35
/F
Balance: $5.35
Selecting Items
The user selects an item by entering the item code, like B2
or C3
. If the user has not added any money, the program should output Item Cost: [Cost of Item]
. If the user has added money, but it is not enough to buy the item, the output should be Insufficient Funds. Item Cost: [Cost of Item]
. If the user did add enough money, the program should output: Item at [Item Location] Purchased. Remaining Balance: [Balance - Cost of Item]
. Then on its own line, print out the emoji of the purchased item. Then print out the entire vending machine (See "Displaying the Vending Machine") with the purchased item replaced with 🚫(U+D83D U+DEAB) Base 10: (55357 57003).
Ending the Program
If the user buys an item which brings his/her balance down to $0.00, the program should automatically terminate. Alternatively, if the user enters "Done" at any time, the program must give the user his/her remaining balance in change. Change must be in only Nickels, Dimes, and Quarters, and must be the smallest amount of coins possible. For example if the remaining balance is $1.45, the output should be QQQQQDD
.
Sample Run
(Input starts with "-")
1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣
A 🍅🍆🍇🍈🍉🍊🍋
B 🍌🍍🍎🍏🍐🍑🍒
C 🍓🍔🍕🍖🍗🍘🍙
D 🍚🍛🍜🍝🍞🍟🍠
E 🍡🍢🍣🍤🍥🍦🍧
F 🍨🍩🍪🍫🍬🍭🍮
G 🍯🍰🍱🍲🍳🍴🍵
H 🍶🍷🍸🍹🍺🍻🍼
-E1
Item Cost: $3.00
-/F
Balance: $5.00
-E1
Item at E1 Purchased. Remaining Balance: $2.00
🍡
1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣
A 🍅🍆🍇🍈🍉🍊🍋
B 🍌🍍🍎🍏🍐🍑🍒
C 🍓🍔🍕🍖🍗🍘🍙
D 🍚🍛🍜🍝🍞🍟🍠
E 🚫🍢🍣🍤🍥🍦🍧
F 🍨🍩🍪🍫🍬🍭🍮
G 🍯🍰🍱🍲🍳🍴🍵
H 🍶🍷🍸🍹🍺🍻🍼
-Done
QQQQQQQQ
Invalid Codes
- If the input starts with
/
but is not a valid money input, outputMoney not Accepted
. - If the input is an item that has already been purchased, output
Item out of stock
- If the input is a digit-letter combination that is not in range (like
A0
orJ2
, output "Invalid code" - For all other invalid input, output "Error"
Bonus (-15%) : Jam
When vending an item, there is a 10% chance the machine will jam, and the item gets stuck. Output JAM!!!
one time. In this case the user must input "punch" or "kick". Each time the user does so, there is a 20% chance that the item will break free, and vend as normal. Until the jam clears, the only inputs recognized are "punch" and "kick". All other inputs do nothing.
Here is a sample:
-A4
Item at A4 purchased. Remaining Balance: $1.00
JAM!!!
-punch
-kick
-kick
-punch
-punch
🍚
(The jam has been cleared. Resume as normal.)
Bonus (-10%) : ID
If the user tries to buy an alcoholic beverage (any item on the last row except the baby bottle), you must demand proof of age. To do so, you ask the user to multiply two random numbers between 13 and 19 (inclusive). Output ID required: [13-19]x[13-19] = ?
. If the user answers correctly, the purchase can go through. If not, print 🔞(U+D83D U+DD1E) base 10: (55357 56606)
Alternative Challenge : Minecraft
This challenge seems like something possible in Minecraft. To successfully create a Minecraft version of this program, the player must
- Have an 8x7 grid to select from 56 unique items
- Be able to add money to the balance (Maybe use different types of stones for the different denominations described above.)
- Give the user the item he/she selects if they have put in enough "money"
- Return the user the appropriate amount of change at the end.
Compatibility Mode
I can only take input at the beginning of the program
- Not to worry, you can make a program that takes all input up front. If your program has not terminated after evaluating all input, assume that "Done" is called at the end. If you do this method, you will not be eligible for any bonuses.
I can't view/output emojis
- You can copy and paste your input and output into this Stack Snippet (or here). It can understand both unicode emojis and HTML codes for emojis. If your output looks correct on this page, your program passes. Try pasting in some of the sample input/output to see how it looks.
function parse() {
var o = document.getElementById("output");
var text = document.getElementById("in").value;
o.innerHTML = text.replace(/\n/g,"<br/>").replace(/ /g," ");
twemoji.parse(o);
}
<head>
<script src="//twemoji.maxcdn.com/twemoji.min.js"></script>
</head>
<body>
<h1>Emoji to Image</h1>
<textarea id="in" rows="10" cols="50"></textarea>
<input type="submit" onclick="parse()">
<div id="output"></div>
</body>
Here is an abbreviated compatibility-mode version of the vending machine display that you can test in the Stack Snippet:
1⃣2⃣3⃣4⃣5⃣...
A🍅🍆🍇🍈🍉...
B
...
I can output emojis, but not to STDOUT.
- Seemingly, the Mac OS X Terminal is the only one known to be able to output emojis. If you are not able to output emojis in your terminal, your other options are
- Send all output to a file.
- Display all output in a window.
- Use the technique described in "I can't view/output emojis".
- Seemingly, the Mac OS X Terminal is the only one known to be able to output emojis. If you are not able to output emojis in your terminal, your other options are
$ can be replaced with your local currency
doesn't make much sense if you then require that the coins be (N)ickels (D)imes and (Q)uarters. I suggest you remove it as it adds confusion. \$\endgroup\$$
symbol is part of the ASCII character set, so it's safe to assume pretty much all keyboards and languages can handle it. It is the only currency symbol in the 7-bit ASCII character set. As a result, other symbols such as the GBP symbol or the EUR symbol € can be incorrectly rendered due to incompatible string encodings, but it virtually never happens with$
. \$\endgroup\$$
symbol has special meaning in most programming languages, so not having it available on the keyboard would be a serious limitation. I'm typing this on my Spanish keyboard and it's actually easier to get $ (shift + 4) than € (alt gr + E) so you can see that the latter symbol added as an afterthought. \$\endgroup\$