Login Register






Challenge - Medicine dosage filter_list
Author
Message
Challenge - Medicine dosage #1
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.).

Reply

RE: Challenge - Medicine dosage #2
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.
telegram: @satan_sl

Reply

RE: Challenge - Medicine dosage #3
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()
"If you look for the light, you can often find it. But if you look for the dark, that is all you will ever see.”


[+] 2 users Like Nil's post
Reply

RE: Challenge - Medicine dosage #4
(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.

Reply

RE: Challenge - Medicine dosage #5
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")

Reply

RE: Challenge - Medicine dosage #6
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.
[Image: CDUAq9d.png]

Reply

RE: Challenge - Medicine dosage #7
My solution is a shell script. Had about 29 minutes and 50 seconds to spare.
Code:
echo "overdose because you're a faggot"

[+] 3 users Like meow's post
Reply

RE: Challenge - Medicine dosage #8
(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://www.sinister.ly/Thread-Drugs-In-Your-Head
[Image: 7ajmN5P.jpg]

Telegram: Oni_SL (Link)

Reply

RE: Challenge - Medicine dosage #9
If you want the challenge to be challenging, drink a bottle of wine and do it in C, like I did ;3

[+] 1 user Likes Rou's post
Reply