13
2
Challenge:
Your job is to create a simple interpreter for a simple golfing language.
Input:
Input will be in the form of string separated by spaces.
You can replace space separation with what you want
Output:
Output the result (a number or a string) obtained after performing all operations. If there are more than one output join the together to give a single result (no separators). The variable's initial value is always zero. i.e: It start at 0
Language Syntax :
The language has following operators :
inc ---> add one to variable
dec ---> remove one from variable
mult ---> multiply variable by 2
half ---> divide the variable by 2
Pri ---> print the variable to console (or whatever your language has)
exit ---> end the program (anything after this is ignored)
Examples:
inc inc inc dec Pri exit ---> 2
dec inc mult inc inc Pri ---> 2
inc inc inc mult half Pri exit inc ---> 3
inc Pri inc Pri inc Pri exit half mult ---> 123
Pri exit ---> 0
inc half Pri exit ---> 0.5
Restriction:
This is code-golf so shortest code in bytes for each language will win.
Note:
- Input will always be valid . (string of operators separated with space)
- You can round down to nearest integer if you don't want decimal places.
3Can I take a list of strings? Can I use another capitalization? – user202729 – 2018-04-27T10:02:42.700
Add exit case? exit should matter – l4m2 – 2018-04-27T12:01:17.553
@MuhammadSalman how many decimal places should we support? Is it okay if we round down when dividing? – user41805 – 2018-04-27T13:01:54.417
@Cowsquack : I guess 2 decimal places will be fine , although yeah you can round down if you want. – Muhammad Salman – 2018-04-27T13:03:17.493
So does that mean it is okay that
inc half Pri
gives 0 instead of 0.5? – user41805 – 2018-04-27T13:03:49.883@l4m2 : What do you mean ? – Muhammad Salman – 2018-04-27T13:04:08.197
@Cowsquack : No , this should return 0.5 or 1 , No zero if even a single operation is performed. (I am willing to change it if it makes golfing easier since these things barely matter) – Muhammad Salman – 2018-04-27T13:06:06.437
@MuhammadSalman let's continue this conversation in chat
– user41805 – 2018-04-27T13:07:02.537Is it possible to separate each printed value with newlines or should they all be on the same line ? – Kaldo – 2018-04-27T14:38:53.373
1@Kaldo : You can separate using new lines – Muhammad Salman – 2018-04-27T15:00:59.473
3Hmm, I wouldn't call that language "golfing language". – Paŭlo Ebermann – 2018-04-28T11:49:59.163
@PaŭloEbermann : Haha , Well I agree , but golfing language it is – Muhammad Salman – 2018-04-28T12:57:40.837
1
This is Deadfish with double and half instead of square and longer command names
– Jo King – 2018-04-30T03:42:41.860Should
Pri
print out without newline? – idrougge – 2018-04-30T13:24:32.107@idrougge : Yes – Muhammad Salman – 2018-04-30T14:38:11.050