[Question]
      [
In Elixir, (linked) lists are in the format `[head | tail]` where **head** can be anything and **tail** is a list of the rest of the list, and `[]` - the empty list - is the only exception to this.
Lists can also be written like `[1, 2, 3]` which is equivalent to `[1 | [2 | [3 | []]]]`
Your task is to convert a list as described. The input will always be a valid list (in Elixir) containing only numbers matching the regex `\[(\d+(, ?\d+)*)?\]`. You may take the input with (one space after each comma) or without spaces. The output may be with (one space before and after each `|`) or without spaces.
For inputs with leading zeroes you may output either without the zeroes or with.
Input must be taken as a string (if writing a function), as does output.
## Examples
```
[] -> []
[5] -> [5 | []]
[1, 7] -> [1 | [7 | []]]
[4, 4, 4] -> [4 | [4 | [4 | []]]]
[10, 333] -> [10 | [333 | []]]
```
[related](https://codegolf.stackexchange.com/questions/126410/sugar-free-syntax), not a duplicate as this in part involves adding mode `]` to the end. Additionally, the Haskell answer here is quite different to the one there.

[Answer]
## Haskell, 50 bytes
```
f.read
f(a:b)='[':show(a+0)++'|':f b++"]"
f _="[]"
```
[Try it online!](https://tio.run/##JclLDoMgEADQvaeYzAYIaPrdkHAET0CJGa2gES2RJt307KVpunmbN1FexhhLMLfim32ke@U56V4YZpnO0@PFSR6ElOzNtIdeSnRYeegMWodlpXkDAyultgOe9nl7NkGA/aVCe/yrTuqsLurq0JXP4COFXOohpS8 "Haskell – Try It Online")
The `+0` lets the Haskell type checker know that we are dealing with lists of numbers, so `read` will parse the input string for us.
[Answer]
# [Python 2](https://docs.python.org/2/), 50 bytes
```
r='%s'
for x in input():r%='[%s|%%s]'%x
print r%[]
```
[Try it online!](https://tio.run/##K6gsycjPM/qfnJ@SaqukpPS/yFZdtVidKy2/SKFCITMPiApKSzQ0rYpUbdWjVYtrVFWLY9VVK7gKijLzShSKVKNj/wO1cXGlVqQmK4BM0TL9Hx3LFW0KxIY6CuZAykRHAYRAAgY6CsbGxrEA "Python 2 – Try It Online")
[Answer]
# JavaScript (ES6), 50 bytes
```
s=>eval(s).map(v=>`[${p+=']',v}|`,p='[]').join``+p
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/Y1i61LDFHo1hTLzexQKPM1i4hWqW6QNtWPVZdp6y2JkGnwFY9OlZdUy8rPzMvIUG74H9yfl5xfk6qXk5@ukaahlJ0rJKmJhe6oClWUUMdBXOsEiY6CiCEXZOBjoKxsTFI7j8A "JavaScript (Node.js) – Try It Online")
---
# Recursive version, 51 bytes
```
f=(s,[v,...a]=eval(s))=>1/v?`[${v}|${f(s,a)}]`:'[]'
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/f8/zVajWCe6TEdPTy8x1ja1LDFHo1hT09bOUL/MPiFapbqstkalOg2oJlGzNjbBSj06Vv1/cn5ecX5Oql5OfrpGmoZSdKySpiYXuqApVlFDHQVzrBImOgoghF2TgY6CsbExSO4/AA "JavaScript (Node.js) – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~39~~ ~~33~~ ~~32~~ 20 bytes
```
\b]
,]
+`,(.*)
|[$1]
```
Saved 13 bytes thanks to H.PWiz, ovs, ASCII-only, and Neil.
[Try it online!](https://tio.run/##K0otycxLNPz/PyYplksnlks7QUdDT0uTqyZaxTD2//9oEx0gjOWKjgUA "Retina – Try It Online")
### Explanation
```
\b]
,]
```
If we don't have an empty list, add a trailing comma.
```
+`,(.*)
|[$1]
```
While there are commas, wrap things with `|[ thing ]`.
[Answer]
# [Perl 5](https://www.perl.org/) `-pl`, ~~31~~ 28 bytes
```
s/\d\K]/,]/;$\=']'x s/,/|[/g
```
[Try it online!](https://tio.run/##K0gtyjH9/79YPyYlxjtWXydW31olxlY9Vr1CoVhfR78mWj/9//9oYx2j2H/5BSWZ@XnF/3ULcv7r@prqGRgaAAA "Perl 5 – Try It Online")
# How?
```
-p                    # (command line) Implicit input/output via $_ and $\
s/\d\K]/,]/;          # insert a comma at the end if the list is not empty
$\=']'x s/,/|[/g      # At the end of the run, output as many ']' as there are
                      # commas in the input.  Replace the commas with "|["
```
[Answer]
# [Elixir](https://elixir-lang.org/), ~~111~~ 85 bytes
```
f=fn[h|t],f->"[#{h}|#{f.(t,f)}]"
[],_->"[]"
h,f->f.(elem(Code.eval_string(h),0),f)end
```
[Try it online!](https://tio.run/##S83JrMgs@v8/zTYtLzqjpiRWJ03XTilauTqjtka5Ok1Po0QnTbM2VokrOlYnHiQDZGaA1AClUnNSczWc81NS9VLLEnPii0uKMvPSNTI0dQw0gZpS81L@e/rrFZSWFCsAFStFm@gogFCsElCSC0XG0EBHwdjYGIsMWOg/AA "Elixir – Try It Online")
I have never used Elixir before. Defines a function that takes a string and a reference to itself and returns a string.
[Answer]
# [Ceylon](https://ceylon-lang.org), 113 bytes
```
String p(String s)=>s.split(" ,[]".contains).select((x)=>!x.empty).reversed.fold("[]")((t,h)=>"[``h`` | ``t``]");
```
[Try it online!](https://try.ceylon-lang.org/?gist=e3d815b7459bfe561287963eea4aaef5)
Here is it written out:
```
// define a function p mapping Strings to Strings.
String p(String s) =>
    // we split the string at all characters which are brackets, comma or space.
    s.split(" ,[]".contains)    // → {String+}, e.g.  { "", "1", "7", "" }
    // That iterable contains empty strings, so let's remove them.
    // Using `select` instead of `filter` makes the result a sequential instead of
    // an Iterable.
     .select((x)=>!x.empty)    // → [String*], e.g.   [1, 7]
    // now invert the order.
    // (This needs a Sequential (or at least a List) instead of an Iterable.)
     .reversed                 // → [String*], e.g.   [7, 1]
    // Now iterate over the list, starting with "[]", and apply a function
    // to each element with the intermediate result.
     .fold("[]")                       // → String(String(String, String))
    //    This function takes the intermediate result `t` (for tail) and an element
    //    `h` (for head), and puts them together into brackets, with a " | " in the
    //    middle. This uses String interpolation, I could have used `"+` and `+"`
    //    instead for the same length.
          ((t,h)=>"[``h`` | ``t``]");  // → String
```
[Try it online!](https://try.ceylon-lang.org/?gist=60089c0d591e519aa80079ae130ca435)
As noted by ovs in a (now deleted) comment: If one select the "without spaces" options for input and output indicated in the question, one can safe 3 more bytes (the obvious ones with spaces in them).
If we don't need to parse the input, but just could get a sequence as input, it gets much shorter (69 bytes).
```
String p(Object[]s)=>s.reversed.fold("[]")((t,h)=>"[``h`` | ``t``]");
```
[Try it online!](https://try.ceylon-lang.org/?gist=6235914fe86ec21c8ce1c327022165b0)
[Answer]
# [Python 3](https://docs.python.org/3/), 65 bytes
```
lambda k:"["+''.join(f"{u}|["for u in eval(k))+-~len(eval(k))*"]"
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHbSilaSVtdXS8rPzNPI02purS2JlopLb9IoVQhM08htSwxRyNbU1Nbty4nNU8DxtVSilX6X1CUmVeikaahFG2iA4WxSpqa/wE "Python 3 – Try It Online")
If the input could be a list instead, then:
**[Python 3](https://docs.python.org/3/), 53 bytes**
```
lambda k:"["+''.join(f"{u}|["for u in k)+-~len(k)*"]"
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHbSilaSVtdXS8rPzNPI02purS2JlopLb9IoVQhM08hW1Nbty4nNU8jW1NLKVbpf0FRZl6JRppGtIkOFMZqav4HAA "Python 3 – Try It Online")
[Answer]
# [SNOBOL4 (CSNOBOL4)](http://www.snobol4.org/csnobol4/), 114 bytes
```
	I =INPUT
S	N =N + 1
	I SPAN(1234567890) . L REM . I	:F(O)
	O =O '[' L ' | '	:(S)
O	OUTPUT =O '[' DUPL(']',N)
END
```
[Try it online!](https://tio.run/##NYw9C4MwFADnl1/xtpfQUIzaLyFDQQsB@xKMmcSlc6lD1/73mKXTwR3c97O9tnebMzi0jkOaRQRGy3hAA6LYGO4sTd20p/PleqsUHnHEaXgWOuge0isBHq1HWqgUwh8SdDIq4cGnuRz/sU9hlLSSZiUG7nNejDa1btYd "SNOBOL4 (CSNOBOL4) – Try It Online")
```
	I =INPUT				;* read input
S	N =N + 1				;* counter for number of elements (including empty list)
	I SPAN(1234567890) . L REM . I	:F(O)	;* get value matching \d until none left
	O =O '[' L ' | '	:(S)		;* build output string
O	OUTPUT =O '[' DUPL(']',N)		;* print O concatenated with a '[' and N copies of ']'
END
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 19 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
É▲²:WlÖ└%ï╪☺╒▓"We↨Φ
```
[Run and debug it](https://staxlang.xyz/#p=901efd3a576c99c0258bd801d5b222576517e8&i=[1,+2,+3]&a=1)
My first Stax post, so probably not optimal.
Unpacked and commented:
```
U,                      Put -1 under input
  {                     Block
   i                      Push loop index, needed later
    '[a$'|++              Wrap the element in "[...|"
            m           Map
             '[+        Add another "["
                s2+     Get the latest loop index + 2
                   ']*+ Add that many "]"
```
[Run and debug this one](https://staxlang.xyz/#c=U,+++++++++++++++++++++%09Put+-1+under+input%0A++%7B++++++++++++++++++++%09Block%0A+++i+++++++++++++++++++%09++Push+loop+index,+needed+later%0A++++%27[a%24%27%7C%2B%2B+++++++++++%09++Wrap+the+element+in+%22[...%7C%22%0A++++++++++++m++++++++++%09Map%0A+++++++++++++%27[%2B+++++++%09Add+another+%22[%22%0A++++++++++++++++s2%2B++++%09Get+the+latest+loop+index+%2B+2%0A+++++++++++++++++++%27]*%2B%09Add+that+many+%22]%22&i=[1,+2,+3])
[Answer]
# [Husk](https://github.com/barbuz/Husk), 22 bytes
```
+:'[J"|[":msr¹₁*₁Lr
"]
```
[Try it online!](https://tio.run/##yygtzv7/X9tKPdpLqSZaySq3uOjQzkdNjVpA7FPEpRT7//9/pWhDAx1jY@NYJQA "Husk – Try It Online")
[Answer]
# [Befunge-98 (PyFunge)](https://pythonhosted.org/PyFunge/), ~~22~~ 21 bytes
```
'[,1;@j,]';#$&." |",,
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tNAtqAQz//9Xj9YxtHbI0olVt1ZWUdNTUqhR0tH5/z/aREcBhGIB "Befunge-98 (PyFunge) – Try It Online")
If there weren't weird restrictions on output, we could do this in 18:
```
'[,1;@j,]';#$&.'|,
```
Fun fact, this is technically a program that does nothing in Python.
[Answer]
# [Ruby](https://www.ruby-lang.org/) `-p`, 39 bytes
Full program:
```
$_[$&]="|[#$2]"while/(,|\d\K(?=]))(.*)/
```
[Try it online!](https://tio.run/##KypNqvz/XyU@WkUt1lapJlpZxShWqTwjMydVX0OnJiYlxlvD3jZWU1NDT0tT////6FiuaFMgNtQxB5ImOkAI4hnoGBsbx/7LLyjJzM8r/q9bAAA "Ruby – Try It Online")
### [Ruby](https://www.ruby-lang.org/), ~~48~~ 45 bytes
Recursive function:
```
f=->s{(s[/,|\d\K(?=])/]&&="|[")&&f[s+=?]]||s}
```
[Try it online!](https://tio.run/##RYxNCoMwEIX3PUVIISiN1RDFVfQAPcI4i/6FLksTF8Xx7GmCNDLw4H3f8D7z7RuCNdXglsJBLWl6TJdiNFjWKIThBLwUwoI7mRGRyK0BDhyQyyOrBgYYS5dbxyiixJTsM1WJ9ptKrpXxsm2T2AO3H9VIrfU@0SQXyX8Fz8/r/bWQp/fsHbPgcQ0/ "Ruby – Try It Online")
[Answer]
# [R](https://www.r-project.org/), ~~84~~ ~~71~~ 69 bytes
```
function(x){while(x<(x=sub('(,|\\d\\K(?=]))(.+)','|[\\2]',x,,T)))1;x}
```
[Try it online!](https://tio.run/##K/qfpmCj@z@tNC@5JDM/T6NCs7o8IzMnVaPCRqPCtrg0SUNdQ6cmJiYlJsZbw942VlNTQ09bU11HvSY6JsYoVl2nQkcnRFNT09C6ovZ/moZSdKySJheINoUxDHXMYUwTHSCEixvoGBsbA3n/AQ "R – Try It Online")
* -15 bytes thanks to @KirillL.
[Answer]
# [Proton](https://github.com/alexander-liao/proton), 57 bytes
```
k=>"["+''.join(str(u)+"|["for u:(e=eval(k)))+-~len(e)*"]"
```
[Try it online!](https://tio.run/##LcKxCoAgEADQX4lbvMtqagrsR8Sh4QRTVEybol@3Jd7LJdUUu1Xdqx00SCGWM7mIVy3YSMKjwaYytA1Z8X0E9EQk5zdwRKYRDPRcXKxoEfQ6/QwQ9Q8 "Proton – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 19 bytes
```
ŒV©;€⁾|[”[;µ®L‘”]ẋṭ
```
[Try it online!](https://tio.run/##AToAxf9qZWxsef//xZJWwqk74oKs4oG@fFvigJ1bO8K1wq5M4oCY4oCdXeG6i@G5rf///ydbMTAsIDMzM10n "Jelly – Try It Online")
A non-recursive alternative to [Erik's solution](https://codegolf.stackexchange.com/a/163849/59487).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 18 bytes
```
ŒVḢ,ŒṘÇ”|;ƲƊ¹¡⁾[]j
```
[Try it online!](https://tio.run/##ATYAyf9qZWxsef//xZJW4biiLMWS4bmYw4figJ18O8ayxorCucKh4oG@W11q////J1sxMCwgMzMzXSc "Jelly – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 18 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
ŒVµ⁾[]jj⁾|[ṫ3;”]ṁ$
```
A full program printing the result (as a monadic link it accepts a list of characters but returns a list of characters and integers).
**[Try it online!](https://tio.run/##y0rNyan8///opLBDWx817ouOzcoCUjXRD3euNrZ@1DA39uHORpX///@rRxsa6CgYGxvHqgMA "Jelly – Try It Online")**
### How?
```
ŒVµ⁾[]jj⁾|[ṫ3;”]ṁ$ - Main link: list of characters  e.g. "[10,333]"
ŒV                 - evaluate as Python code              [10,333]
  µ                - start a new monadic chain, call that X
   ⁾[]             - list of characters                   ['[',']']
      j            - join with X                          ['[',10,333,']']
        ⁾|[        - list of characters                   ['|','[']
       j           - join                                 ['[','|','[',10,'|','[',333,'|','[',']']
           ṫ3      - tail from index three                ['[',10,'|','[',333,'|','[',']']
                 $ - last two links as a monad (f(X)):
              ”]   -   character                          ']'
                ṁ  -   mould like X                       [']',']'] (here 2 because X is 2 long)
             ;     - concatenate                          ['[',10,'|','[',333,'|','[',']',']',']']
                   - implicit (and smashing) print        [10|[333|[]]]
```
[Answer]
# Java 10, 107 bytes
```
s->{var r="[]";for(var i:s.replaceAll("[\\[\\]]","").split(","))r="["+i+"|"+r+"]";return s.length()<3?s:r;}
```
[Try it online.](https://tio.run/##jY9BTsMwEEX3PcXIK1txLSAgpKYFcQC6YZlmYVy3uHWdaOxEQiVnDxOIWKLIY2nG/vP1/kl3ennanwfjdYzwql24LgBcSBYP2ljYjiPAW0IXjmD41ERR0HtPlyomnZyBLQTYwBCXT9dOI@CGlRUrDjXycXSrqNA2nkxfvOes3O2oqopJxoSKjXeJUy/EuMcyl7EvlmHGyAJtajFAVN6GY/rgYp0/xxUW/VD8AjTtuyeAiaOr3R4ulGSCLSstphSfMdmLqtukGvpJPvCgDB85xU@gfyQPMzS38nGW6k7mM3T3ks4MuxuZ539@/aIfvgE)
**Explanation:**
```
s->{                       // Method with String as both parameter and return-type
  var r="[]";              //  Result-String, starting at "[]"
  for(var i:s.replaceAll("[\\[\\]]","")
                           //  Removing trailing "[" and leading "]"
             .split(","))  //  Loop over the items
    r="["+i+"|"+r+"]";     //   Create the result-String `r`
  return s.length()<3?     //  If the input was "[]"
          s                //   Return the input as result
         :                 //  Else:
          r;}              //   Return `r` as result
```
[Answer]
# [Standard ML](http://www.mlton.org/), 71 bytes
```
fun p[_]="]|[]]"|p(#","::r)="|["^p r^"]"|p(d::r)=str d^p r;p o explode;
```
[Try it online!](https://tio.run/##HchLCsMgEADQfU8xTDcJWGixq4gnkTEUjBAwOhgTuvDu5rN7vHUJryWUFFvzWwQ2I2mkaoiwcvdEgcOQe43VoGXIFu93d64lg7tWMSSY/hySm1TbfwE8aJiLelweT3OeY@k8oPm8hZRSfAn7dgA "Standard ML (MLton) – Try It Online") Uses the format without spaces. E.g. `it "[10,333,4]"` yields `"[10|[333|[4]|[]]]]"`.
**ungolfed**
```
fun p [_]       = "]|[]]"          (* if there is only one char left we are at the end *)
  | p (#","::r) = "|[" ^ p r ^ "]" (* a ',' in the input is replaced by "|[" and an closing "]" is added to the end *)
  | p (d::r)    = str d ^ p r      (* all other chars (the digits and the initial '[') are converted to a string and concatenated to recursive result *)
val f = p o explode  (* convert string into list of chars and apply function p *)
```
[Try it online!](https://tio.run/##NYtBCsMgFET3nmL43SRgocWuAj2J/IaCEQpGxdjShXe3mtBZzOK9mW1159Xl4Gu1b48IPTOO3EFcNDNBAKWp4USSpimNXRVNeDSYWhPTf2J2v7@3nGCOjRCfp4NtMCJg@UYXzFI7mztLL58HC9LXi1RKyRvTWH8 "Standard ML (MLton) – Try It Online")
[Answer]
# [R](https://www.r-project.org/), ~~140~~ 136 bytes
Down 4 bytes as per Giuseppe's sound advice.
```
function(l,x=unlist(strsplit(substr(l,2,nchar(l)-1),", ")))paste(c("[",paste0(c(x,"]"),collapse=" | ["),rep("]",length(x))),collapse="")
```
[Try it online!](https://tio.run/##TYxBC8IwDIXv/oqQUwMZbE7x4n7J8FBL5walK2sLPfjfayZMhEC@l5f3tjrdmzplb9KyeuW4DNm7JSYV0xaDWwTyU1isM3szayFqOmJkQCIKOiarjMIR@cutiML4QGKzOqdDtAPCG0Y5bDYocdhZ/0qzKpL/e0Kqk/RI8rTv6wEdw@3gC8M@P6tl6PteZP0A "R – Try It Online")
[Answer]
# [R](https://www.r-project.org/), 108 bytes
```
function(l)Reduce(function(x,y)paste0("[",x,"|",y,"]"),eval(parse(t=sub("]",")",sub("\\[","c(",l)))),"[]",T)
```
[Try it online!](https://tio.run/##PYpNCsIwEIX3niLMagaeUIniRi9R3LUuYkxBCLU0ibTg3WMqtMOD@d7PmDt12ecu9Ta@3j17qd0zWcdbMmGWwYToKqaGMIG@hBl0J4H7GM@DGYPjeA3pwSUFCeHPbVv2ZJngpRyoKe1NcscLyW75pxUOUOeVj1CLtqqC0loXm38 "R – Try It Online")
It took almost a year to find a better R solution than previous...should have known `Reduce` would be the answer! Outputs without spaces, input can be with or without spaces.
[Answer]
# [Python 2](https://docs.python.org/2/), 63 bytes
```
lambda s:'['+'|['.join(map(str,eval(s))+[']'])+']'*len(eval(s))
```
[Try it online!](https://tio.run/##RU7dCoIwFL6upzh3Z8shmoogrBdZu1ilZMw5dAWB724by4LDd873w8exb3cfzXHt@HnVarjcFMwNCkxwEZg@xt6QQVkyu4m1L6XJTGkiUKKkiceDbg3Z9LUbJ@iNZTA@nfUXCIFCIoOAkoFnVaQVLCDkJuYM6qjnQa@jubklgzAxUAbvD/IfyzMGRVF8e7Lgevqrks1@Z6feuPgh8pMPdsQTum3Ow9/p1Fqtri1BQIZI1w8 "Python 2 – Try It Online")
[Answer]
# sed + `-E`, 46 bytes
```
:
s/\[([0-9]+)(, ?([^]]*)|())\]/[\1 | [\3]]/
t
```
A fairly straightforward approach. The second line takes `[\d+, ...]` and changes it to `[\d | [...]]`. The third line jumps back to the first line, if the substitution was successful. The substitution repeats until it fails and then the program terminates. Run with `sed -E -f filename.sed`, passing input via stdin.
[Answer]
# [Red](http://www.red-lang.org), 110 bytes
```
func[s][if s ="[]"[return s]replace append/dup replace/all b: copy s",""|[""]"(length? b)- length? s"]""|[]]"]
```
[Try it online!](https://tio.run/##VY3BCsIwEETv/YplTwqRKlGEgvgPXsMe0mSjhZCGpDkI/nuMoEiZy7yZgUls642tos4N1ZVgVCY1OchwQUWoEi8lBciUOHptGHSMHGxvS4Rv1GvvYRzAzPEJGQXiSyESbjyH@/K4wrjdwc/nVrSeCKnGNIUFHHyOuj@cVnQQ5xUfRdN6sRdSSsL6Bg "Red – Try It Online")
## Explanation of the ungolfed version:
```
f: func[s][
    if s = "[]" [return s]                    ; if the list is empty, return it
    b: copy s                                 ; save a copy of the input in b
    replace/all b "," "|["                    ; replace every "," with "|["
    append/dup b "]" (length? b) - length? s  ; append as many "]" as there were ","
    replace b "]" "|[]]"                      ; replace the first "]" with "|[]]"
]                                             ; the last value is returned implicitly
```
[Red](http://www.red-lang.org) is so easily readable, that I doubt I needed adding the above comments :)
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), 38 bytes
```
{'['~S:g/\s|.<($/\|\[/~']'x$_+1}o&EVAL
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPu/Wj1avS7YKl0/prhGz0ZDRT@mJiZav049Vr1CJV7bsDZfzTXM0ee/NVdxYqVCmoJStKGOkY5xrBJCwBSZY6hjjsyNVfoPAA "Perl 6 – Try It Online")
]


[Question]
      [
## Introduction
The challenge itself was something I came across and had to try and figure out for a personal of project of mine. I ended up branching out and asking family members if they could provide an equation to meet the requirements.
**Note:** I have (with the help of others) found a solution for this but now I'm just trying to see how others would approach this.
## Challenge
Take the following scenario where the left hand side number is N (the input):
```
N    Output
0 -> 9
1 -> 99
2 -> 999
3 -> 9999
4 -> 99,999
5 -> 999,999
...
15 -> 9,999,999,999,999,999
```
So, essentially, for an input number **N**, your program must provide the highest integer with **N + 1** decimal places.
**Note:** Commas are not required to separate the numbers, I placed them above purely for readability.
## Criteria of Success
The criteria of success is based on the following:
* Shortest in terms of code size

[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 3 bytes
### Code:
```
>¬∞<
```
Uses the **05AB1E** encoding. [Try it online!](https://tio.run/##MzBNTDJM/f/f7tAGm///TQA "05AB1E ‚Äì Try It Online")
### Explanation:
```
>      # Increment the implicit input
 ¬∞     # Compute 10 ** (input + 1)
  <    # Decrement the result
```
[Answer]
# [Neim](https://github.com/okx-code/Neim), 3 bytes
```
>9ùï£
```
Explanation:
```
>      Increment input
 9ùï£    Repeat 9
```
[Try it online!](https://tio.run/##y0vNzP3/387yw9ypi///NwUA "Neim ‚Äì Try It Online")
[Answer]
# [Proton](https://github.com/alexander-liao/proton), 11 bytes
```
(1+)+("9"*)
```
[Try it online!](https://tio.run/##KyjKL8nP@59m@1/DUFtTW0PJUklL839BUWZeiUaahomm5n8A "Proton ‚Äì Try It Online")
This is a function.
# Explanation
```
(1+)+("9"*)  Function
 1+          Anonymous function; add the input to 1
      "9"*   Anonymous function; multiply "9" by the input
    +        Function Composition; add the input to 1 then multiply "9" by this number
(  ) (    )  Brackets for order of operations
```
:o proton beats python with its function composition for once :D
[Answer]
# [J](http://jsoftware.com/), 7 bytes
Anonymous tacit prefix function
```
9^&.>:]
```
[Try it online!](https://tio.run/##y/r/P83WyjJOTc/OKvZ/anJGvkKagoGCoYKRgrGCiYKpgqFpxX8A "J ‚Äì Try It Online")
`9^`‚Ä¶`]`‚ÄÉnine raised to the power of the argument
‚ÄÉ`&.`‚Ä¶‚ÄÉwhile both nine and the argument are under the influence of
‚ÄÉ‚ÄÉ`>:`‚ÄÉincrement
I.e. increment nine and the argument, then power, then un-increment, i.e. decrement. Effectively `((9+1)^(n+1))-1`.
[Answer]
# APL+WIN, ~~9~~ 5 bytes
Thanks to ngn for -3 bytes and Ad√°m for -1 byte
Prompts for integer input:
```
1‚éï/‚çï9
```
[Answer]
# [99](https://github.com/TryItOnline/99), 90 bytes
```
 999
9999 9 9
99999 99 9 9999 9
999 999 9999 9

99999
999 999 9
 999999 999
 9 9999
```
[Try it online!](https://tio.run/##s7T8/1/B0tKSC4gtFYAQzADSYA6YxQXhw7mcnJxcIABWiJDkAstDeFxQzf//mwAA "99 ‚Äì Try It Online")
Possibly not optimal, but it was fun to write.
EDIT: looks like I was right, as [Jo King outgolfed me](https://codegolf.stackexchange.com/a/163816/67312) by not incrementing the input and being smarter about the gotos.
```
 999			assign input to tri-nine
9999 9 9		assign 0 to quad-nine
99999 99 9 9999 9	assign 81 to quint-nine for printing
999 999 9999 9		increment tri-nine

99999			print 81/nine (the numeral nine)
999 999 9		decrement tri-nine
 999999 999		if tri-nine is zero exit program (goto outside program)
 9 9999			else goto line nine
```
[Answer]
# [*99*](https://github.com/TryItOnline/99), 69 bytes
```
9999 9 9
99999 99 9 9999 9
 999
99999
 99 999
999 999 9
 9 9999
```
[Try it online!](https://tio.run/##s7T8/98SCBSAkMsSwgJzwCwuEM0FAWBJLrCsJVipAkwJWDHQGAA "99 ‚Äì Try It Online")
Appropriate (but it's a pity that this didn't end up at 99 bytes)
### Explanation
```
9999 9 9           9999 = 9-9
99999 99 9 9999 9  99999 = 99-9+(9-9)-9 = 9*9
 999               999 = input*9
Filler to get up to line 9
99999      Print (9*9)/9 as a number
 99 999    Jump to line 99 if 999 is 9-9
999 999 9  999 = 999 - 9
 9 9999    Jump unconditionally to line 9
```
[Answer]
# [Actually](https://github.com/Mego/Seriously), 3 bytes
```
u‚ï§D
```
Explanation:
```
u    Increment input
 ‚ï§   10 ** x
  D  Decrement
```
[Try it online!](https://tio.run/##S0wuKU3Myan8/7/00dQlLv//mwIA "Actually ‚Äì Try It Online")
[Answer]
# [MATL](https://github.com/lmendo/MATL), 6 bytes
```
Q10w^q
```
[Try it online!](https://tio.run/##y00syfn/P9DQoDyu8P9/YwA "MATL ‚Äì Try It Online")
### Explanation:
```
Q       % Grab input and increment by 1
 10     % Push 10
   w    % Swap stack
    ^   % Raise 10 to the power of input+1
     q  % Decrement by 1
```
[Answer]
# Pyth, 4
```
*\9h
```
[Online test](https://pyth.herokuapp.com/?code=%2A%5C9h&input=0%0A1%0A2%0A3%0A4%0A5%0A15&test_suite=1&test_suite_input=0%0A1%0A2%0A3%0A4%0A5%0A15&debug=0).
### Explanation
```
    Q  # Implicit input
   h   # Increment
*\9    # Repeat string "9" n+1 times
```
[Answer]
# [dc](https://www.gnu.org/software/bc/manual/dc-1.05/html_mono/dc.html), 8
```
A?1+^1-p
```
[Try it online!](https://tio.run/##S0n@/9/R3lA7zlC34P9/EwA "dc ‚Äì Try It Online")
### Explanation
```
A         # Push 10
 ?        # Push input
  1+      # Increment input
    ^     # Raise 10 to the (input + 1)th power
     1-   # Decrement
       p  # Print
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~14~~ 13 bytes
```
f n=10*10^n-1
```
Or for string output 15 bytes, `f n='9'<$[0..n]`
Thanks to @EsolangingFruit for a byte.
[Try it online!](https://tio.run/##y0gszk7Nyfn/P00hz9bQIE4jT9tQU9fwf25iZp6CrUJBaUlwSZFPnoKSn4KCgn9pCVBAScHOTiE3scA3XkEjJlPXTkEDokqvOCO/XDMTJAsRUFBSeNQ2SQGsvqAoM69EQSNNIVNTUyHaQE/PNPY/AA "Haskell ‚Äì Try It Online")
[Answer]
# [Zsh](https://www.zsh.org/), 19 bytes
[Zsh](https://www.zsh.org/) does a better job than [Bash](https://www.gnu.org/software/bash/) ([needs eval](https://tio.run/##S0oszvj/P7UsMUehoCgzryRNwVJVr1ih2kBPT8Ww9v///4YA)):
```
printf 9%.s {0..$1}
```
[Try it online!](https://tio.run/##qyrO@P@/oCgzryRNwVJVr1ih2kBPT8Ww9v///4YA "Zsh ‚Äì Try It Online")
### Alternative, 20 bytes
This works for both [Zsh](https://www.zsh.org/) and [Bash](https://www.gnu.org/software/bash/) (due to [Digital Trauma](https://codegolf.stackexchange.com/users/11259/digital-trauma?tab=profile)):
```
echo $[10**($1+1)-1]
```
[Try it online!](https://tio.run/##qyrO@P8/NTkjX0El2tBAS0tDxVDbUFPXMPb////GAA "Zsh ‚Äì Try It Online")
[Answer]
# [Python 3](https://docs.python.org/3/), 16 bytes
```
lambda a:"9"*-~a
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUSHRSslSSUu3LvF/QVFmXolGmoaJpuZ/AA "Python 3 ‚Äì Try It Online")
Just a simple anonymous function.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 18 bytes
```
x=>"9".repeat(x+1)
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/C1k7JUkmvKLUgNbFEo0LbUPN/cn5ecX5Oql5OfrpGmoappibXfwA "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 4 bytes
```
‚Äò‚Åµ*‚Äô
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw4xHjVu1HjXM/P//vykA "Jelly ‚Äì Try It Online")
```
‚Äò‚Åµ*‚Äô - Main link. Argument: n (integer)
‚Äò    - n+1
 ‚Åµ*  - 10 ** (n+1)
   ‚Äô - (10 ** (n+1)) - 1
```
[Answer]
# [Husk](https://github.com/barbuz/Husk), 4 bytes
```
R'9‚Üí
```
[Try it online!](https://tio.run/##yygtzv7/P0jd8lHbpP///xsAAA "Husk ‚Äì Try It Online")
```
R'9‚Üí  -- example input: 3
   ‚Üí  -- increment: 4
R'9   -- replicate the character '9': ['9','9','9','9']
      -- implicitly print "9999"
```
[Answer]
# [Canvas](https://github.com/dzaima/Canvas), 3 [bytes](https://github.com/dzaima/Canvas/blob/master/files/chartable.md)
```
‚ïµ9√ó
```
[Try it here!](https://dzaima.github.io/Canvas/?u=JXUyNTc1OSVENw__,i=NQ__,v=2)
```
‚ïµ    increment the input
 9   push "9"
  √ó  repeat the "9" input+1 times
```
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 48 bytes
```
({}()){({}<(((((()()()){}()){}){}){}())>[()])}{}
```
[Try it online!](https://tio.run/##SypKzMzTTctJzP7/X6O6VkNTsxpI2WiAgSYIakJEayEIyLSL1tCM1aytrv3/3/C/riMA "Brain-Flak ‚Äì Try It Online")
This uses the `-A` to enable ASCII output. Bonus round: A version without `-A`.
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 50 bytes
```
({}(())){({}<((({})(({}){}){}){})>[()])}{}({}[()])
```
[Try it online!](https://tio.run/##SypKzMzTTctJzP7/X6O6VkNDU1OzGsiw0dAAkppgAo7sojU0YzVrgcqqa8HM//8NAQ "Brain-Flak ‚Äì Try It Online")
[Answer]
# [Momema](https://github.com/ScratchMan544/momema), 21 bytes
```
a00+1*0-8 9a=+*0-+1_A
```
[Try it online!](https://tio.run/##y83PTc1N/P8/0cBA21DLQNdCwTLRVhvI0DaMd/z/39LS8l9@QUlmfl7xf91MAA "Momema ‚Äì Try It Online") Requires the `-i` interpreter flag.
## Explanation
A brief rundown of Momema's features:
* Its only data type is the unbounded integer. It has a double-ended tape (indexed by unbounded integers) where every number is initialized to zero.
* Strings of digits are integer literals which evaluate to themselves. Leading zeroes are parsed as their own integers.
* `+ab` evaluates to the sum of `a` and `b`.
* `-a` evaluates to the negation of `a`.
* `*a` evaluates to the value of cell `a` on the tape.
* `=a` evaluates to 0 if `a` evaluates to 0, and `=` otherwise.
* At the top level, `ab` stores `b` at cell `a` on the tape. Attempting to write a number to `-8` writes its decimal representation to STDOUT instead.
* At the top level, `[w]a` (where `[w]` is any string of lowercase letters) acts like "relative jump forward by `a` jump instructions that share the label `[w]`."
* The Momema reference implementation accepts a flag `-i`, which activates interactive mode. In interactive mode, `_[W]` (where `[W]` is any string of uppercase letters) is called a *hole* and evaluates to a number read from STDIN. However, it caches the number with its label, so if a hole with the same label is ever evaluated again it will be reused.
Knowing this, here's how you expand this program:
```
a   0                                                                                # do {
0   (+ 1 (* 0))                                                                             #   n = n + 1
-8  9                                                                                #   print 9
a   (= (+ (* 0) (- (+ 1 _A))))                                                              # while (n != input)
```
(This still parses, by the way; the Momema parser treats parentheses the same way as whitespace.)
---
```
a   0
```
Jumps forward by 0 `a` instructions (i.e. does nothing). This is only here to serve as a jump target later.
```
0   (+ 1 (* 0))
```
Increments the value of cell 0 (initially 0) and stores it back in cell 0.
```
-8  9
```
`-8` is memory-mapped for numeric I/O, so this outputs `9` to STDOUT.
```
a   (= (+ (* 0) (- (+ 1 _A))))
```
Compute `tape[0] - (input + 1)`. If it is zero (i.e. both sides were equal), then `=` maps the result to 0, making it a no-op. Control runs off of the end of the program. However, if it is nonzero, this is a `1`. Since there are no `a` instructions after here, it wraps around to the beginning of the program.
[Answer]
# [brainfuck](https://github.com/TryItOnline/brainfuck), ~~24~~ 23 bytes
thanks to [Jo King](https://codegolf.stackexchange.com/users/76162/jo-king) for -1 byte
```
-[++>+[+<]>]>+<,+[->.<]
```
[Try it online!](https://tio.run/##SypKzMxLK03O/v9fN1pb2047Wtsm1i7WTttGRzta107PJvb/f04A "brainfuck ‚Äì Try It Online") Takes input as ASCII
[Answer]
# [Whitespace](https://web.archive.org/web/20150618184706/http://compsoc.dur.ac.uk/whitespace/tutorial.php), 79 bytes
```
[S S S T    S T S N
_Push_10][S N
S _Duplicate_10][S N
S _Duplicate_10][S N
S _Duplicate_10][T  N
T   T   _Read_STDIN_as_integer][T   T   T   _Retrieve_input][N
S S N
_Create_Label_LOOP][S S S T N
_Push_1][T  S S T   _Subtract][S N
S _Duplicate][N
T   T   S N
_If_negative_Jump_to_Label_EXIT][S N
T   _Swap][S T  S S T   S N
_Copy_2st][T    S S N
_Multiply][S N
T   _Swap][N
S N
N
_Jump_to_Label_LOOP][N
S S S N
_Create_Label_EXIT][T   S S S _Add][T   N
S T _Print_as_integer]
```
Letters `S` (space), `T` (tab), and `N` (new-line) added as highlighting only.
`[..._some_action]` added as explanation only.
[Try it online](https://tio.run/##K8/ILEktLkhMTv3/X0FBgRMIuYAQgji5OEEAwgXxFCDSnBBSAcLnVADzgJgLpAzEB6pV4Pz/3wQA) (with raw spaces, tabs and new-lines only).
**Explanation in pseudo-code:**
```
Integer i = STDIN as integer
Integer j = 10
Start LOOP:
  i = i - 1
  If i is negative (-1): Go to function PRINT_AND_EXIT
  j = j * 10
  Go to next iteration of LOOP
function PRINT_AND_EXIT:
  j = j + i (Since i=-1 at this point, this is basically j = j - 1)
  Print j as integer
  Exit with error
```
**Example run (`n=4`):**
```
Command   Explanation                   Stack              HEAP    STDIN   STDOUT  STDERR
SSSTSTSN  Push 10                       [10]
SNS       Duplicate top (10)            [10,10]
SNS       Duplicate top (10)            [10,10,10]
SNS       Duplicate top (10)            [10,10,10,10]
TNTT      Read STDIN as integer         [10,10,10]         {10:4}  4
TTT       Retrieve                      [10,10,4]          {10:4}
NSSN      Create Label_LOOP             [10,10,4]          {10:4}
 SSSTN     Push 1                       [10,10,4,1]        {10:4}
 TSST      Subtract (4-1)               [10,10,3]          {10:4}
 SNS       Duplicate top (3)            [10,10,3,3]        {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,10,3]          {10:4}
 SNT       Swap top two                 [10,3,10]          {10:4}
 STSSTSN   Copy 2nd                     [10,3,10,10]       {10:4}
 TSSN      Multiply (10*10)             [10,3,100]         {10:4}
 SNT       Swap top two                 [10,100,3]         {10:4}
 NSNN      Jump to Label_LOOP           [10,100,3]         {10:4}
 SSSTN     Push 1                       [10,100,3,1]       {10:4}
 TSST      Subtract (3-1)               [10,100,2]         {10:4}
 SNS       Duplicate top (2)            [10,100,2,2]       {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,100,2]         {10:4}
 SNT       Swap top two                 [10,2,100]         {10:4}
 STSSTSN   Copy 2nd                     [10,2,100,10]      {10:4}
 TSSN      Multiply (100*10)            [10,2,1000]        {10:4}
 SNT       Swap top two                 [10,1000,2]        {10:4}
 NSNN      Jump to Label_LOOP           [10,1000,2]        {10:4}
 SSSTN     Push 1                       [10,1000,2,1]      {10:4}
 TSST      Subtract (2-1)               [10,1000,1]        {10:4}
 SNS       Duplicate top (1)            [10,1000,1,1]      {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,1000,1]        {10:4}
 SNT       Swap top two                 [10,1,1000]        {10:4}
 STSSTSN   Copy 2nd                     [10,1,1000,10]     {10:4}
 TSSN      Multiply (1000*10)           [10,1,10000]       {10:4}
 SNT       Swap top two                 [10,10000,1]       {10:4}
 NSNN      Jump to Label_LOOP           [10,10000,1]       {10:4}
 SSSTN     Push 1                       [10,10000,1,1]     {10:4}
 TSST      Subtract (1-1)               [10,10000,0]       {10:4}
 SNS       Duplicate top (0)            [10,10000,0,0]     {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,10000,0]       {10:4}
 SNT       Swap top two                 [10,0,10000]       {10:4}
 STSSTSN   Copy 2nd                     [10,0,10000,10]    {10:4}
 TSSN      Multiply (10000*10)          [10,0,100000]      {10:4}
 SNT       Swap top two                 [10,100000,0]      {10:4}
 NSNN      Jump to Label_LOOP           [10,100000,0]      {10:4}
 SSSTN     Push 1                       [10,100000,0,1]    {10:4}
 TSST      Subtract (0-1)               [10,100000,-1]     {10:4}
 SNS       Duplicate top (-1)           [10,100000,-1,-1]  {10:4}
 NTTSN     If neg.: Jump to Label_EXIT  [10,100000,-1]     {10:4}
NSSSN      Create Label_EXIT            [10,100000,-1]     {10:4}
TSSS       Add (10000+-1)               [10,99999]         {10:4}
TNST       Print as integer             [10]               {10:4}          99999
                                                                                error
```
Stops program with error: No exit defined.
[Answer]
# [Japt](https://github.com/ETHproductions/japt), ~~5~~ 4 bytes
```
¬∞U√Æ9
```
[Try it online!](https://tio.run/##y0osKPn//9CG0MPrLP//NwYA)
Shaved off that one byte thanks to [Shaggy](https://codegolf.stackexchange.com/users/58974/shaggy)'s clever eyes. You can see the edit history for a number of 5-byte solutions.
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), 26 bytes
```
{for(;a++<$1;){printf"9"}}
```
[Try it online!](https://tio.run/##SyzP/v@/Oi2/SMM6UVvbRsXQWrO6oCgzryRNyVKptvb/f0NTAA "AWK ‚Äì Try It Online")
[Answer]
# Julia, 14 bytes
`f(n)="9"^(n+1)`
That's if the result can be a string.
[Answer]
# [SNOBOL4 (CSNOBOL4)](http://www.snobol4.org/csnobol4/), 30 bytes
```
	OUTPUT =DUPL(9,INPUT + 1)
END
```
[Try it online!](https://tio.run/##K87LT8rPMfn/n9M/NCQgNETB1iU0wEfDUsfTD8TTVjDU5HL1c/n/39AUAA "SNOBOL4 (CSNOBOL4) ‚Äì Try It Online")
[Answer]
# [Gol><>](https://github.com/Sp3000/Golfish), 5 bytes
```
PR`9H
```
[Try it online!](https://tio.run/##S8/PScsszvhv6Ohu6f4/ICjB0uP/fwA "Gol><> ‚Äì Try It Online")
This is a Gol><> function which takes the stack content as input.
### Example full program & How it works
```
1AG9G
PR`9H
1AG    Register row 1 as function G
   9G  Call G with stack [9]
P      Increment
 R`9   Push char '9' that many times
    H  Print the stack content as chars and halt
```
[Answer]
# TI-Basic, 7 bytes
```
10^(Ans+1)-1
```
Fairly straightforward...
[Answer]
# [CJam](https://sourceforge.net/p/cjam), 6 bytes
```
qi)'9*
```
[Try it online!](https://tio.run/##S85KzP3/vzBTU91S6/9/YwA "CJam ‚Äì Try It Online")
[Answer]
# [Perl 5](https://www.perl.org/), 7 bytes
```
$_=9x$_
```
[Try it online!](https://tio.run/##K0gtyjH9/18l3tayQiX@/3/Tf/kFJZn5ecX/dQsA "Perl 5 ‚Äì Try It Online")
]


[Question]
      [
## Introduction
The challenge itself was something I came across and had to try and figure out for a personal of project of mine. I ended up branching out and asking family members if they could provide an equation to meet the requirements.
**Note:** I have (with the help of others) found a solution for this but now I'm just trying to see how others would approach this.
## Challenge
Take the following scenario where the left hand side number is N (the input):
```
N    Output
0 -> 9
1 -> 99
2 -> 999
3 -> 9999
4 -> 99,999
5 -> 999,999
...
15 -> 9,999,999,999,999,999
```
So, essentially, for an input number **N**, your program must provide the highest integer with **N + 1** decimal places.
**Note:** Commas are not required to separate the numbers, I placed them above purely for readability.
## Criteria of Success
The criteria of success is based on the following:
* Shortest in terms of code size

[Answer]
# IBM/Lotus Notes Formula, 16 bytes
```
@Power(10;i+1)-1
```
Simple port of my Python answer. One of the nice things about formula is that if you pass it a list it will apply the same function to each list member.
[![enter image description here](https://i.stack.imgur.com/qJNpE.png)](https://i.stack.imgur.com/qJNpE.png)
[Answer]
# [Befunge-98 (FBBI)](https://github.com/catseye/FBBI), ~~13~~ 12 bytes
-1 byte thanks to [Jo King](https://codegolf.stackexchange.com/users/76162/jo-king)
```
&#9':_@#\-1,
```
[Try it online!](https://tio.run/##S0pNK81LT9W1tPj/X03ZUt0q3kE5RtdQ5/9/UwA "Befunge-98 (FBBI) – Try It Online")
[Answer]
# [Symbolic Python](https://github.com/FTcode/Symbolic-Python), ~~40~~ 37 bytes
```
__=-~(_==_)
_=(__+__**-~__)**-~_+~_+_
```
[Try it online!](https://tio.run/##K67MTcrPyUzWLagsycjP@/8/Pt5Wt04j3tY2XpMr3lYjPl47Pl5LS7cuPl4TTGkDUfz///8NAQ "Symbolic Python – Try It Online")
---
### Ungolfed
```
# implicit input stored in _
__  = -~(_==_)             # __ = -~True = 1 + True = 1 + 1 = 2
_=(__+__**-~__)**-~_+~_+_  # _  = (2 + 2 ** -~2) ** -~_ + ~_ + _
                                = (2 + 2**3) ** (_ + 1) - -~_ + _
                                = 10 ** (_ + 1) - (_ + 1) + _
                                = 10 ** (_ + 1) - 1
# implicit output of _
```
---
### other 37 byte solutions
```
__=_==_
_=(-~__*-~-~-~-~__)**-~_+~_+_
```
[Try it online!](https://tio.run/##K67MTcrPyUzWLagsycjP@/8/Pt423tY2niveVkO3Lj5eS7cOAuPjNbWAnHhtIIr///@/IQA "Symbolic Python – Try It Online")
```
_=(-~(_==_)*-~-~-~-~(_==_))**-~_+~_+_
```
[Try it online!](https://tio.run/##K67MTcrPyUzWLagsycjP@/8/3lZDt04j3tY2XlNLtw4CIVxNLaBAvDYQxf///98QAA "Symbolic Python – Try It Online")
---
# [Symbolic Python](https://github.com/FTcode/Symbolic-Python), 29 bytes
multiplies the string `'9'` by `_ + 1`
```
_=`-~-~(_==_)*-~-~(_==_)`*-~_
```
[Try it online!](https://tio.run/##K67MTcrPyUzWLagsycjP@/8/3jZBt063TiPe1jZeUwvBTACy4////28IAA "Symbolic Python – Try It Online")
[Answer]
# [Tcl](http://tcl.tk/), 26 bytes
```
puts [expr 10*10**$argv-1]
```
[Try it online!](https://tio.run/##K0nO@f@/oLSkWCE6taKgSMHQQAuItFQSi9LLdA1j////bwoA "Tcl – Try It Online")
[Answer]
# [Common Lisp](http://www.clisp.org/), 30 bytes
```
(lambda(n)(1-(expt 10(1+ n))))
```
[Try it online!](https://tio.run/##FcxNDkAwFEXhuVXcmLiNSBQben6aSJTiDSSiWy/O/DvDMp8h8Zx0h0tcxPejcDW0FacrKGxNW2I1X8lkdNvhRaF5vKNk8clBLwHFt1E4FKxh0aBF94MX "Common Lisp – Try It Online")
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~5~~ 4 bytes
```
×9⊕Ｎ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/19LQ8lSSUdBW1vDM6@gtMSvNDcptUhDU1Pz/3@D/7plOf91M/8b/jf6b/zf5L9u/n/L/5YgBMYQwhIA "Charcoal – Try It Online")
### Explanation
```
×9     Repeat "9"
  ⊕Ｎ ++(next number as input) times
```
[Answer]
# JavaScript (ES6), 18 bytes
Just throwing out a recursive solution to the problem:
```
f=n=>n?9+f(n-1):''
```
Evaluates the expression `''+9+9+9+9...` (depending on `n`).
Because the first operand is a string, all the `+` operators are treated as concatenation instead of addition.
In my Chrome, works up to `f(11424)` before hitting a stack overflow.
```
f=n=>n?9+f(n-1):''
for(i = 0; i < 100; i += 10) {
  console.log(f(i));
}
```
[Answer]
## PHP, 25 bytes
[Try it online](https://tio.run/##K8go@G9jX5BRwKWSWJReZmtoas1lbwcUsi0uKYovSi1ITSzRsNQBS2obalr//w8A)
**Code**
(Passing `$arguments` to the script)
```
<?=str_repeat(9,$argv+1);
```
**Or a recursive function, 42 Bytes**
[Try it online!](https://tio.run/##K8go@G9jXwAk00rzkksy8/MU0jRUSjWrU5Mz8oEMGwNNeyUlKyVLJT2QuK6hpnXt/zQNS03r/wA)
```
function f($u){echo($u<0)?"":"9".f($u-1);}
```
[Answer]
# [Phooey](https://github.com/ConorOBrien-Foxx/Phooey), 11 bytes
```
&.+1[$i9-1]
```
[Try it online!](https://tio.run/##K8jIz0@t/P9fTU/bMFol01LXMPb/f1MA "Phooey – Try It Online")
## Explanation
```
&.+1[$i9-1]
&.              take numeric input
  +1            add 1
    [   -1]     until that is zero:
     $i9        output 9s
```
[Answer]
# [Attache](https://github.com/ConorOBrien-Foxx/Attache), 9 bytes
```
{N!-~_&9}
```
[Try it online!](https://tio.run/##SywpSUzOSP2fpmBl@7/aT1G3Ll7Nsva/X2pqSnG0SkFBcnosV0BRZl5JSGpxiXNicWpxdJqOgoGVqbqhaex/AA "Attache – Try It Online")
## Alternatives
**10 bytes:** `{"9"*t-~_}`
**13 bytes:** (pointfree) `9&Resize@1&`+`
## Explanation
```
{N!-~_&9}
{       }     anonymous lambda taking input `_`
   -~_        input + 1
      &9      9s repeated that much (array of 9s)
 N!           cast to integer
```
[Answer]
# [Red](http://www.red-lang.org), 24 bytes
```
func[n][loop n[prin"9"]]
```
Outputs a string
[Try it online!](https://tio.run/##K0pN@R@UmhIdy5Vm9T@tNC85Oi82Oic/v0AhL7qgKDNPyVIpNvZ/UWpBamKJQq6CkQFYtEQhTSE39j8A "Red – Try It Online")
[Answer]
# [Python 2](https://docs.python.org/2/), ~~20~~ 18 bytes
```
lambda i:10**-~i-1
```
[Try it online!](https://tio.run/##K6gsycjPM/qfZhvzPycxNyklUSHTytBAS0u3LlPX8H9afpFChUJmnkJRYl56qoaRgaZVQVFmXolCmkaF5n8A "Python 2 – Try It Online")
Don't think it needs an explanation.
-2 with thanks to @ovs
[Answer]
# Java 8, ~~27~~ 25 bytes
```
n->n+=Math.pow(10,n+1)+~n
```
[Try it online.](https://tio.run/##hY/PDoIwDMbvPEWPW1AC/jkRfAO4cDQe5kAcjkKgYIzBV8cJXM2SNk37@5qvLcUgtmX2mKQWXQexUPh2ABRS3t6EzCH5tQC6xgIkmwvy0MxGkyY6EqQkJIAQwYTbE7pRLOjuNfWTBf4G3YC7H5zCRd70V23k69ZQqwwq48lSahUW5wsIvhimr47yyqt78hqDSCNDTzKfz@Z/eWDhOwvfW/jBwo@2@9YHRmecvg)
This is basically a shorter version of `n->(long)Math.pow(10,n+1)-1`, because `n+=...-n` saves a byte in comparison to `(long)...`. (And combining `-n-1` to `+~n` saves a second byte in this case.)
[Answer]
# Excel, 12 bytes
```
=10^(A1+1)-1
```
Or alternatively, to better handle larger values (`>10`) for `13 bytes`
```
=REPT(9,A1+1)
```
[Answer]
# [Ruby](https://www.ruby-lang.org/), 11 bytes
```
->n{?9*-~n}
```
[Try it online!](https://tio.run/##KypNqvyfZvtf1y6v2t5SS7cur/Z/QWlJsUJatEEsF5RlaBr7HwA "Ruby – Try It Online")
[Answer]
# [Swift 4](https://developer.apple.com/swift/), ~~47~~ ~~34~~ 32 bytes
~~-13~~ -15 bytes thanks to [@Mr. Xcoder](https://codegolf.stackexchange.com/users/59487/mr-xcoder)
```
{(0...$0).map{_ in"9"}.joined()}
```
[Try it online!](https://tio.run/##Ky7PTCsx@Z@TWqKQpmD7v1rDQE9PT8VAUy83saA6XiEzT8lSqVYvKz8zLzVFQ7P2f1p@kUImUFgBpM5EoVqhoCgzr0QjTSNTU1Oh9j8A "Swift 4 – Try It Online")
[Answer]
# Japt `-P`, 3 bytes
```
ò@9
```
[Try it](https://ethproductions.github.io/japt/?v=2.0a0&code=8kA5&input=OAotUA==)
---
## Explanation
```
ò       :Range [0,input]
 @      :Pass each through a function
  9     :  Return 9
        :Implicitly join and output
```
[Answer]
# [Cubix](https://github.com/ETHproductions/cubix), 15 bytes
```
Iu9)^>Os(?@.>sW
```
[Try it online!](https://tio.run/##Sy5Nyqz4/9@z1FIzzs6/WMPeQc@uOPz/f0sA "Cubix – Try It Online")
Expands to the following cube:
```
    I u
    9 )
^ > O s ( ? @ .
> s W . . . . .
    . .
    . .
```
[Answer]
# [Triangularity](https://github.com/Mr-Xcoder/Triangularity), 31 bytes
```
...)...
..IE@..
.)10^).
@_+....
```
[Try it online!](https://tio.run/##KynKTMxLL81JLMosqfz/X09PTxOIufT0PF0dQLSmoUGcph6XQ7w2UFjv/38TAA "Triangularity – Try It Online")
### Also 31 bytes
```
...)...
..IE)..
.@_rM..
"9"}""J
```
[Try it online!](https://tio.run/##KynKTMxLL81JLMosqfz/X09PTxOIufT0PF01QbRDfJEvkFayVKpVUvL6/98EAA "Triangularity – Try It Online")
[Answer]
# [GolfScript](http://www.golfscript.com/golfscript/), 6 bytes
```
~)'9'*
```
[Try it online!](https://tio.run/##S8/PSStOLsosKPmfp1r9v05T3VJd639erWqd9X8DLkMuIy5jLhMuUy4zLnMuCy5LLkNTAA "GolfScript – Try It Online")
Explanation:
```
~)'9'* Full program, implicit input
       Stack: '5'
~      Evaluate
       Stack: 5
 )     Increment
       Stack: 6
  '9'  Push '9'
       Stack: 6 '9'
     * Repeat
       Stack: '999999'
       Implicit output
```
## [GolfScript](http://www.golfscript.com/golfscript/), 7 bytes
```
~)10\?(
```
[Try this one!](https://tio.run/##S8/PSStOLsosKPmfp1r9v07T0CDGXuN/Xq1qnfV/Ay5DLiMuYy4TLlMuMy5zLgsuSy5DUwA "GolfScript – Try It Online")
Explanation:
```
~)10\?( Full program, implicit input
        Stack: '5'
~)      Evaluate and increment (as above)
        Stack: 6
  10\?  Raise 10 to that power
        Stack: 1000000
      ( Decrement
        Stack: 999999
        Implicit output
```
[Answer]
# [Stax](https://github.com/tomtheisen/stax), 4 bytes
```
^|Av
```
[Run and debug it](https://staxlang.xyz/#c=%5E%7CAv&i=15&a=1)
Packed would not be any shorter.
Explanation:
```
^|Av Full program, implicit input
^    Increment
 |A  Raise ten to that power
   v Decrement
     Implicit output
```
## [Stax](https://github.com/tomtheisen/stax), 4 bytes
```
^'9*
```
[Run and debug it](https://staxlang.xyz/#c=%5E%279*&i=15&a=1)
```
^'9* Full program, implicit input
^    Increment
 '9* Repeat "9"
     Implicit output
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/) (`-lm`), 22 bytes
```
f(n){n=pow(10,-~n)-1;}
```
[Try it online!](https://tio.run/##DcfBCoMwDADQs/mK4BgkYIcedqrbv0hrXaFGqZUdxH36sr3bc2ZyTjWQ8CGPdXlT1zbmI2w6e@oliku7H7Hfio/L7fUEiFJwHqIQ4wHVmv8PVF993WCgO7OFKo9lz4KthVO/LqRh2tSk@Qc "C (gcc) – Try It Online")
Saved 4 bytes thanks to Kevin Cruijssen.
[Answer]
# [Prolog (SWI)](http://www.swi-prolog.org), ~~34~~ ~~23~~ 20 bytes
```
X+Y:-Y is 10*10^X-1.
```
[Try it online!](https://tio.run/##HYyxCoMwFEV3v@IthaR5CXngZJXOznEwi@BgS@DRhKj4@Wna6R4OnJty5PjW@xVKmZXvtIewA9k72WXWZMoNXmvgM2/AMSY4ExwR2oaFQyfNf0fZade3OP1SpwhZTFWa5qlZ2Eo4Ko9XDscmvMQPIw32QUN9/wI "Prolog (SWI) – Try It Online")
Call as `<input>+<result variable>`.
]


[Question]
      [
# File Permissions
[code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'")
*Adapted from the UIL - Computer Science Programming free response question "Carla" for 2018 District.*
# Introduction
In UNIX-like operating systems, each file, directory, or link is "owned" by a "user", who is a member of a "group", and has certain "permissions" represented by a ten-character string such as "drwxrwxrwx". The first character is 'd', '-', or 'l' (directory, file, or link), followed by three sets of "rwx" values, indicating "read, write, execute" permissions. The first set is the user's rights, the middle set the group's rights, and the third everyone else's rights to that object.
Permission denied for any of these rights is represented by a '-' in place of the 'r', 'w', or 'x'. For example, a sample directory permission string would be "drwxr--r--", indicating full directory rights for the user, but "read-only" rights for the group member and all others.
**Each "rwx" combination can also be represented by an octal value (0-7) with the most significant bit representing read permission, the next most significant bit representing write permission, and the least significant bit representing execute permission.**
# Challenge
Given a four-character code string made up of a character: 'D', 'F', or 'L', followed by a three-digit octal integer value, like 664, output the resulting 10 character string that represents the permission value indicated.
# Input
Your program or function may either read the input from standard in (four characters will be entered, optionally followed by a newline) or be passed the input as an argument.
Your program may accept uppercase or lowercase inputs but must be consistent (either all inputs are uppercase or all inputs are lowercase).
# Output
Your program must print the resulting ten-character string that represents the permission value indicated in the exact format specified above. Tailing white space is allowed.
# Test Cases
In: `F664` Out: `-rw-rw-r--`
In: `D775` Out: `drwxrwxr-x`
In: `L334` Out: `l-wx-wxr--`
In: `F530` Out: `-r-x-wx---`
In: `D127` Out: `d--x-w-rwx`
# Scoring and Rules
* [Standard loop-holes](https://codegolf.meta.stackexchange.com/questions/1061/loopholes-that-are-forbidden-by-default) are forbidden.
* [Standard rules](https://codegolf.meta.stackexchange.com/questions/2419/default-for-code-golf-program-function-or-snippet/2422#2422) apply.
* Please provide a link to test your code as well as an explanation.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest answer in bytes wins!

[Answer]
## bash, ~~59~~ 53 bytes
```
chmod ${1:1} a>a;stat -c%A a|sed s/./${1:0:1}/|tr f -
```
Right tool for the job?
Thanks to [Dennis](https://codegolf.stackexchange.com/users/12012/dennis) for saving 5 bytes and [HTNW](https://codegolf.stackexchange.com/users/50062/htnw) for saving one.
[Try it online!](https://tio.run/##S0oszvj/PzkjNz9FQaXa0MqwViHRLtG6uCSxREE3WdVRIbGmODVFoVhfTx8kbQBUoF9TUqSQpqD7////NDMzEwA "Bash – Try It Online")
```
chmod ${1:1} a>a;  # call chmod with the input with its first character removed
                   # note that the redirection creates the file a *before* the
                   #   chmod is run, because of the way bash works
stat -c%A a|       # get the human readable access rights
sed s/./${1:0:1}/  # replace the first character with the first char of input
|tr f -            # transliterate, replacing f with -
```
[Answer]
# [Python 2](https://docs.python.org/2/), 78 bytes
```
lambda a,*b:[a,'-'][a=='f']+''.join('-r'[x/4]+'-w-w'[x/2]+'-x'[x%2]for x in b)
```
Takes input as a character and three ints.
[Try it online!](https://tio.run/##VYvLCsIwEEX3fkU2Mo1OfMTWgpAviVkklGBLTUooNH59nG6kcjaHw73TZ37FIItn6llG@3adZRYP7qEtggCjrVLgwRwBTkPsQwUigc7nmopYxLK6XD2T7aXxMbHM@sAcL1Pqw8x8RX@8EzXf/VIH2BLNJo2AN2K7omND6fJ/vKLElpcv "Python 2 – Try It Online")
### Explanation
`[a,'-'][a=='f']` takes either the input character or `-`, if the character is `f`.
`'-r'[x/4]+'-w-w'[x/2]+'-x'[x%2]` is essentially an octal conversion to get the `rwx` string.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 19 bytes
```
“rwx“-”Œp⁺;Ṁ⁾f-yị@~
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw5yi8gogqfuoYe7RSQWPGndZP9zZ8KhxX5pu5cPd3Q51/x/u3nK4/VHTmsj//9PMzEy4UszNTblyjI1NuNJMjQ24UgyNzAE "Jelly – Try It Online")
### How it works
```
“rwx“-”Œp⁺;Ṁ⁾f-yị@~  Main link. Argument: s (string)
“rwx“-”              Set the return value to ["rwx, "-"].
       Œp            Take the Cartesian product, yielding ["r-", "w-", "x-"].
         ⁺           Take the Cartesian product, yielding
                     ["rwx", "rw-", "r-x", "r--", "-wx", "-w-", "--x", "---"].
          ;Ṁ         Append the maximum of s (the letter).
            ⁾f-y     Translate 'f' to '-'.
                  ~  Map bitwise NOT over s.
                     This maps the letter to 0, because it cannot be cast to int,
                     and each digit d to ~d = -(d+1).
                ị@   Retrieve the results from the array to the left at the indices
                     calculated to the right.
                     Indexing is modular and 1-based, so the letter from s is at
                     index 0, "---" at index -1, ..., and "rwx" at index -8.
```
[Answer]
## [Perl 5](https://www.perl.org/) with `-p`, 37 bytes
```
s/\d/(<{-,r}{-,w}{-,x}>)[$&]/ge;y;f;-
```
Takes input in lowercase.
[Try it online!](https://tio.run/##K0gtyjH9/79YPyZFX8OmWlenqBZIlIOIilo7zWgVtVj99FTrSus0a93//9PMzEy4UszNTblyjI1NuNJMjQ24UgyNzP/lF5Rk5ucV/9ctAAA "Perl 5 – Try It Online")
[Answer]
# [Retina 0.8.2](https://github.com/m-ender/retina/wiki/The-Language/a950ad7d925ec9316e3e2fb2cf5d49fd15d23e3d), 43 bytes
```
\d
$&r$&w$&x
f|[0-3]r|[0145]w|[0246]x
-
\d
```
[Try it online!](https://tio.run/##K0otycxL/P8/JoVLRa1IRa1cRa2CK60m2kDXOLYISBmamMaWA2kjE7PYCi5dLqC6///TzMxMuFLMzU25coyNTbjSTI0NuFIMjcwB "Retina 0.8.2 – Try It Online") Link includes test cases. Takes input in lower case. Explanation:
```
\d
$&r$&w$&x
```
Triplicate each digit, suffixing with `r`, `w` and `x`.
```
f|[0-3]r|[0145]w|[0246]x
-
```
Change all the incorrect letters to `-`s.
```
\d
```
Delete any remaining digits.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 51 bytes
```
f
-
0
---
1
--x
2
-w-
3
-wx
4
r--
5
r-x
6
rw-
7
rwx
```
[Try it online!](https://tio.run/##DctBCsAgDADB@/4loEbNewpWKJQepND83uYyh4Vd53s9R957IiREhBw6BfkEDZ3Kit5Cp7OiW@gx9V4ZZo1btTKbJkYu9gM "Retina – Try It Online")
No idea how to use Retina, so please let me know how to do this better. I just figured I'd try to learn at least one language that isn't Pyth.
### Explanation:
Replace `f` with `-` (leaving `d` and `l` unchanged), then replace each digit with the appropriate `rwx`.
[Answer]
# JavaScript (ES6), 63 bytes
Expects the input string in lowercase.
```
s=>s.replace(/\d|f/g,c=>1/c?s[c&4]+s[c&2]+s[c&1]:'-',s='-xw-r')
```
[Try it online!](https://tio.run/##y0osSyxOLsosKNHNy09J/Z9m@7/Y1q5Yryi1ICcxOVVDPyalJk0/XSfZ1s5QP9m@ODpZzSRWG0QZQSjDWCt1XXWdYlt13Ypy3SJ1zf/J@XnF@Tmpejn56RppGkppZmYmSpqaXGjCKebmpliEc4yNsalOMzU2wGaIoZE5UPg/AA "JavaScript (Node.js) – Try It Online")
### Commented
```
s => s.replace(   // replace in the input string s
  /\d|f/g, c =>   //   each character c which is either a digit or the letter 'f'
    1 / c ?       //   if c is a digit:
      s[c & 4] +  //     append '-' or 'r'
      s[c & 2] +  //     append '-' or 'w'
      s[c & 1]    //     append '-' or 'x'
    :             //   else:
      '-',        //     just replace 'f' with '-'
  s = '-xw-r'     //   s holds the permission characters
)                 // end of replace()
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 27 bytes
```
ＦＳ≡ιdιlιf¦-⭆rwx⎇§↨⁺⁸Ｉι²⊕λκ-
```
[Try it online!](https://tio.run/##bc@/CsIwEAbw3ac4Ml0gDgqi6KROHYSCvsCRpLYY03JJbUV89prin8nhlt8H38fpkljX5IahqBkw800bj5Erf0YpIXRV1CVgJeEx0RQsCCPWkKc8Jtx8zP2x4mdiKpIaW1Dr4hffGwdqUHDXCwUny574jtuYeWN73KUWzF0bcKVgT2Hslgrm6TKv2V6tj9agG/GiYByRaeaZHlkuZsP05l4 "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
 Ｓ                          Input string
Ｆ                           Loop over characters
   ι                        Current character
  ≡                         Switch
    d                       Literal `d`
     ι                      Implicitly print current character
      l                     Literal `l`
       ι                    Implicitly print current character
        f                   Literal `f`
         ¦                  (Separator between string literals)
          -                 Implicitly print literal `-`
                            Implicit default case
            rwx             Literal `rwx`
           ⭆                Map over characters
                     ι      Input character
                    Ｉ       Cast to integer
                   ⁸        Literal 8
                  ⁺         Sum
                      ²     Literal 2
                 ↨          Base conversion
                        λ   Inner index
                       ⊕    Incremented
                §           Index into base conversion
                         κ  Inner character
                          - Literal `-`
               ⎇            Ternary
                            Implicitly print
```
[Answer]
# [Haskell](https://www.haskell.org/), ~~84~~ ~~83~~ 81 bytes
```
f 'f'='-'
f y=y
t#n=f t:((\x->["-r"!!div x 4,"-w-w"!!div x 2,"-x"!!mod x 2])=<<n)
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P01BPU3dVl1XnStNodK2kqtEOc82TaHESkMjpkLXLlpJt0hJUTEls0yhQsFER0m3XLcczjcC8iuAvNz8FBAvVtPWxiZP839uYmaegq1CSj6XAgQUlJYElxT55KkAbVKONtMx0zGJxZRLAcqZ65jrmGKRywHKGesYY9UHMtMUKGeAw0xDHSMd89j/AA "Haskell – Try It Online")
Ended up being pretty similar in concept to Mnemonic's Python 2 answer. f creates the file type, the rest is the gets permissions from the octal number. This one really made me wish & was a bitwise and operator included in prelude.
[Answer]
# Java 8, 100 bytes
```
s->s.replaceAll("(\\d)","$1r$1w$1x").replaceAll("f|[0-3]r|[0145]w|[0246]x","-").replaceAll("\\d","")
```
[Try it online.](https://tio.run/##hU/JbsIwEL3zFSMrh1hqIky2AwKJD4ALR8jBdRLkYExkm02Qbw/T1pdWqiLNaLY38960/MqjtjoOQnFrYc2lfk4ApHa1abioYfNVAmydkfoAIvSJpXPs9@ho1nEnBWxAwwIGGy1tbOpO4fpKqZCE@31FyQcJmAnYLWB3Qn/Nm9duGiWlwcDSrLxhnKV5eceV6A8UL2GX0GH@w9xdPhUyewHXs6zghC94lbuSUy//YV19is8XF3c4cUqHOhZInecpod@//A@qiiIbBakkGb/UZMl0nI7NCg/qJ/3wBg)
Port of [*@Neil*'s Retina answer](https://codegolf.stackexchange.com/a/163713/52210).
**Explanation:**
```
s->                                 // Method with String as both parameter and return-type
  s.replaceAll("(\\d)","$1r$1w$1x") //  Replace every digit `d` with 'drdwdx'
   .replaceAll("f                   //  Replace every "f",
                |[0-3]r             //  every "0r", "1r", "2r", "3r",
                |[0145]w            //  every "0w", "1w", "4w", "5w",
                |[0246]x",          //  and every "0x", "2x", "4x", "6x"
               "-")                 //  with a "-"
   .replaceAll("\\d","")            //  Remove any remaining digits
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 21 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
Ḣ⁾f-yɓOBṫ€4a“rwx”o”-ṭ
```
A full program printing to STDOUT. (As a monadic link the return value is a list containing a character and a list of three lists of characters.)
**[Try it online!](https://tio.run/##y0rNyan8///hjkWPGvel6VaenOzv9HDn6kdNa0wSHzXMKSqveNQwNx@IdR/uXPv///8Uc3NTAA "Jelly – Try It Online")** Or see the [test-suite](https://tio.run/##y0rNyan8///hjkWPGvel6VaenOzv9HDn6kdNa0wSHzXMKSqveNQwNx@IdR/uXPv/4e4th9uBckf3OACZWUAWUI2Crp0CUEHk//9pZmYmXCnm5qZcOcbGJlxppsYGXCmGRuYA "Jelly – Try It Online").
### How?
```
Ḣ⁾f-yɓOBṫ€4a“rwx”o”-ṭ | Main Link: list of characters
Ḣ                     | head & pop (get the 1st character and modify the list)
 ⁾f-                  | list of characters = ['f', '-']
    y                 | translate (replacing 'f' with '-'; leaving 'd' and 'l' unaffected)
     ɓ                | (call that X) new dyadic chain: f(modified input; X)
      O               | ordinals ('0'->48, '1'->59, ..., '7'->55 -- notably 32+16+value)
       B              | convert to binary (vectorises) (getting three lists of six 1s and 0s)
        ṫ€4           | tail €ach from index 4 (getting the three least significant bits)
           “rwx”      | list of characters ['r', 'w', 'x']
          a           | logical AND (vectorises) (1s become 'r', 'w', or 'x'; 0s unaffected)
                 ”-   | character '-'
                o     | logical OR (vectorises) (replacing any 0s with '-'s)
                   ṭ  | tack (prepend the character X)
                      | implicit print (smashes everything together)
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg) `-p`, 37 bytes
```
s:g[\d]=[X~]('-'X <r w x>)[$/];s/f/-/
```
[Try it online!](https://tio.run/##K0gtyjH7/7/YKj06JiXWNjqiLlZDXVc9QsGmSKFcocJOM1pFP9a6WD9NX1f///80MzMTrhRzc1OuHGNjE640U2MDrhRDI/N/@QUlmfl5xf91CwA "Perl 6 – Try It Online")
Port of Dom Hastings' Perl 5 solution.
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), 38 bytes
Inspired by [a comment](https://codegolf.stackexchange.com/questions/163691/file-permissions#comment396365_163694) from [ASCII-only](https://codegolf.stackexchange.com/users/39244/ascii-only).
```
\d
---$&*
---____
r--
--__
w-
-_
x
f
-
```
[Try it online!](https://tio.run/##K0otycxLNPz/PyaFS1dXV0VNC0TFAwFXka4uF4jJVQ6k47kquNK4dP//TzMzM@FKMTc35coxNjbhSjM1NuBKMTQyBwA "Retina – Try It Online")
The idea is converting each digit to unary (the default unary digit in Retina is `_`) with three leading `-`, and then converting binary digits from the most to the least significant.
[Answer]
# [Python 3](https://docs.python.org/3/), 71 bytes
```
lambda s:("-"+s)[s[0]!="f"]+stat.filemode(int(s[1:],8))[1:]
import stat
```
[Try it online!](https://tio.run/##VYtBCsMgFAX3OUX6V0raktQmlkBOYl1YzKeCRoluenoTNwVXD@bNhF/6@o1lXN7ZKvfRqo0zgRt0kYooenlZAEF2Mal0R2NX5/VKzJZIFMMsry9KyzbGBb@ntmg57OVHAjhNT6C0@QPN@VgBy1ht4Mj6Ohke/AT5AA "Python 3 – Try It Online")
Python 3.3+ has a built-in for that, although due to the need for an import, and differences in expected input format, it is not very golf-friendly.
[Answer]
# [Tcl](http://tcl.tk/), 139 bytes
```
proc P s {join [lmap c [split $s ""] {expr {[regexp \\d $c]?"[expr $c&4?"r":"-"][expr $c&2?"w":"-"][expr $c&1?"x":"-"]":$c==f?"-":$c}}] ""}
```
[Try it online!](https://tio.run/##XY69CsIwFEb3PMXlEtwE@w@FklfonmaQtJVKtCGpWAh59nip4OD0Hc5yvk2blKxbNfTgIdzX5QnSPK4WNEhvzbIB94CoIEy7dRCkm25EMAwjcK0EysNzfSoFOmzxjOqncoHvP5UJ3L8KW667bhbERDEqysR0tOkJm@u6ZGPTVMwURcnmqriwMcsbFiHY1@bpVzuA7GlVTB8 "Tcl – Try It Online")
---
# [Tcl](http://tcl.tk/), 144 bytes
```
proc P s {join [lmap c [split $s ""] {expr {[regexp \\d $c]?[list [expr $c&4?"r":"-"][expr $c&2?"w":"-"][expr $c&1?"x":"-"]]:$c==f?"-":$c}}] ""}
```
[Try it online!](https://tio.run/##XY7NCsMgEAbvPsWySG@F5h8CwVfIXT0Uk5QU24haGhCf3UoKPfS0w3yHHa90SsZuCkZwEO7b@gSuH1cDCrgzevVAHSBKCPNuLARu51smEGICqiTjenUe@DFSdaoZWuzxjPKnSobvP1Uw3L9K9lQNw8IyZ4pR5l8xHQE5hyxtW5Op6xqiq6omS1NdyFSUHYkQzMu7HNcL4GO@MqYP "Tcl – Try It Online")
##
# [Tcl](http://tcl.tk/), 149 bytes
```
proc P s {join [lmap c [split $s ""] {if [regexp \\d $c] {list [expr $c&4?"r":"-"][expr $c&2?"w":"-"][expr $c&1?"x":"-"]} {expr {$c==f?"-":$c}}}] ""}
```
[Try it online!](https://tio.run/##Xc5LCsMgEIDhvacYRLorNG8IBK@QvXFRTCwpthG1NCCe3Q4pdNHVMB8M8wdlcrZuUzCCh3jf1icI87haUCC8NWsA5oFSCXHVINxyW3YL0zQDU2hm9QEEksP9VHPqaE/PVP6o5PT9RwWn@5cSxAMjU8OgOVLPVEpJ4sOUjwpsIrptazJ3XUNMVdVEN9WFzEXZEby3r@CxsJ9AjDhlyh8 "Tcl – Try It Online")
##
# [Tcl](http://tcl.tk/), 150 bytes
```
proc P s {join [lmap c [split $s ""] {if [regexp \\d $c] {set v [expr $c&4?"r":"-"][expr $c&2?"w":"-"][expr $c&1?"x":"-"]} {expr {$c==f?"-":$c}}}] ""}
```
[Try it online!](https://tio.run/##Xc5NCsIwEIbhfU4xhOBOsH8WCiVX6D7NQtJGKtGGJGoh5OxxqODC1cADw/cGZXK2blUwgId4W5cHCHO/WFAgvDVLAOaBUglx0SDcfJ03C@M4AVNofg7wAoHmEA41p4529Ejlj0pO339UcLp9KUHcMTLV95ojdUyllCQuprxnYBTR53NNprZtiKmqmuimOpGpKFuC//YZPCZ2I4gBr0z5Aw "Tcl – Try It Online")
##
# [Tcl](http://tcl.tk/), 180 bytes
```
proc P s {join [lmap c [split $s ""] {if [regexp \\d $c] {[set R regsub] (..)1 [$R (.)1(.) [$R 1(..) [$R -all 0 [format %03b $c] -] r\\1] \\1w\\2] \\1x} {expr {$c==f?"-":$c}}}] ""}
```
[Try it online!](https://tio.run/##HY9Bi8IwEIXv@RWPkoX1UGmsWhDEvyBekxxq2kiXuA1JRKHkt3dncxjm48G8eS8Zt64@zAZXRCw/8/QL6Z69h4GM3k0JPKKqNJbJQobxMX48lBrADWkyjgk3kBxfd43v7XYjIPmNaCNoCot/uVDdO4cG0s7h2Sd8Ne29@NQaQSmhyVi8ldoV@GQs9Cxg4eZ8tpeqrk7c5Jw15clrCUmRmT0e92zougNzbbtn9tA2bBC7jtG9f6VIBU4K8kpb5/UP "Tcl – Try It Online")
**Still very ungolfed!**
[Answer]
# [Java (JDK 10)](http://jdk.java.net/), 118 bytes
```
s->{var r=s[0]=='f'?"-":""+s[0];var z="-xw r".split("");for(int i=0;++i<4;)r+=z[s[i]&4]+z[s[i]&2]+z[s[i]&1];return r;}
```
[Try it online!](https://tio.run/##VU/BbsIwDL3zFVYkRrvSiEEBiRCmadJuO3GseshawsJKWjkuGyC@PWsBTdrB8rPfs/28UwcV74ovb/Z1hQS7tuYNmZLrxuZkKssfRS8vlXPwroyFcw@gbj5Kk4MjRW06VKaAfcsFa0Jjt2kGCrcuvEoB3u57lvmnwjQb3kQr0NK7eHU@KASULh1lUg704JnFbMFY1DVEx50ki3@@ARl3dWkoYCwUusLAWAIjRyKKzDIRIUbylLrUZA9JFt3R@A89ZQI31KAFFBcvrr66JTcvQBtHi3@mAdZHR5s9rxridSsiHbB@4iBeQd/1LRteh4aguarr8hh0Fafqtf3xBVEdgzAMb3cuvS4u3uvZLPHFfD715WSSeD2djHzxNJ7/Ag "Java (JDK 10) – Try It Online")
## Credits
* 13 bytes saved thanks to [Kevin Cruijssen](https://codegolf.stackexchange.com/users/52210/kevin-cruijssen)
[Answer]
# Excel, 224 bytes
```
=IF(LEFT(A1,1)="f","-",LEFT(A1,1))&CHOOSE(MID(A1,2,1)+1,"---","--x","-w-","-wx","r--","r-x","rw-","rwx")&CHOOSE(MID(A1,3,1)+1,"---","--x","-w-","-wx","r--","r-x","rw-","rwx")&CHOOSE(MID(A1,4,1)+1,"---","--x","-w-","-wx","r--","r-x","rw-","rwx")
```
Done in 4 stages:
```
IF(LEFT(A1,1)="f","-",LEFT(A1,1))    Replace "f" with "-".
```
And 3 times:
```
CHOOSE(MID(A1,2,1)+1,"---","--x","-w-","-wx","r--","r-x","rw-","rwx")
```
Trying to be smarter, adds `25 bytes` per set of rights, 75 in total:
```
IF(INT(MID(A1,2,1))>3,"r","-")&IF(MOD(MID(A1,2,1),4)>1,"w","-")&IF(ISODD(MID(A1,2,1)),"x","-")
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), ~~34~~ 27 bytes
```
ćls8βbvyi…rwx3*Nèë'-}J'f'-:
```
[Try it online!](https://tio.run/##MzBNTDJM/f//SHtOscW5TUlllZmPGpYVlVcYa/kdXnF4tbpurZd6mrqu1f//bmZmJgA "05AB1E – Try It Online")
Golfed down 7 bytes by [@MagicOctopusUrn](https://codegolf.stackexchange.com/users/59376/magic-octopus-urn)
---
```
ć                           # Remove head from string.
 ls                         # Lowercase swap.
   8βb                      # Octal convert to binary.
      vy                    # For each...
        i        ë  }
         …rwx3*Nè           # If true, push the correct index of rwx.
                  '-        # Else push '-'.
                     J      # Repeatedly join stack inside the loop.
                      'f'-: # Repeatedly replace 'f' with '-' inside the loop.
```
[Answer]
# [Python 2](https://docs.python.org/2/), 238 bytes
```
lambda m,r=str.replace,s=str.split,j="".join,b=bin,i=int,z=str.zfill,g=lambda h,y:y if int(h)else "-":r(m[0],"f","-")+j(j([g(z(s(b(i(x)),"b")[1],3)[0],"r"),g(z(s(b(i(x)),"b")[1],3)[1],"w"),g(z(s(b(i(x)),"b")[1],3)[2],"x")])for x in m[1:])
```
[Try it online!](https://tio.run/##fc7NCsIwEATgVwl72sW1@IMIhTxJLdJoY1PSNiQR2758jcWrXgYGPoZxU2yG/rBoIcVlsVWn7pXo2MsQfeZrZ6tbzWFtwVkTuZUAWTuYnpVUKY00feR5FbM21vJDfmcanvJJGC2SwIZqG2oBW8g9dsWuZNDAqdKmxRaLB84YUKHBkYhBARX7ko@0Sg/EP0FKeP0DhwRGoJL04MWY3oiu2OclLc5/nmn01etqeveMSETL/Xw@vQE "Python 2 – Try It Online")
I had assumed this would be a drop in the bucket, but I was wrong indeed. Probably should have realized that a lambda wasn't the best idea at some point.
[Answer]
# APL+WIN, 55 bytes
Prompts for input string with leading character lower case:
```
('dl-'['dlf'⍳↑t]),⎕av[46+(,⍉(3⍴2)⊤⍎¨⍕1↓t←⎕)×9⍴69 74 75]
```
Explanation:
```
9⍴69 74 75 create a vector of ascii character codes for rwx -46, index origin 1
1↓t←⎕ prompt for input and drop first character
,⍉(3⍴2)⊤⍎¨⍕ create a 9 element vector by concatenating the binary representation for each digit
46+(,⍉(3⍴2)⊤⍎¨⍕1↓t←⎕)×9⍴69 74 75 multiply the two vectors and add 46
⎕av[.....] convert back from ascii code to characters, 46 being '-'
('dl-'['dlf'⍳↑t]), append first character from input swapping '-' for 'f'
```
[Answer]
# [Python 3](https://docs.python.org/3/), 77 bytes
```
lambda a,*b,k='-xw-r':f'{a}-'[a=='f']+''.join(k[x&4]+k[x&2]+k[x&1]for x in b)
```
[Try it online!](https://tio.run/##XYvNCgIhFEb3PYWrrjbXaP4aCHySyYUySDaTDjKQET27GUFUnMUHh@/Mt@XkXZ0MEcc0qYseFFG40TgK4PHKAxwM3NWDQ6@EAAOyANievXV07OO6kcVrqveU0vhAIrGOaJbmYN1CDc0R7jMNY6uPGwC7TPvtJsA68/PLbZvd7q8tscKOsfQE "Python 3 – Try It Online")
[Answer]
# [J](http://jsoftware.com/),  57  52 bytes
5 bytes saved thanks to FrownyFrog!
```
-&.('-DLld'i.{.),[:,('-',:'rwx'){"0 1&.|:~1#:@}."."0
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/ddX0NNR1XXxyUtQz9ar1NHWirXSAAuo6VupF5RXqmtVKBgqGano1VnWGylYOtXpKekoG/zW5uFKTM/IV0hTU3czMTNThPBdzc1MEz8fYGEnOzdTYAEmloZG5@n8A "J – Try It Online")
Yet another long solution... I don't know how to make `}` work in tacit verbs and that's why I used the much longer `{"0 1&.|:` for selection.
## Explanation:
`@}.` Drop the first symbol and
`,.&.":` convert the rest to a list of desimal digits
`]:#:` convert each digit to a list of binary digits (and cap the fork)
`('-',:'rwx')` creates a 2-row table and use 0 to select from its first row / 1 - from its second one
```
   '-',:'rwx'
---
rwx
```
`{"0 1&.|:~` uses the binary digits to select from the table above
`[:,` flattens the result
`('d-l'{~'DFL'i.{.)` formats the first symbol
`,` appends the fisrt symbol to the list of permissions
[Answer]
# PHP, 68 bytes
```
<?=strtr(strtr($argn,[f=>_,___,__x,_w_,_wx,r__,r_x,rw_,rwx]),_,"-");
```
translates `f` in lowercase input to underscore and every octal number to its `rwx` equivalent, using underscores instead of dashes (to save the need for quotes), then replaces the `_` with `-`.
Run as pipe with `-nF` or [try it online](http://sandbox.onlinephpfunctions.com/code/fc954b2f180b55b9c250179105dec22bf2e4cbef).
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 109 104 bytes
At least C can convert octal input.... :-)
**Edit:** I realized that the size modifier wasn't strictly required, and that `putchar()` is shorter than `printf()` in this case!
```
f(a,b){char*s="-xwr";scanf("%c%o",&a,&b);putchar(a-70?a:*s);for(a=9;~--a;putchar(s[(1&b>>a)*(a%3+1)]));}
```
[Try it online!](https://tio.run/##PcrRCoIwFIDhe59iLJQdc1GESC3tpreILo7HloPawmkFYq@@6qbLn@8neSEKM2PpOjRntvN9Y9yirYIWmNUwUotd6ksuX8@OK09oteAxxY5nCWZJDeo@9L9JoCyWe9ymHpR23yw36i0l/t0fxSqpqwohFRiv5ys4AagpGNuzGxorHs40wMaIMS1ARVM4FHn@AQ "C (gcc) – Try It Online")
Original:
```
f(a,b){char*s="-xwr";scanf("%c%3o",&a,&b);putchar(a-70?a:*s);for(a=9;~--a;printf("%c",s[(1&b>>a)*(a%3+1)]));}
```
[Try it online!](https://tio.run/##HcvRCoIwFIDhe59iLJQd2yIRkVraTW8RXRxny0Ft4rQCsVc36/KH71fiptS8Mlbdh/pKDr6vjds05awZ8gpG1WAX@4KK96uj0iu0mtFQhamjPEIeVSDbof8phiLfHnEfe5DaLVns5EcIlG1nbP@/KPdnlkRVWSLEDMN0ncAFQE7zIsgDjWVPZ2ogY0CIZiCDaT7lWfYF "C (gcc) – Try It Online")
]


[Question]
      [
# 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.

[Answer]
# shell + sed + dc, 56 ~~61~~ bytes
```
sed '1i0
s/.//2g;y"idmhe"+-*/q";i1
/[*/]/i1+
/P/crdn'|dc
```
[Try it online!](https://tio.run/##Tce9DkAwFAbQ/T6FdGlC@NTqJexioC29iZ9QEhLvXgmL6eR0rXfBardEkmdN1cb017Vj/8aevH@bjnGXd/DWRFJxTh4ZUAzlJdhMzookjbGKkhWhjtGAVUKooDczy9voEB4 "Bash ‚Äì Try It Online")
Converts the program into a dc program, then evaluates it as dc code. This takes the input separated by newlines. Note that dc is stack-based and uses reverse polish notation, so `5 2-` gives `3`, and numbers are always rounded down.
The input is first piped to sed
`1i0` on the first line of input, insert (prepend) a 0, this will be the accumulator
`s/.//2g` remove everything but the first character on each line
`y"idmhe"+-*/q"` transliterate `idmhe` into `+-*/q` respectively, + - \* / are the arithmetic commands and q quits the program
`i1` on every line insert a `1` - this satisfies addition and subtraction
`/[*/]/` on every line containing \* or /, `i1+` additionally insert `1+` because of the preceding `1`, which dc will eventually evaluate into `2`
`/P/` on every line containing P, `crdn` change it into `rdn`, equivalent to reverse the top two elements, to rid the inserted `1`, and duplicate and output as a number without newline (whilst popping it, hence the earlier duplicate) in dc
Now this is evaluated as a dc expression.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 21 bytes
```
·∏≤·∏¢‚Ç¨O%11·ªã‚Åæ‚Äô‚Äòj‚ÄúI»Æ·∏§H‚Äù¬§VI
```
[Try it online!](https://tio.run/##y0rNyan8///hjk0Pdyx61LTGX9XQ8OHu7keN@x41zHzUMCPrUcMczxPrHu5Y4vGoYe6hJWGe////z8xLVgDhgKJMhZTUZDAGsWFiIDq3NKcEQgBFAA "Jelly ‚Äì Try It Online")
---
Note that the ASCII values of the first characters (`idmhPe`) modulo 11 are unique modulo 6.
---
Using modulo 16:
# [Jelly](https://github.com/DennisMitchell/jelly), 21 bytes
```
·∏≤·∏¢‚Ç¨O%‚Å¥·ªã‚Äú·∏¢wƒ°·∏ûkz‚Äô·πÉ√òJ¬§VI
```
[Try it online!](https://tio.run/##y0rNyan8///hjk0Pdyx61LTGX/VR45aHu7sfNcwBCpQfWfhwx7zsqkcNMx/ubD48w@vQkjDP////Z@YlK4BwQFGmQkpqMhiD2DAxEJ1bmlMCIYAiAA "Jelly ‚Äì Try It Online")
The string that is used to index into is `·∏§H‚Äò‚ÄôI»Æ` in this case. The `‚Äò‚Äô` are no longer on the boundaries.
[Answer]
# [R](https://www.r-project.org/), ~~128~~ 125 bytes
```
Reduce(function(x,y)switch(y,i=x+1,d=x-1,m=x*2,h=x/2,P={cat(x);x}),substr(el(strsplit(gsub("e.*$","",scan(,""))," ")),1,1),0)
```
[Try it online!](https://tio.run/##XYhLDsIgFACvQoiLR31@6NZwh8YbUErlJZQaPpHGeHasWzczk4nN0xh13GCx2a1TEu1up2IszCWYTGuAiptIL8rGwYak6lHipOpJ4qJq16NT9dLjoN5GZ6jiVj8CUxlTjmA97EpPTxke@wNuz92BI@eYjA6whxDI2Y8SpcCraJyCYUMk9m9bKTOn/cyW4jNvXw "R ‚Äì Try It Online")
Must be called with `source(echo=FALSE)` to prevent the return value from being printed automatically. The alternative would be to [wrap everything in `invisible`](https://tio.run/##XYhLDsIgFACvQoiL9@rz024Nd2i8AaVUXkLRAFUa49mxbt3MTCZWz0PUcYXZZncfE1YOT048eAtXOy7GwrQEk/keoNCK6cXZOFiJVdm3NKpyaGlWpenIqXLqqFdvozMUvJQPUlqGlCNYD5vSw3OG2/ZA2mOzkyQlJaMDbIFIUvzYUot0RqySgxF9ZPFvWzgLp/0k5sVnWb8) but that's much less golfy (and ruins my [still] nice byte count).
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 25 bytes
```
√é‚Ç¨¬¨"idmhPe"S"><¬∑;=q"S‚Ä°J.V
```
[Try it online!](https://tio.run/##MzBNTDJM/f//cN@jpjWH1ihlpuRmBKQqBSvZ2Rzabm1bqBT8qGGhl17Y///R6pl5yeo6CuoBRZkgCh8vtSKzBERnJOakgejc0pwS9VgA "05AB1E ‚Äì Try It Online")
Maps each of the language function with the corresponding 05AB1E function (using the first char of each function), and then executes the resulting string as 05AB1E code.
[Answer]
# [Python 3](https://docs.python.org/3/), ~~110~~ ~~91~~ 82 bytes
`exit` will cause the program to exit with an error.
```
x=0
for c in input():c=='P'==print(x,end='');x+=(1,-1,x,-x/2,c,0)['ndmhx'.find(c)]
```
[**Try it online!**](https://tio.run/##XcXBCsIwDADQu1@RW1rMdNObI/@wu3iQdmWBLSulg/j11bPw4OVPXXa9t2bcn9JeIIDoTz6q84/AjBMy5yJandGskRH9aGd2A3UDGXV2vVGg3j9R47YYXpJodMG/WhMNMBWB/2eTCst7TbAda/0C "Python 3 ‚Äì Try It Online")
[Answer]
# [Red](http://www.red-lang.org), 121 bytes
```
func[s][v: 0 parse s[any[["i"(v: v + 1)|"d"(v: v - 1)|"m"(v: v * 2)|"h"(v: v / 2.0)|"P"(prin v)|"e"(exit)]thru" "| end]]]
```
[Try it online!](https://tio.run/##ZYxBCoMwEEX3nuIzK21pa116itJtyEJMggENEqO04N3TRFTaugiTN/P@t1L4pxSMJ6r0ajQ1GzibSuToKztIDKwyb8ZIUxq2E864ZzOJlS4LdSudUARqVrqhuOaBH5T2VhtM4S8plS/tMu4aOxJohjSCc@4VSJsa2xOyxsNqRJmSGHcgSoIVL9HoxtbtelB/re@uxWyqVu2NcX304/V/LvaSjS3HzFZL/gM "Red ‚Äì Try It Online")
## Readable:
```
f: func [s] [
    v: 0
    parse s [
        any [
            [ "i" (v: v + 1)
            | "d" (v: v - 1)
            | "m" (v: v * 2)
            | "h" (v: v / 2.0)
            | "P" (prin v)
            | "e" (exit)]
            thru [" " | end]
        ]
    ]
]
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~131~~ ~~125~~ ~~122~~ ~~121~~ ~~118~~ ~~117~~ 115 bytes
```
v=0;o=""
for x in input().split("x")[0].split():
 if"Q">x:o+=`v`
 else:v+=(1,-1,v,-v/2.)['idmh'.find(x[0])]
print o
```
[Try it online!](https://tio.run/##LcyxDoMgFEDRna94eYsQ0aqjDf2GdjYmNlXCSygQpYR@PXVocpez3PCNxruhlKS6q1eITPsdMpA7C5/IRXsES5FjRjF1819iZEAaH3jLo6/VkhYGmz22MdWK97LpZZJNugytmCpa36ZqNbmV5/MgZhZ2chF8KUjuBeZpNdx3wh8 "Python 2 ‚Äì Try It Online")
-6 and -3 with thanks to @Rod
-3 and -2 with thanks to @etene
-1 by replacing `"Pri"==x` with `"P"in x`
[Answer]
# JavaScript (ES6), ~~83~~ 79 bytes
*Saved 4 bytes thanks to @l4m2*
Iteratively replaces the instructions with either the output or empty strings.
```
s=>s.replace(/\S+./g,w=>m<s?'':w<{}?m:(m+={d:-1,e:w,i:1,m}[w[0]]||-m/2,''),m=0)
```
[Try it online!](https://tio.run/##jc/dCoIwFAfw@55i7Eal6dToZrh6haDL6kLmrMWm4SyD8tmtGX2ZRQfG4LDf/5xt40OsWSF2pZvlCW9S2mg60V7BdzJm3MbL@dDDa1TRiYr01LJIFZ3qqSK2GtJTQtwAcVIhQQKk6kW18Fer89lVOESW5SBFfadheaZzyT2Zr@3UhiJj4H4SzsCsEIAfRQnBWzkOwBiEg442wki1l@Uj5hrxn36d3SZsYpk@NjBt@NSjPm3edu/WtkkmE950EH74Lz/t1s37fdPf1oW/tDduLg "JavaScript (Node.js) ‚Äì Try It Online")
### Commented
```
s =>                       // given the input string s
  s.replace(/\S+./g, w =>  // for each word w in s:
    m < s ?                //   if m is a string:
      ''                   //     ignore this instruction
    :                      //   else:
      w < {} ?             //     if w is 'Pri' ({} is coerced to '[object Object]'):
        m                  //       output the current value of m
      : (                  //     else:
          m +=             //       add to m:
            { d: -1,       //         -1 if w is 'dec'
              e: w,        //         w  if w is 'exit' (which turns m into a string)
              i: 1,        //         1  if w is 'inc'
              m            //         m  if w is 'mult'
            }[w[0]]        //       using the first character of w to decide
            || -m / 2,     //       or add -m/2 (for 'half') if the above result was falsy
        ''),               //       do not output anything
    m = 0                  //   m = unique register of our mighty CPU, initialized to 0
  )                        // end of replace()
```
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~37~~ 35 bytes
```
‚âî‚Å∞Œ∑Ôº¶‚éá‚ÑñŒ∏x‚Ä¶Œ∏‚åïŒ∏xŒ∏‚â°Œπn‚â¶‚äïŒ∑d‚â¶‚äñŒ∑m‚â¶‚äóŒ∑h‚â¶‚äòŒ∑rÔº©Œ∑
```
[Try it online!](https://tio.run/##bY@xCsIwEIb3PsXRKYEKzjpJRXQoOPgCZxJNIE1sktaK@OwxpTpEnI77/o87fibRMYs6xo336mrIsgJJ18XFOiAn4Qy6B6ltbwLpKijHklbQWM2nbacM/9KEO0rB31VgEoii8CwYegGlKVfQ4O1z/mCYE60wQfD50SzxTNqKv1KbS7Y/61yQmbBHPeS5S/nRqdSlRh@IpCl5xagMmzD8TjGqABL1BdpehyIuBv0G "Charcoal ‚Äì Try It Online") Link is to verbose version of code. Inspired by @RickHitchcock's answer. Explanation:
```
‚âî‚Å∞Œ∑
```
Clear the variable.
```
Ôº¶‚éá‚ÑñŒ∏x‚Ä¶Œ∏‚åïŒ∏xŒ∏‚â°Œπ
```
Truncate the input at the `x` if there is one, then loop over and switch on each character of (the remainder of) the input.
```
n‚â¶‚äïŒ∑
```
`n` i**n**crements the variable.
```
d‚â¶‚äñŒ∑
```
`d` **d**ecrements the variable.
```
m‚â¶‚äóŒ∑
```
`m` **m**ultiplies the variable by two (i.e. doubles).
```
h‚â¶‚äòŒ∑
```
`h` **h**alves the variable.
```
rÔº©Œ∑
```
`r` p**r**ints the variable cast to string.
[Answer]
# JavaScript (ES6), ~~77~~ 75 bytes
(Borrowed (*stole*) @Arnauld's trick of using `m` as the variable name, saving 2 bytes.)
```
f=([c,...s],m=0)=>c<'x'?(c=='P'?m:'')+f(s,m+({h:-m/2,d:-1,n:1,m}[c]||0)):''
```
Recursively walks the string, looking for distinct letters per instruction and ignoring the rest:
* n: inc
* d: dec
* m: mult
* h: half
* P: Pri
* x: exit
Takes advantage of the fact that `undefined` is neither greater than nor less than `'x'`, causing the recursion to stop at the end of the string *or* when it encounters the `'x'` in **exit**.
```
f=([c,...s],n=0)=>c<'x'?(c=='P'?n:'')+f(s,n+({h:-n/2,d:-1,n:1,m}[c]||0)):''
console.log(f('inc inc inc dec Pri exit'));                 //--> 2
console.log(f('dec inc mult inc inc Pri'));                 //--> 2
console.log(f('inc inc inc mult half Pri exit inc'));       //--> 3
console.log(f('inc Pri inc Pri inc Pri exit half mult'));   //--> 123
console.log(f('Pri exit'));                                 //--> 0
console.log(f('inc half Pri exit'));                        //--> 0.5
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 107 bytes
```
f=s=>s.split` `.map(([o])=>F?0:o=="i"?i++:o=="d"?i--:o=="m"?i*=2:o=="h"?i/=2:o=="P"?S+=i:F=1,F=i=0,S="")&&S
```
[Try it online!](https://tio.run/##bY/BioMwFADv@xUhBzFrtK32UFxevXkueBShQWP7lmiksWX/3k1CtyzSQ8gQZl6Sb/EQpr3hNMej7uSy9GDgaBIzKZzP5JwMYgrDWjcMjmWxzTUARVpgFHnsLMaxx8HiJ6Ser5Y3Tz7RoooA8xJ2vASELa@AUhYE1dLq0WglE6UvYR9SHFvytzrZktMNifzBmTKAlH2sbGc4c7ir@ZXZhDLyTv8/3CdXofrXFe7Yhxn7elc6b737zk9x89wjd2nGVp@q9w2vDw0/cJJZoxfKSPYL "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 91 bytes
```
_=>_.split` `.map(o=>o<{}>!_?S+=+i:o<"e"?i--:o<"f"?++_:o<"i"?i/=2:o<"j"?i++:i*=2,i=S="")&&S
```
[Try it online!](https://tio.run/##bYxBCoMwEEX3PUWahWhTLbi0jl6h4AE0xNiORCNqS6H07DYRKiIuhvnMvPdr/uKD6LEb/VaXcqpgyiHJg6FTOBakCBreuRoSHX@@yTFPMwYMIx1TSVP0fZsqmjKW24TmdoHQxtpExiI8QXhGyIBSz3GySeh20EoGSt/dyqXYCvKfUgpy65HIN47U8w4b1L4t1jzVuDiG30HXrTP@4Kpaulfidc@03HbP3txi@4w5/QA "JavaScript (Node.js) ‚Äì Try It Online")
# [JavaScript (Node.js)](https://nodejs.org), 96 bytes
```
_=>_.split` `.map(o=>F?0:o<"Q"?S+=i:o<"e"?i--:o<"f"?F=1:o<"i"?i/=2:o<"j"?i++:i*=2,F=i=0,S="")&&S
```
[Try it online!](https://tio.run/##bYzLDoJADEX3fgWZBQF5iCzRwo61hg8AAjNaMjAE0Pj3OCWRGMKi6U17zm3KdzlWA/aT16mazwLmHOLcH3uJU2EUflv2loI4TYJIXdmdJZkDSJGzBD2PkmBJCmdKqG8nCCk2OjpOhEcI3RQQAjcDxmzTzOZKdaOS3JfqYQmLYVcZv6l5ZdwGNPgHJ2bbhw1Kb8Lal5xWR/M76H/rgj9LKdZuOmvpsmcRs92LszRQlzbnLw "JavaScript (Node.js) ‚Äì Try It Online")
# [JavaScript (Node.js)](https://nodejs.org), 99 bytes
```
s=>s.split` `.map(_=>eval('++i7--i7++e7u+=+i7i*=27i/=2'.split(7)[Buffer(e+_)[0]%11%6]),e=i=u='')&&u
```
[Try it online!](https://tio.run/##XY09D4IwFAB3f0UXbWv5EAc7PQYHZndDsMJDn6lAaGv679HExThdbrjcw7yMa2eafDqMHS553uE13CBCKdpxcKPFzI43EWUS5aqCxUHpMjdZ8hd2yZ5mEg2U@DJWcKVIpylppVAHBR@jLew15bDn30RoeT6GvsdZoGrkeVevi2J9qGWCQBCAc7nZhOV3XAlOQ8tOM7F/YiTP7sb27Bms51Kuljc "JavaScript (Node.js) ‚Äì Try It Online")
[Answer]
# JavaScript, 107 bytes
```
s=>eval('x=0;x'+(s.split` `.map(v=>({i:"++",d:"--",m:"*=2",h:"/=2",P:";alert(x)",e:"//"})[v[0]]).join`;x`))
```
[Answer]
# [Haskell](https://www.haskell.org/), 93 bytes
```
(0!)
a!(c:t)|c=='P'=show a++a!t|c>'w'=""|1<2=(a+sum(lookup c$zip"ndmh"[1,-1,a,-a/2]))!t;a!e=e
```
[Try it online!](https://tio.run/##Xc0xDoIwFADQ3VP8NiZtA0RhVL9nYFeHnwrS0JaGlpAYzm51dnrjGyiOnbW5x3uWR6Z2xKQ@JbVpRNEKjMO0AhUFsbTpq1gFcr7VlwYlFXFx0k7TuATQ@7cJ3D/dwG91WdUllRUdmodSLJ2JddhlR8YDQpiNT/CruPEa2tnAn1zlj@4tvWKudAhf "Haskell ‚Äì Try It Online")
Essentially a translation of [mbomb007's Python answer](https://codegolf.stackexchange.com/a/163596/3852).
[Answer]
# Lua, 207 bytes
```
s=0;n=0;for a in io.read():gmatch'.'do if s==0 then s=1;n=a=='i'and n+1 or a=='d'and n-1 or a=='m'and n*2 or a=='h'and n/2 or n;if a=='P'then print(n)elseif a=="e"then break end elseif a==' 'then s=0 end end
```
[Answer]
# [Python 3](https://docs.python.org/3/), 114 110 109 116 bytes
Actually would have taken two bytes less in Python 2 because `exec` is a statement and doesn't need parentheses...
* *Saved 4 extra bytes thanks to @ElPedro*
* *Saved an extra byte by taking advantage of the fact that `find` returns -1 on error, which can then be used as an index*
* *+7 bytes because I hadn't noticed the no-newlines rule :(*
```
i=0;exec(";".join("i+=1 i-=1 i*=2 i/=2 print(i,end='') exit()".split()["idmhP".find(h[0])]for h in input().split()))
```
[Try it online!](https://tio.run/##XY29DsMgEINf5XRLoD80bceId8geZagCiKvIBREipU@fwtClkvXZg2XHT/YLP4@DdNvZ3U4CO1TvhVggnfUd6Fpx0g@gW0FMxFnQxbLRTSPB7pSFRLXGUMOAZGbfo3LERvihHeXolgQeiIviVjq/rpTllSfoE8G/11nwr@Bg3kL@Ag "Python 3 ‚Äì Try It Online")
Maps the first character of every input word to a piece of Python code. These are then concatenated and `exec`ed.
Pretty straightforward approach, that could probably be golfed a bit more. The difficulty mostly resides in finding the shortest form out of many possible ones...
[Answer]
# [Ruby](https://www.ruby-lang.org/) + `-na`, ~~81~~ ~~73~~ 65 bytes
```
x=0;$F.map{|w|eval %w{x+=1 x-=1 1/0 $><<x x*=2 x/=2}[w.ord%11%6]}
```
[Try it online!](https://tio.run/##KypNqvz/v8LWwFrFTS83saC6prwmtSwxR0G1vLpC29ZQoUIXSBjqGyio2NnYVChUaNkaKVTo2xrVRpfr5RelqBoaqprF1v7/n5mXrJBbmlOClcAliSoO51HIICQcUJT5L7@gJDM/r/i/bl4iAA "Ruby ‚Äì Try It Online")
Pretty straightforward. For the first letter of each word, find the corresponding command string and `eval` it. Uses integer division, and `exits` by throwing a `ZeroDivisionError`.
-5 bytes: Use `.ord%11%6` instead of a string lookup. Credit goes to [user202729](https://codegolf.stackexchange.com/a/163573/77973)
-3 bytes: `.ord` only considers the first character of the string, so I can skip a `[0]`.
-8 bytes: Use `-a` flag to automatically split input, thanks to [Kirill L.](https://codegolf.stackexchange.com/users/78274/kirill-l)
[Answer]
# [Emojicode](http://www.emojicode.org/), 270 bytes
```
üêñüî•üçáüçÆc 0üîÇjüç°üí£üêïüîü üçáüçäüòõjüî§incüî§üçáüçÆc‚ûïc 1üçâüçãüòõjüî§decüî§üçáüçÆc‚ûñc 1üçâüçãüòõjüî§multüî§üçáüçÆc‚úñÔ∏èc 2üçâüçãüòõjüî§halfüî§üçáüçÆc‚ûóc 2üçâüçãüòõjüî§Priüî§üçáüëÑüî°c 10üçâüçìüçáüçéüçâüçâüçâ
```
[Try it online!](https://tio.run/##jZBfDsFAEMbfnWKOgJO4gmwrVtBESDwiEkGoP201ITaCV8/O4wL2Bsxs19JqxcN0d7q/b2a@sRtOjTPHsh9SLKZSeAcpZiNKAkzOlGBcGOQxHdTwjsDqiO8@/hCggYkU4RZfvRNvMjqM8Lb3GRTwOsaYGsyyk1iQhjU69Xac2wX3q8ug@IVWy/VKouQmjSu1@BtbDskyds5rbq3lc52reNAnJ4Xbp9ccRJtRXuEVaAiwNNhdriZGPOxFjTAxEsIIJ2NGq0fKkHx2UTJyanqBXvgPMaHJU0lVodeKMwr84YlqxmbSLC7uCQ "Emojicode ‚Äì Try It Online")
```
üêãüî°üçá
üêñüî•üçá
üçÆc 0
üîÇjüç°üí£üêïüîü üçá
üçäüòõjüî§incüî§üçáüçÆc‚ûïc 1üçâ
üçãüòõjüî§decüî§üçáüçÆc‚ûñc 1üçâ
üçãüòõjüî§multüî§üçáüçÆc‚úñÔ∏èc 2üçâ
üçãüòõjüî§halfüî§üçáüçÆc‚ûóc 2üçâ
üçãüòõjüî§Priüî§üçáüëÑüî°c 10üçâ
üçìüçáüçéüçâüçâüçâüçâ
üèÅüçá
 üî•üî§inc inc inc dec Pri exitüî§
üòÄüî§üî§
 üî•üî§dec inc mult inc inc Priüî§
üòÄüî§üî§
 üî•üî§inc inc inc mult half Pri exit incüî§
üòÄüî§üî§
 üî•üî§inc Pri inc Pri inc Pri exit half multüî§
üòÄüî§üî§
 üî•üî§Pri exitüî§
üòÄüî§üî§
 üî•üî§inc half Pri exitüî§
üçâ
```
[Answer]
# [SNOBOL4 (CSNOBOL4)](http://www.snobol4.org/csnobol4/), 165 bytes
```
	P =INPUT ' exit '
	x =0
S	P LEN(1) $ L ARB ' ' REM . P	:S($L)F(end)
i	X =X + 1	:(S)
d	X =X - 1	:(S)
P	O =O X		:(S)
m	X =X * 2	:(S)
h	X =X / 2.	:(S)
e	OUTPUT =O
END
```
[Try it online!](https://tio.run/##Nc5NC4JAFIXh9Z1fcRaCM0WW4kqYRZFBYM7gB7itNBwwhWrhv5@ModXlue/mvMfpNg2xtaQhz7muK/joZvNZDqMZcsfKJWVpzkMBDxn2xWFpPor0ggCakpJ7mTjxbmwFM9RANlgjpISXgrXOm781KUiFhhyfLq8QOffOW0SBe3Sk6uo3SiqW5kdrzXhHfx0e0C/zBQ "SNOBOL4 (CSNOBOL4) ‚Äì Try It Online")
Gross.
```
	P =INPUT ' exit ' 				;* append ' exit ' to the input to guarantee that the program will stop
	x =0						;* initialize x to 0 else it won't print properly if the program is 'Pri'
S	P LEN(1) $ L ARB ' ' REM . P	:S($L)F(end)	;* set L to the first letter of the word and goto the appropriate label
i	X =X + 1	:(S)
d	X =X - 1	:(S)
P	O =O X		:(S)				;* append X to the output string
m	X =X * 2	:(S)
h	X =X / 2.	:(S)				;* divide by 2. to ensure floating point
e	OUTPUT =O					;* print whatever's in O, which starts off as ''
END
```
[Answer]
# C# (.NET Core), 186 Bytes
```
class P{static void Main(string[]a){int v=0;foreach(var s in a){var i=s[0];if(i=='i')v++;if(i=='d')v--;if(i=='m')v*=2;if(i=='h')v/=2;if(i=='P')System.Console.Write(v);if(i=='e')break;}}}
```
[Answer]
# [Perl 5](https://www.perl.org/) `-a`, 61 bytes
```
eval'$,'.qw(++ -- ;exit ;print$,||0 *=2 /=2)[(ord)%11%6]for@F
```
[Try it online!](https://tio.run/##K0gtyjH9/z@1LDFHXUVHXa@wXENbW0FXV8E6tSKzRMG6oCgzr0RFp6bGQEHL1khB39ZIM1ojvyhFU9XQUNUsNi2/yMHt///MvGSFjMScNIWAokwFkMZ/@QUlmfl5xf91fU31DAwN/usmAgA "Perl 5 ‚Äì Try It Online")
Stole @user202729's `ord%11%6` trick
## How?
```
-a            # split the input by whitespace, store in @F
eval          # Execute the string that results from:
'$,'          # $, (the accumulator)
.             # appending:
qw(           # create an array for the following whitespace separated values:
++ --            # operators for inc & dec
;exit            # exit
;print$,||0      # Pri  (||0 ensures that 0 is output if accumulator is null
*=2 /=2)         # mult div
[(ord)%11%6] # @user202729's trick selects one of the preceding operations
for@F        # for every term input
```
[Answer]
# Pyth, 44 Bytes
```
Vmx"idmhPe"hdcwd=Z@[hZtZyZcZ2ZZ)NIqN4pZIqN6B
```
[Test Suite](https://pyth.herokuapp.com/?code=Vmx%22idmhPe%22hdcwd%3DZ%40%5BhZtZyZcZ2ZZ%29NIqN4pZIqN6B&input=inc+inc+inc+mult+half+Pri+exit+inc&test_suite=1&test_suite_input=inc+inc+inc+dec+Pri+exit%0Adec+inc+mult+inc+inc+Pri%0Ainc+inc+inc+mult+half+Pri+exit+inc%0Ainc+Pri+inc+Pri+inc+Pri+exit+half+mult%0APri+exit%0Ainc+half+Pri+exit&debug=0)
## explanation
```
Vmx"idmhPe"hdcwd=Z@[hZtZyZcZ2ZZ)NIqN4pZIqN6B   ## full program
             cwd                               ## split input on space
Vmx"idmhPe"hd                                  ## iterate through list of numbers corresponding to operators
                =Z@[hZtZyZcZ2ZZ)N              ## assign the variable Z (initialliy Zero) it's new value
                                 IqN4pZ        ## print Z if the current operator is "Pri" (4)
                                       IqN6B   ## break if the current operator is "exit" (5)
```
[Answer]
# TI-BASIC, 112 bytes
This takes advantage of some assumptions that are AFAIK perfectly acceptable. Number one being that all variables are initialized to zero prior to execution; number two being that input is taken via `Ans`.
```
Ans+" E‚ÜíStr1
While 1
I+4‚ÜíI
sub(Str1,I-3,1‚ÜíStr2
A+(Ans="I")-(Ans="D
If inString("MH",Str2
Then
I+1‚ÜíI
2AAns+A/2(1-Ans
End
If Str2="P
Disp A
If Str2="E
Stop
Ans‚ÜíA
End
```
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), 164 bytes
```
a->{int c=0;for(String g:a.split(" ")){char b=g.charAt(0);if(b==105)c++;if(b==100)c--;if(b==109)c*=2;if(b==104)c/=2;if(b==80)System.out.print(c);if(b==101)return;}}
```
[Try it online!](https://tio.run/##lVHdSsMwFL7vUxx6lThaO1FQSwUfQCrsUrxI07TLbNOSngyl7NlrUmemA6FehOQ7nO@P7NieRV0v1K58m3jDhgGemFRjACAVCl0xLiAf950sQZMNaqlqYDQ92IUBGUoOOeQGe4OQwcSih9HygGdJWnWeUN@zeOgbiSSEkNKRb5mGIqtj93hEktBUVqTIsnVyQ/lq5VFCeRR5dEf5RXbl4TXllx7eJnTzMaBo485g3FtbJPwku6ZaoNEqPRym1GbvTdHY7McKc73W9j4GfnlldAy@asWahFJx@D6l4PCsJYh3iSFNg3PXRhE7PXHdvuO1pkEvYgWWcH/6zvwtayrv7sZLVRzn/J41ZkWnvUTpP72dy6@4f5MC@ymf "Java (OpenJDK 8) ‚Äì Try It Online")
Above is my solution that rounds off to integers, but below is my solution that handles decimals. The obnoxious way that java prints doubles adds another 55 byes to the score. I left the new lines to make the code more readable in the second submission only because it‚Äôs essentially the same solution with one extra command and an import statement.
# [Java (OpenJDK 8)](http://openjdk.java.net/), 219 bytes
```
a->{
double c=0;
for(String g:a.split(" ")){
char b=g.charAt(0);
if(b==105)c++;
if(b==100)c--;
if(b==109)c*=2;
if(b==104)c/=2;
if(b==80)System.out.print(new DecimalFormat("0.#").format(c));
if(b==101)return;}}
```
[Try it online!](https://tio.run/##lVHRSsMwFH3PV1zqS7LR2ImCWioI4ptM2KP4kKXplpmmJb2dk7Jvr2k31zkQ5kNIzuWec@65WYm1CItS2VX60eq8LBzCytc4qg3yUUykEVUFL0LbhgBoi8plQiqYNutCp@DoDJ22CxAs3vqGCgVqCVOY1ljWCAm0InxoSFrUc6NAJlFMsuLAWtwLXpVGIw0gYKwhcikczJMF7x6PSCMWE53ReZJMohsmx@MBRkyG4QDvmBwlVwO@ZvJywLcRm31VqHJe1MhLb47Uqk94UlLnwjwXLhd@iIhfBIxnOyTZkfmEOYW1s/F228Y@aOnz@KD7vP0ucr@kfbC3d@HD7HbAHQ20lfBzUiXh1WlQG42Bdzidy1jqqwO36@94eW3wIOIFzuEe@/b8pTDZwb0rn6vScU7vXqNX7LTPUfpP7s7l17h/k4j/lG8 "Java (OpenJDK 8) ‚Äì Try It Online")
[Answer]
# [C (gcc)](https://gcc.gnu.org/), ~~120~~ ~~114~~ 111 bytes
-6 bytes thanks to ceilingcat.
```
x,d;f(char*s){for(x=0;s>1;s=index(d^1?s:"",32)+1)d=*s-100,x+=d?d==5:-1,x*=d^9?d^4?1:.5:2,d+20||printf("%d",x);}
```
[Try it online!](https://tio.run/##XY9disMgFIWf6ypEKGiiQ8y0DxOx2cKsIBC8SSq0aYlpEdquPROFhE4f5Mo537k/RnTGTJPnoFpqjvWQOPZoLwP1OlPuIJXTtofGU6hk6QpC@HfOUslAJ07ILOM@1VCC1vtCSO4TDdVPCdWulMXXvsg5pHn2fF4H248tJVsg3DP1mu4XC7iLA/E8ET3QZmXETjoshDhgwrFjCm1aGsv1NjpKyPx9ITTD@FzbnsZwR4ntDV4eNAb/DhY33o6BD37Qgne@ncYVnKHFf89H5lif2rVLkN/JoH/WyMVUyC/05x6B/tc6HjT9AQ "C (gcc) ‚Äì Try It Online")
# 124 bytes
Floating-point version:
```
d;f(char*s){for(float f=0;s>1;s=strchr(s,32)+1)d=*s-80,f+=d==25,f-=d==20,f*=d^29?d^24?1:.5:2,s=d^21?s:"",d?:printf("%f",f);}
```
[Try it online!](https://tio.run/##XY9hisMgEIV/11OIsGBSXZq0hd0EmyvsCRaCdhIhTYpjl4XSs2dVSOj2h87w3vfGUctO63k2NXDdty7H7A6T4zBMraegdjWeihoVeqd7x1Hsy2xbZEblKD92ArbKKFUeBcjUBCVX5rv8bMJ1aIrq/ViVAqNUNFgxJkxTXZ0dPXD2BkxAVj/mn8ka2qX3aViA3MlmZeShQCqlPFEmKGY12QBP5XrzyBkL7YOQANNLa0eewh1ndtR0Oeas6Zez9PxrfeSjH7XoXW6DX8EALf5zPjF9O8A6JcrPZNRfa@JSKuYX@nWPSP8bnT40/wE "C (gcc) ‚Äì Try It Online")
I did not bother with a version that rounds down, but makes an exception for 0, which would be allowed, if I understand the comment-chain correctly.
[Answer]
# [33](https://github.com/TheOnlyMrCat/33), 62 bytes
```
s'i'{1a}'d'{1m}'m'{2x}'h'{2d}'P'{o}'e'{@}It[mzsjk""ltqztItn1a]
```
[Try it online!](https://tio.run/##Mzb@/79YPVO92jCxVj0FSOXWqueqVxtV1KpnAKmUWvUA9er8WvVU9WqHWs@S6Nyq4qxsJaWcksKqEs@SPMPE2P//AQ "33 ‚Äì Try It Online")
This program takes the instructions delimited by newlines
## Explanation:
```
It[mzsjk""ltqztItn1a]
  [mz            n1a] | Forever
It    jk       It     | - Get the first character of the next instruction
            qz        | - Call the function declared previously
     s  ""lt  t       | - Make sure we don't lose track of the variable
```
The code before that segment defines all the functions.
[Answer]
# [JavaScript (V8)](https://v8.dev/), 152 bytes
```
i=>{return n="",p=0,e=1,i.split(" ").map(i=>{e&&("inc"==i&&p++,"dec"==i&&p--,"mult"==i&&(p*=2),"half"==i&&(p/=2),"Pri"==i&&(n+=p),"exit"==i&&(e=0))}),n}
```
[Try it online!](https://tio.run/##XY1BDoIwEEWv0syi6UhBdOVmPINXaLDomFqaUoiJ4ewVUDauJv9lXt7DjKZvIodUjqfcUmY6v6NNQ/TCE4AOVGtLB81VHxwnBQKwepqglkcrpQL2DRCxlKEoNFzttspSw3Nw6TtV2NERNdyNazeyX8kl8g/4gsIM7Is3yVKNOKH2U24633fOVq67qXatitkU/3eRxRIRaxsxfwA "JavaScript (V8) ‚Äì Try It Online")
]