Sinisterly
Challenge - Medicine dosage - Printable Version

+- Sinisterly (https://sinister.li)
+-- Forum: Coding (https://sinister.li/Forum-Coding)
+--- Forum: Coding (https://sinister.li/Forum-Coding--71)
+--- Thread: Challenge - Medicine dosage (/Thread-Challenge-Medicine-dosage)



Challenge - Medicine dosage - Rou - 01-10-2016

So I participated in a programming challenge by a company specializing in medical software recently.

You have 30 minutes to solve a challenge, and you're not allowed to see the challenge text before the timer starts running. Obviously you don't have the actual time limit I had when solving this challenge, but be honest and do your best in 30 minutes. You can use any language you want. (I used C, because why not? It's a challenge, goddammit!)

Start the timer NOW. The challenge includes the time taken to read and understand the challenge text!

The challenge is as follows:
Spoiler:
In 30 minutes, create a program that takes an arbitrary string as input after the program has started.
Let X and Y be whole decimal numerics, and apply the following rules:
When the input is "X", print "X units per day."
When the input is "X*Y", print "X units Y times a day."
When the input is "X+Y", print "X units morning, Y units night."

Example:
Given the input "5", the corresponding output should be "5 units per day."

(Command line arguments are ignored. E.g. running the program as "./program 5" would be insufficient.)


(I finished the challenge with about 250 seconds to spare. I've also had an entire bottle of Hungarian Olaszrizling white wine. This challenge was thrown at me by a colleague who wants to start a business with me. I was also given a 5 second penalty every time the program was run.).


RE: Challenge - Medicine dosage - Satan - 01-10-2016

So basically its just repeating the given input with aa specific layout?

I mean you could do that with Visual Basic in about twenty seconds...

I don't know if I'm just not understanding the rules or not.


RE: Challenge - Medicine dosage - Nil - 01-10-2016

Python3 Solution
Code:
import re def main(): dosage = input('Enter the dosage: ') parsed = re.split("([+/*])", dosage.replace(" ", "")) if '+' in parsed: print(parsed[0], 'units morning,', parsed[2],'units night.') elif '*' in parsed: print(parsed[0],'units',parsed[2],'times a day.') else: print(parsed[0],'units per day.') main()



RE: Challenge - Medicine dosage - Rou - 01-10-2016

(01-10-2016, 02:38 AM)Maddison Wrote: So basically its just repeating the given input with aa specific layout?

I mean you could do that with Visual Basic in about twenty seconds...

I don't know if I'm just not understanding the rules or not.
Yeah, it's a very simple challenge. It's like FizzBuzz, but with string parsing instead.


RE: Challenge - Medicine dosage - Rick - 01-11-2016

I'm pretty shit at this type of thing tbh

Code:
def intcheck(x): try: if int(x) == float(x): return True else: return False except: return False def conc(x): t = "" for i in x: t += i return t check = False while True: inp = input("Input: ") inplist = list(inp) if "*" in inp: X = conc(inplist[0:inplist.index("*")]) Y = conc(inplist[inplist.index("*")+1:len(inplist)]) if intcheck(X) and intcheck(Y): print(X," units ",Y," times a day.") elif "+" in inp: X = conc(inplist[0:inplist.index("*")]) Y = conc(inplist[inplist.index("*")+1:len(inplist)]) if intcheck(a) and intcheck(b): print(X," units morning, ",Y," units night.") elif intcheck(inp): print(inp," units per day.") else: print("Incorrect syntax")



RE: Challenge - Medicine dosage - Shebang - 01-11-2016

Not only did I finish this in a few minutes, it's pretty short as well! This is Python 2.

Code:
f=input() i=2*('+'in f)+('*'in f) print["%s units per day.","%s units %s times a day.","%s units morning, %s units night."][i]%tuple(f.split('.*+'[i]))

Example Input:
Code:
"4+10"

Example Output:
Code:
4 units morning, 10 units night.



RE: Challenge - Medicine dosage - meow - 01-11-2016

My solution is a shell script. Had about 29 minutes and 50 seconds to spare.
Code:
echo "overdose because you're a faggot"



RE: Challenge - Medicine dosage - Oni - 01-11-2016

(01-11-2016, 02:18 AM)meow Wrote: My solution is a shell script. Had about 29 minutes and 50 seconds to spare.
Code:
echo "overdose because you're a faggot"

Drugs in your head.

Spoiler:
https://sinister.li/Thread-Drugs-In-Your-Head



RE: Challenge - Medicine dosage - Rou - 01-11-2016

If you want the challenge to be challenging, drink a bottle of wine and do it in C, like I did ;3