title: Can you decrypt me? (Robbers)

text:
# Question
Title: Can you decrypt me? (Robbers)
# Can you decrypt me?

## Robbers

Find any combination of \\$n\\$ working chars to change and what they should change into, where \\$n\\$ is chosen by the cop. You cannot change less than n chars, only exactly \\$n\\$.

## Example

```
print(2)

```

N is 1.

---

Robbers' post:

```
print(1)

```

## Scoring

For the robbers, the user with the most cracks wins. If there is a tie, then it is a tie.

# Answer
> 2 votes
# brainfuck, 49 bytes, \\$n = 49\\$, cracks @l4m2's answer

```
"-[>->>-<<<---------]>-----"&console.log(196>>2.)

```

Try it online!

Polyglot with JavaScript (Node.js), just to keep things interesting.

# Answer
> 1 votes
# Python 3.8 (pre-release), by enzo 723 bytes, n=9

Probably not as intended, but this works...

```
P=3
p=[i*(P+1)+1*(i//2)for i in range(P)]
v=[(p[2]*(p[1]+1)+1)+(p[1]-1)*i for i in p]
I=[x*2-1+(v[2]-v[1]+1)*(i//2)for i,x in enumerate(v[::-1])]
t=[vars(__builtins__)[dir(__builtins__)[i]]for i in I]
m='_'.join(vars(t[0])[dir(t[0])[i]].__name__ for i in v)
M=vars(__builtins__)[dir(__builtins__)[v[2]+1]](''.join(x.__name__[:len(t)-i]for i,x in enumerate(t)))
l=t[2](M,m[2:v[1]-v[0]+1]+m[v[2]-v[1]+t[1](t[0](v[2])[-1]):])[-1::-1]
PP=[len(dir(t[2]))-p[2]-1,len(m),sum(len(dir(x))for x in t)//sum(p)+len(p)-1,I[1]%(len(dir(t[1]))+len(dir(t[2]))),sum(p)-1,sum(I)//sum(v)+len(p)-1,sum(p)-1,p[2],I[1]%(len(dir(t[1]))+len(dir(t[2]))),v[2]-v[0]-len(v)-1]
print(9)#xxxxxxt[0])[dir(t[0])[sum(PP[:P])]](t[0](),[l[i-1]for i in PP])))

```

Try it online!

# Answer
> 1 votes
# brainfuck, cracks l4m2's answer, 57 bytes, n=3

```
>++--+++++++++++++++++++++++++++++++++++++++++++++++++++.

```

Try it online!

I assume this is the intended one? n=3 doesn't offer many possiblilities.

# Answer
> 1 votes
# Python, 669 bytes Mukundan314's

```
import lzma
exec(lzma.decompress(b'\xe0\x00E\x00A]\x004\x9bJg\xb8R<s\xda\xb0\xe5\xbe\xe9\xde\t\x02\x8d\x9d\x02LW\x8bw\x87\xf3mkn1\xc5\xd9\xd6\xe9\xc9E\xf25\xd3\xd7\x01\x91\xc2FM4\xe5sW\xd6\xaaR\x07j\xe7\xa3\x80\x05b\xfcZ9\x0en5\xc2\x00\x01\x00\x00/\x00\xe0\x00\x86\x00y]\x002\x9d\x88\xce\xe12k^\xffi\x8eN\xf1\x83j-\xf5\\\x86\xd9\x01\xb6\xban\xb5_B\xcb@\xeeZ\x05u\x9c,a\xf3\xd1\xf5y\x96\xd0\xf6\x11\x82y\x13\x9cUb:j\x13\xa72\xccl_J\x90*\xf0\x1b[t\x84\xcb\xad\xff>qg\xf7\xe7\x93L\x04\x8fT\x91\xfe\xc9\xd1\x84]\x9f\xcd\xa6\x9e3W[\xbb\xcb/A\xbbZr\x9fq\xf5Wj\xe4\xe0\\\xadt)\xea\xee\xa7]\x80A1\x04\x8e\x9aM\x00', format=lzma.FORMAT_RAW, filters=[{'id': lzma.FILTER_LZMA2}]))

```

Attempt This Online!

IDKY I brute-forced

# Answer
> 1 votes
# Python, 873 bytes

```
import lzma;exec(lzma.decompress(b'\xe0\x00\x86\x00\x7f]\x00\x05\t\x8c\x1f48\x17VAca7\xfc\xaf\xf6\xcd(?\xfa\x11\xf2f\x12\xa8\xe8\xd5\xeb!\x99\xe1\xe7\x81i\x94\x9ej\xf1\x95\x1f\xdd\x83\x11\x01\x84\xb8\xa9=\xe2\xa6\xe6\x88\x8b\xb0\x8a\xacWkV\xc4!\xb4\xaf\\c\xfa\xbc\xf9\xb1\xee\x04\'\xe7d0pJ3B\x02\xcbH\xa2u\r6\xe2>4\xb8\x8f\xe1\x99\x1bW\x8c\x0cT/\xd7wt.{_\x89\t\xb1Ws\xdc\x7f.\xcc\xd6\xb8\x0f\x874\x8eH\xb4\xccq\xb7UV\x00\x00\x01\x00\x00b\x00\x01\x00\x18a85aa25882b90aaa356ebd56b\x00\x01\x00\x008\x00\x01\x00\x006\x00\x01\x00\x007\x00\x01\x00\ndf940ede04a\x00\x01\x00\x000\x00\xe0\x00T\x00A]\x002\r\x88&\x926K\xd9\xf0vNM\xc8\xee\x93\xdfB\xf5\xf5t\x85\x88:\xf9\xa5\xe0\xeb`\xc4\xbdK\xf6s%\xe4\xdf\xae\x1a\xe1-\t\x91\xda\xab\xd0\x10\xea\xa1\x9d\xcd\xec\xe9\x95hD\xb8\xfb\x90\x8e\xe8\x9d\x99"\x14\x00\x00', format=lzma.FORMAT_RAW, filters=[{"id": lzma.FILTER_LZMA2}]).decode())

```

Attempt This Online!

Actually even the part you don't specify can change

# Answer
> 1 votes
# Python 3, generate bunch of solutions for Command Master's

```
import sys
s = '77925340277363824169293758807642437284508406489944233814731817114744334387054677199464359370358303681225801571736917189241020964424020531423054738521455432784731931386377196234255749859141710848221995*7660297729448052594468076976871308901099050010752258215140275334247136696601489292003583235840730794856813394396865245853772202539436917905108732823263342134564638227230398268672502337581353160403575356676232895580244410109024495577929416391%997624712161309143295415334518642567808466476564516128021383833912794511198191262082650250977292178811713461440089160581066992373718706289075971369001597094521060013695658387955211810675571614035311614'
g = '0123456789+-*/&|^%~'
for i2 in range(len(s)):
	for c2 in g:
		sys.stderr.write (str(i2)+','+str( c2)+'\r')
		for i1 in range(i2):
			for c1 in g:
				try:
					cmd = s[:i1] + c1 + s[i1+1:i2] + c2 + s[i2+1:]
					if cmd.count('**') == 0:
						t = eval(s[:i1] + c1 + s[i1+1:i2] + c2 + s[i2+1:])
						if t == 2:
							print(i1, c1, i2, c2)
				except:
					0

```

Try it online!

I don't know which is intended or not listed but a bunch of solution provided. You can also claim xnor solved it

Time: 14m22.162s

Output: Here

# Answer
> 1 votes
# ///, 8271 bytes, n=2, by Fmbalbuena

```
/~-/-~~//-~/~\--//-*///*\*/76543//~~~~~~~~~~~~%%%/*2*//~///*///%/4//-//~~~--********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************%%%
             ^                                     ^

```

Try it online!

### Alternative solution

```
/~-/-~~//-~/~%--//-*///*\*/76543//~~~~~~~~~~~~%%%/***//~///*///%/4//-//2/~--********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************%%%
                                                                       ^^

```

Try it online!

Not a good choice of language.

# Answer
> 1 votes
# C++ (gcc), 5204 bytes

```
#include <iostream>
using namespace std;
string secret = "secret";
void f1(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"611111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f2(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f3(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f4(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f5(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f6(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
void f7(){if(secret.length()!=6){cout<<"1111111";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1111111";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1111111";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1111111";return;}}}}}}}}
int main() {
    f1();
    /*();
    f3();
    f4();
    f5();
    f6();
    f7();
    cout<<6;
    f1();
    f2();
    f3();
    f4();
    f5();
    f6();
    f7(*/
}

```

Try it online!

Can't hack without `\0`

---

For someone trying to solve in intended way:

* You are supposed to choose 6 elements from \[1,111\]
* For each set of 6 elements in \[1,111\], there's non-empty subset of both, whose sum is same
* Then I don't know if any conclusion used
* Searched for one day and get `,>@Vn~`
* Confirmed unique. `time` result `895471.99user 2246.72system 28:27:01elapsed 876%CPU (0avgtext+0avgdata 411544maxresident)k 2352inputs+1721048outputs (229024major+17451minor)pagefaults 0swaps`

# Answer
> 0 votes
# C++ (gcc), 4960 bytes, cracks dfe dfe's cop

Sorry for the unintended solution ): I'll try to find the intended one, it seems interesting. This only used 4 changes, if you must use all 6 than you can just change the comment.

```
#include <iostream>
using namespace std;
string secret = "secret";
void f1(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"6";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f2(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f3(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f4(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f5(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f6(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
void f7(){if(secret.length()!=6){cout<<"1";return;}int a[6]={secret[0]-' ',secret[1]-' ',secret[2]-' ',secret[3]-' ',secret[4]-' ',secret[5]-' '};for(int i=0;i<5;i++){if(a[i]>=a[i+1]){cout<<"1";return;}}for(int i=0;i<6;i++){if(a[i]<=0||a[i]>111){cout<<"1";return;}}for(int i=1;i<=111;i++){for(int j=i+1;j<=111;j++){for(int k=j+1;k<=111;k++){for(int l=k+1;l<=111;l++){for(int m=l+1;m<=111;m++){for(int n=m+1;n<=111;n++){int b[6]={i,j,k,l,m,n};bool yay=false;for(int o=1;o<(1<<6);o++){for(int p=1;p<(1<<6);p++){int asum=0;int bsum=0;for(int q=0;q<6;q++){if(o&(1<<q)){asum+=a[q];}if(p&(1<<q)){bsum+=b[q];}}if(asum==bsum){yay=true;break;}}if(yay){break;}}if(!yay){cout<<"1";return;}}}}}}}}
int main() {f1();}//);f3();f4();f5();f6();f7();cout<<6;f1();f2();f3();f4();f5();f6();f7();}

```

Try it online!

---
Tags: number, cops-and-robbers
---


title: How many arguments were passed?

text:
# Question
Title: How many arguments were passed?
Using your language of choice, write a function that takes a variable number of arguments and returns the number of arguments it was called with.

Specifics:

* Your language needs to support variadic argument functions: something callable that takes an arbitrary number of arguments and returns a value.
* Parameters must be able to be passed individually. This means that passing an array would only count for one parameter. You can use an "all passed arguments" array if your language supports it; the restriction is on how the function is called.
* Code that calls this function must not be required to pass the number of arguments *in its source*. If a compiler inserts the number of arguments as part of a calling convention, that is allowed.
* The arguments can be of any type you want. You can support only a single type (e.g. only supporting `int` is still valid), arbitrary types (any type of argument is allowed), or any combination of argument types (e.g. first arg is `int`, rest are strings).
* Your function may have a maximum number of arguments (especially since resources are finite), but must support *at least 2* arguments.

Samples:

* `f()` returns `0`
* `f(1)` or `f("a")` returns `1`
* `f([1, 2, 3])` returns `1` as it is passed an array, not 3 arguments
* `f(1, 10)` or `f(1, "a")` returns `2`

As this is code-golf, the winning solution is the one that uses the fewest number of bytes.

# Answer
## Amstrad CPC Z80 binary call from BASIC, 1 byte, hex encoded

```
C9          : RET

```

(Also 2 and 5 byte versions, see below)

Upon entry to the call, the number of parameters passed will be in the `A` register. The code simply returns immediately. There is no concept of return values in the Z80, just entry and exit states. The value is just "there" accessible in the register since the code changes no input conditions, except for `PC` (the program counter) and `SP` (the stack pointer). However, the value in `A` is not accessible to BASIC and gets overwritten almost immediately.

Examples:

```
CALL &8000, "Hello", "World"

```

`A` = 2

```
CALL &8000, 42

```

`A` = 1

```
CALL &8000

```

`A` = 0

---

By request, here is some code that makes the value accessible in BASIC. I was very surprised to find it could be done in only 5 bytes!:

### The machine code:

```
12          : LD   (DE), A
13          : INC  DE
AF          : XOR  A
12          : LD   (DE), A
C9          : RET

```

On entry:

* `AF` \- the accumulator and flags registers (treated as two 8-bit registers)
    + `A` contains the number of parameters passed, up to the maximum of 32 parameters
    + I'm not sure what's in `F`. It appears to have all flags RESET to `0`, except the two undefined flags which are both `1`. The `Z` flag (zero) is SET to `1` if there were no parameters passed in
* `BC`
    + `B` \- 32 minus the number of parameters (`A` \+ `B` = 32)
    + `C` \- `&FF`
* `DE` \- The address of the last parameter, or the calling address if no parameters were passed in
* `HL` \- The address of the first byte after the tokenised BASIC command currently being executed (either as a program or in immediate command mode)
* `IX` \- The stack address of the pointer to the last parameter
* `IY` \- `&0000`

The code

1. `L`oa`D`s the address pointed to by `DE` with the value in `A`
2. `INC`rements `DE`
3. `XOR`s `A` (with `A`), giving `&00`
4. `L`oa`D`s the value in `A` to the address pointed to by `DE`
5. `RET`urns

On exit:

* `A` is destroyed (it's always `&00`)
* `DE` is destroyed (it's always one higher than on entry)
* All other registers are preserved

### The BASIC

Amstrad basic has only three data types, plus simple arrays. By default, all BASIC variables are REAL (signed, 32 bit mantissa, 8 bit exponent), which can be made explicit with `!`. For an INTEGER (signed, 16 bit) use `%` and for a STRING (1 byte string length, up to 255 bytes character data, binary safe) use `$`:

* `x` \- REAL (implicit)
* `x!` \- REAL (explicit)
* `x%` \- INTEGER
* `x$` \- STRING

You can also use `DEFINT`, `DEFREAL` and `DEFSTR` with a single letter, or a range of two single letters to specify the default type for all variables starting with that letter, similar to FORTRAN.

* `DEFSTR a`
* `DEFINT x-z`

Now:

* `a` \- STRING (implicit)
* `i` \- REAL (implicit)
* `x` \- INTEGER (implicit)
* `x$` \- STRING (explicit)

The easiest type to work with is the integer. The machine code expects the last parameter to passed by address, not value, which is why `@` is prefixed to the variable. The return variable is counted as one of the `CALL`s parameters.

The machine code is called as follows from BASIC (assuming it's loaded at into memory at address `&8000`):

```
CALL &8000, "Hello", "World", 42, @n%

```

`n%` = 4

This will always give the correct result, regardless of the initial value of `n%`.

For a 2-byte version that preserves all input registers:

```
CALL &8003, "Hello", "World", 42, @n%

```

`n%` = 4

This skips the first three bytes, and only gives the correct result if the initial value of `n%` is `0`-`255`. This works because the Z80 is little-endian.

The return parameter must be initialised before being passed, otherwise BASIC will throw an `Improper argument` error. In the below image, I am printing (with the shortcut `?` since I've golfed the demonstration too!) the return values immediately before and after the call to show the value changing. I'm using the value `&FFFF` because that is the binary representation of `-1` for a signed integer. This demonstrates that the 5-byte program correctly writes both bytes, whereas the 2-byte program only writes the low byte and assumes that the high byte is already `&00`.
> 17 votes

# Answer
# Java (JDK 10), 11 bytes

```
a->a.length

```

Try it online!
> 37 votes

# Answer
# JavaScript, 15 bytes

```
[].push.bind(0)

```

The `Array.prototype.push` function takes any number of arguments, adds them to its array, and returns the size of the array. Therefore, the `push` function used on an empty array returns the number of arguments supplied to `push`.

```
f = [].push.bind(0)

f(10,2,65,7)
> 4

f()
> 0

```

The `.bind(0)` simply gives the `push` function a fixed `this` value so that it can be stored in a variable. In fact, the 7-byte identifier **`[].push`** can be used literally (but not assigned) without `bind`:

```
[].push(10,2,65,7)
> 4

[].push()
> 0

```
> 32 votes

# Answer
# JavaScript (ES6), 16 bytes

```
(...a)=>a.length

```

```
f=
(...a)=>a.length

console.log(f())
console.log(f(1))
console.log(f(1,2))
console.log(f(1,2,3))
console.log(f(1,2,3,4))
```
> 20 votes

# Answer
# Haskell, 108 107 95 94 bytes

```
class T r where z::Int->r
instance T Int where z=id
instance T r=>T(a->r)where z n _=z$n+1
z 0

```

Try it online!

This was surprisingly hard to get working, but I had fun trying to find out how to implement something that's trivial in imperative languages.
> 19 votes

# Answer
# Python 3, 15 bytes

```
lambda*a:len(a)

```

Try it online!
> 17 votes

# Answer
# Zsh, ~~7~~ 5 bytes

```
<<<$#

```

Try it online!
> 12 votes

# Answer
# Brain-Flak, 6 bytes

My first Brain-Flak solution worthy posting, I guess it's the right tool for this job:

```
([]<>)

```

Try it online!

### Explanation

When executing a Brain-Flak program, initially the left stack contains all arguments. From there it's simply a matter of:

```
(      -- push the following..
 []    --   height of the stack (ie. # of arguments)
   <>  -- ..to the other stack  (toggles to the other stack)
)      --
       -- the right stack now contains the # of arguments which
       -- gets printed implicitly

```
> 9 votes

# Answer
# Wolfram Language (Mathematica), 11 bytes

```
Tr[1^{##}]&

```

Try it online!

Suggested by JungHwan Min. Some restrictions (input must be rectangular) but we are not required to handle arbitrary input.

**11 bytes**

```
Length@!##&

```

Try it online!

Another 11 byte solution suggested by Martin Ender. This seems to error when there isn't one input but it still returns the correct value in all cases.

**12 bytes**

```
Length@{##}&

```

Try it online!

My original solution.

In Mathematica `##` stands for a variadic number of arguments in a function. `{` and `}` wraps them in a list and `Length@` takes the length of this list. `&` at the end turns this into an actual function.
> 8 votes

# Answer
# C++14 (gcc), 34 bytes

As generic variadic lambda function (C++14 required):

```
[](auto...p){return sizeof...(p);}

```

Try it online!

### Previous (incorrect) answer: 32 bytes

It was missing the `template<class...T>` and `(p)`

```
int f(T...p){return sizeof...p;}

```
> 7 votes

# Answer
# , 30 bytes

```
function(...)length(list(...))

```

Try it online!
> 7 votes

# Answer
# Bash, 12 bytes (thanks to paxdiablo for saving 4)

```
n()(echo $#)

```

Copy and paste at a bash prompt. Then run the n function from the prompt:

```
$ n
0
$ n 46 gr 3443 dad
4
$ n 4fwj23 wrw jdwj 00998 34 eyt q3 vg wq j qw
11

```
> 7 votes

# Answer
# Octave, 9 bytes

```
@()nargin

```

Try it online!

Anonymous function taking any number of arguments (and silently discarding the lot), and outputs the number of arguments through the built-in `nargin`. This does not work in MATLAB, where you would need `varargin` to allow for arbitrary many arguments.
> 6 votes

# Answer
# Ruby, 12 bytes

```
->*a{a.size}

```

Try it online!

`*a` is a splat of the arguments, making `a` consume all arguments passed to the Proc. `a.size` obtains its size.
> 5 votes

# Answer
# Perl 6, 5 bytes

Thanks @Joshua for -5 bytes

```
{+@_}

```

Try it online!
> 5 votes

# Answer
# Perl 5, 9 bytes

```
sub{~~@_}

```

Try it online!
> 4 votes

# Answer
# Dodos, ~~32~~ 31 bytes

```
f
	dot i f dab
i

	dip dot dab

```

Try it online!

Uses Dennis' increment function.

## Explanation

```
f                     # definition of f - target function
        dot i f dab   # sum of j(f(all args but first)). recurses until it has 0 args
i                     # definition of i - returns (arg, 1) given 1 arg
                      # arg
        dip dot dab   # 1 (dot dab on list of length 1 returns 0, dip returns |0 - 1|)

```

Alternatively, 32 bytes without recursion in target function (thanks @Leo)

```
	dot i
i
	dip dot dab dot
	i dab
```

Try it online!

## Explanation

```
        dot i             # anonymous function: sum of i(args)
                          # here this becomes implicit main
i                         # definition of i - returns a list with all arguments replaced with 1
        dip dot dab dot   # 1 (dab dot returns empty list, dot returns 0, dip returns |0 - 1|
        i dab             # list concatenated with i(all args but first)

```
> 4 votes

# Answer
# C++, 72 bytes

```
int f(){return 0;}template<class...P>int f(int,P...p){return f(p...)+1;}

```

Saves bytes by only working with ints.
> 4 votes

# Answer
# PHP, 34 bytes

```
function(...$a){return count($a);}

```
> 4 votes

# Answer
# C# .NET, 11 bytes

```
a=>a.Length

```

Try it online.

**Explanation:**

In C# .NET `object` is used for multi-type arguments, allowing one to pass integers, strings, characters, etc. as possible inputs. For example:

```
// Can be called like: `F(2)`, `F("test")`, `F('a')`, etc.
void F(object arg){ ... }

```

C# .NET can also have a fixed size of optional arguments. For example:

```
// Can be called like: `F()`, `F(2)`, `F("test")`, `F('a')`, etc.
void F(object arg = null){ ... }

```

And there are also varargs, which is an undefined amount of optional arguments (which is what I've used in this answer). For example:

```
// Can be called like: `F()`, `F(2)`, `F(2, "test", 'a')`, etc.
void F(params object[] args){ ... }

```

Usually lambdas are created like this:

```
System.Func<object[], int> F f = a=>a.Length;
// A call like `f(new object[]{2, "test", 'a'))` will return 3 (size of the input array)

```

But unfortunately `System.Func` doesn't support `params` varargs, so I'll have to create a `delegate` instead:

```
delegate int F(params object[] args);
F f = a=>a.Length;
// A call like `f()` will return 0, and `f(2, "test", 'a')` will return 3

```

Which is my answer for this challenge, and can be found in the linked TIO test code.

---

The only limitation is that inputting an actual `object[]` like `f(new object[]{1,2,3})` will result in 3 instead of 1. `f(new int[]{1,2,3})` will still result in 1, because it interprets the `int[]` as a single `object`. To have the `object[]` parameter be interpret as a single object as well it can be casted to an object like this: `f((object)new object[]{1,2,3})`.
> 4 votes

# Answer
# Rust, 57 bytes

```
macro_rules!f{()=>{0};($($x:expr),+)=>{[$($x),+].len()};}

```

Explanation:

```
macro_rules! f {         // define a macro called f
    () => {0};           // when called without arguments, expand to 0
    ($($x:expr),+) => {  // when called with 1 or more comma seperated arguments
        [                // rust uses [a, b, c] to make an array
            $($x),+      // expand to the arguments seperated with a comma
        ]
        .len()           // take the length of that.
    };
}

```

Test:

```
fn main() {
    println!("{:?}", f!());                // prints 0
    println!("{:?}", f!(4));               // prints 1
    println!("{:?}", f!(5, 2));            // prints 2
    // works with anything, as long as you dont mix things
    println!("{}", f!("", "a", "hello"));  // prints 3
}

```
> 3 votes

# Answer
# , 20 bytes

```
function(...)nargs()

```

Try it online!

R has a function just for that.
> 3 votes

# Answer
# PHP, 35 bytes

```
function(){return func_num_args();}

```

manual entry
> 2 votes

# Answer
# Common Lisp, 28 bytes

```
(defun f(&rest a)(length a))

```

Try it online!
> 2 votes

# Answer
# Add++, 3 bytes

```
L,L

```

Try it online!
> 2 votes

# Answer
## Batch, ~~50~~ 49 bytes

```
set n=0
for %%a in (%*)do set/an+=1
exit/b%n%

```

No builtin in Batch, so we have to go old-school. Saved 1 byte thanks to @IsmaelMiguel. Outputs via exit code, or save 3 bytes if output via global variable is valid. Example of use in a full program:

```
@echo off
call:c %*
echo %ERRORLEVEL%
exit/b
:c
set n=0
for %%a in (%*)do set/an+=1
exit/b%n%

```
> 2 votes

# Answer
# PHP, 11 bytes

```
<?=$argc-1;

```

Try it online: 1 input | 3 inputs
> 2 votes

# Answer
# Go, ~~44~~ ~~30~~ 28 bytes

-2 bytes thanks to BMO

My first code golf attempt.

```
func(a...int){print(len(a))}

```

Try it online (outputs to Debug-window instead of STDOUT).
> 2 votes

# Answer
# PowerShell 3, 25 bytes

```
function a(){$args.Count}

```

Usage:

```
a 1 2 ...

```

Console output for "a 1 2 3"

```
PS: C:\> a 1 2 3
3

```

Pretty self explanatory. Powershell stores all unspecified args in the $args list, so we just grab a count of it. Since the language implicitly writes values to the console, the act of finding the count will print to the console without needing a Write-Host or Write-Output.

Edit: Mistyped; should have been 25 bytes (typed 35).
> 2 votes

# Answer
# x86 32-bit (i386) machine code function, 13 bytes

Calling convention: **i386 System V (stack args), with a NULL pointer as a sentinel / terminator for the end-of-arg-list**. (Clobbers EDI, otherwise complies with SysV).

C (and asm) don't pass type info to variadic functions, so the OP's description of passing integers or arrays with no explicit type info could only be implemented in a convention that passed some kind of struct / class object (or pointers to such), not bare integers on the stack. So I decided to assume that all the args were non-NULL pointers, and the caller passes a NULL terminator.

**A NULL-terminated pointer list of args is actually used in C for functions like POSIX `execl(3)`**: `int execl(const char *path, const char *arg, ... /* (char *) NULL */);`

C doesn't allow `int foo(...);` prototypes with no fixed arg, but `int foo();` means the same thing: args unspecified. (Unlike in C++ where it means `int foo(void)`). In any case, this is an asm answer. Coaxing a C compiler to call this function directly is interesting but not required.

`nasm -felf32 -l/dev/stdout arg-count.asm` with some comment lines removed.

```
24                       global argcount_pointer_loop
25                       argcount_pointer_loop:
26                               .entry:
28 00000000 31C0             xor   eax, eax  ; search pattern = NULL
29 00000002 99               cdq             ; counter = 0
30 00000003 89E7             mov   edi, esp
31                       ;    scasd           ; edi+=4; skip retaddr
32                       .scan_args:
33 00000005 42               inc   edx
34 00000006 AF               scasd            ; cmp eax,[edi] / edi+=4
35 00000007 75FC             jne  .scan_args
36                       ;    dec   edx       ; correct for overshoot: don't count terminator
37                       ;    xchg  eax,edx
38 00000009 8D42FE           lea   eax, [edx-2]    ; terminator + ret addr
40 0000000C C3               ret

size = 0D               db $ - .entry

```

The question shows that the function must be able to return 0, and I decided to follow that requirement by not including the terminating NULL pointer in the arg count. This does cost 1 byte, though. (For the 12-byte version, remove the LEA and uncomment the `scasd` outside the loop and the `xchg`, but not the `dec edx`. I used LEA because it costs the same as those other three instructions put together, but is more efficient, so the function is fewer uops.)

**C caller for testing**:

Built with:

```
nasm -felf32 -l /dev/stdout arg-count.asm | cut -b -28,$((28+12))- &&
 gcc -Wall -O3 -g -std=gnu11 -m32 -fcall-used-edi arg-count.c arg-count.o -o ac &&
 ./ac

```

`-fcall-used-edi` is required even at -O0 to tell gcc to assume that functions clobber `edi` without saving/restoring it, because I used so many calls in one C statement (the `printf` call) that even `-O0` was using EDI. It appears to be safe for gcc's `main` to clobber EDI from its own caller (in CRT code), on Linux with glibc, but otherwise it's totally bogus to mix/match code compiled with different `-fcall-used-reg`. There's no `__attribute__` version of it to let us declare the asm functions with custom calling conventions different from the usual.

```
#include <stdio.h>

int argcount_rep_scas();       // not (...): ISO C requires at least one fixed arg
int argcount_pointer_loop();   // if you declare args at all
int argcount_loopne();

#define TEST(...) printf("count=%d = %d = %d   (scasd/jne) | (rep scas) | (scas/loopne)\n", \
        argcount_pointer_loop(__VA_ARGS__), argcount_rep_scas(__VA_ARGS__), \
        argcount_loopne(__VA_ARGS__))

int main(void) {
    TEST("abc", 0);
    TEST(1, 1, 1, 1, 1, 1, 1, 0);
    TEST(0);
}

```

Two other versions also came in at 13 bytes: this one based on `loopne` returns a value that's too high by 1.

```
45                       global argcount_loopne
46                       argcount_loopne:
47                           .entry:
49 00000010 31C0             xor   eax, eax  ; search pattern = NULL
50 00000012 31C9             xor   ecx, ecx  ; counter = 0
51 00000014 89E7             mov   edi, esp
52 00000016 AF               scasd           ; edi+=4; skip retaddr
53                       .scan_args:
54 00000017 AF               scasd
55 00000018 E0FD             loopne  .scan_args
56 0000001A 29C8             sub   eax, ecx
58 0000001C C3               ret

size = 0D = 13 bytes               db $ - .entry

```

This version uses rep scasd instead of a loop, but takes the arg count modulo 256. (Or capped at 256 if the upper bytes of `ecx` are 0 on entry!)

```
63                       ; return int8_t maybe?
64                       global argcount_rep_scas
65                       argcount_rep_scas:
66                               .entry:
67 00000020 31C0             xor   eax, eax
68                           ;    lea   ecx, [eax-1]
69 00000022 B1FF             mov   cl, -1
70 00000024 89E7             mov   edi, esp
71                       ;    scasd              ; skip retaddr
72 00000026 F2AF             repne scasd        ; ecx = -len - 2 (including retaddr)
73 00000028 B0FD             mov   al, -3
74 0000002A 28C8             sub   al, cl       ; eax = -3 +len + 2
75                       ;    dec   eax
76                       ;    dec   eax
77 0000002C C3               ret

size =  0D = 13 bytes         db $ - .entry

```

Amusingly, yet another version based on `inc eax` / `pop edx` / `test edx,edx` / `jnz` came in at 13 bytes. It's a callee-pops convention, which is never used by C implementations for variadic functions. (I popped the ret addr into ecx, and jmp ecx instead of ret. (Or push/ret to not break the return-address predictor stack).
> 2 votes

# Answer
# JavaScript, 35 bytes

```
f=
function(){return arguments.length}

console.log(f(2,5,4))
```
> 1 votes

# Answer
# Cauliflower, 16 bytes

```
(\((@a))(len@a))

```

Try it online!
> 1 votes

# Answer
# Actually, 2 bytes

```
`

```

Try it online!

Note: this is a grave and a space
> 1 votes

# Answer
# Japt, 2 bytes

```
Nl

```

I suspect the answer will be similar in many golfing languages, take all of the inputs as an array and return its length.

Try it online!
> 1 votes

# Answer
# Kotlin, 26 bytes

Defines function `a` with a `vararg` parameter `x: Any`. Thus, the arguments passed can be anything but `null`.

```
fun a(vararg x:Any)=x.size

```

Try It Online!
> 1 votes

# Answer
# Clojure, 11 bytes

```
#(count %&)

```

Try it online!
> 1 votes

# Answer
# Lua, 11 bytes

```
print(#arg)

```

Try it online: 1 input | 3 inputs
> 1 votes

# Answer
# Julia 0.6, 16 bytes

```
f(x...)=endof(x)

```

Try it online!
> 1 votes

# Answer
# Stax, 4 bytes

```
{L%}

```

Run and debug it at staxlang.xyz!

Simple. Listifies the entire stack and all input, and returns the resulting length. No thought went into this answer.

Works without the closing brace, but I think that that makes it an incomplete "function" (block).
> 1 votes

# Answer
# Vim, 10 bytes

```
:ec argc()

```

Where "an argument" is a filename for Vim to edit. Hopefully this counts.
> 1 votes

# Answer
**Avail, 32 characters**.

```
Method"f(«_‡,»)"is[t:tuple||t|];

```

Avail's a little different. Any particular function has fixed arity, so the nearest approximation is a multi-method taking a polyadic argument (shown with spaces)...

```
Method "f(«_‡,»)" is [t : tuple | |t|];
Assert f(10,20,30) = 3;

```

The guillemets say expect multiple arguments (the underscore), separated by commas (the comma after the double-dagger). The "f", "(", and ")" (and ",") are actual keywords of this method. The guillemet mechanism is supported by the compiler, which assembles instructions at call sites (like the Assert statement on the second line) to assemble arguments into a tuple, mostly similar to Java. However, Avail also supports multiple repeated arguments, nested repetitions, strong heterogeneously typed arguments, and a ton more.

In the general spirit of code golf,

```
Method "g(«x‡,»#)" is [w : whole number | w];
Assert g(x,x,x) = 3;

```

The # after the close-guillemet arranges to pass the number of repetitions of the preceding group, rather than the actual tuple. However, it's pointless to throw away actual arguments, so they're forbidden in such a group. Only constant tokens are allowed, namely "x" in this case, as reflected in the example assertion.
> 1 votes

# Answer
# Pyth, 10 bytes

```
D[$*b$)Rlb

```

Try it online!

Pyth doesn't really support defining variadic functions, but it does allow embedding Python code directly into the source, and Python allows variadic functions. We can get away with just using two bytes of Python code: `*b`, which makes `b` a variadic argument, containing the list of arguments passed in. We redefine the function `[`, which the Pyth parser understands to be a variadic function, and then we simply return the length of `b`.

Note that this can be run on TIO but not the standard Pyth executor at `http://pyth.herokuapp.com/`, due to sandboxing limitations.
> 1 votes

# Answer
# AutoHotkey, 33 bytes

```
f(p*){
n+=p.MaxIndex()
return n
}

```

The asterisk `*` defines the parameter `p` as a variadic parameter.
`MaxIndex()` returns the highest numeric index which, in this case, is the parameter count.
By starting with nothing and adding the `MaxIndex`, you get a `0` for empty calls.

Here's an example of it in a full program:

```
MsgBox % f()
MsgBox % f(1)
MsgBox % f([1, 2, 3])
MsgBox % f(1, 10)
MsgBox % f(1, "a")

Exit

f(p*){
n+=p.MaxIndex()
return n
}

```

The returns as shown in the message box are (in order) 0,1,1,2,2.

---

# AutoHotkey, 8 bytes

If it is allowable to write an entire program that returns the number of parameters passed to it, the result is much shorter:

```
Send %0%

```
> 1 votes

# Answer
# Röda, 15 bytes

```
main a...{[#a]}

```

Try it online!

`a...` indicates that the program takes in a variable number of arguments

`[ ]` prints the following

* `#a` the length of variable `a`
> 1 votes

# Answer
# x86-64 machine code, 5 bytes (program for Linux, exit status = ret value)

# ia32 (i386) machine code, 4 bytes

This program does `sys_exit(argc)`.

It works for the x86-64 System V ABI, where the stack on process entry has `argc` followed by `argv[0]`, `argv[1]`, ... NULL, `envp[0]`, ..., NULL. (Or the i386 SysV ABI, where the stack layout is the same, but in 4-byte elements).

`nasm -felf64 -l /dev/stdout arg-count.asm` listing output:

```
 1                                  global _start
 2                                  _start:
 3 00000000 5F                          pop rdi
 4 00000001 B03C                        mov al, 60     ; __NR_exit
 5 00000003 0F05                        syscall

```

Most registers (including `rax`) are zeroed by the kernel on entry to user-space. To we can set rax=60 with just a `mov al` in a static executable where no dynamic linker code ran first.

Assemble + link into a static executable with
`yasm -felf64 arg-count.asm && ld -o arg-count arg-count.o`

---

```
   32-bit version: nasm -felf32 -l /dev/stdout arg-count.asm
 1                                  global _start
 2                                  _start:
 3 00000000 5B                          pop ebx
 4 00000001 40                          inc eax       ; __NR_exit = 1
 5 00000002 CD80                        int 0x80

yasm -felf32 arg-count32.asm &&
ld -melf_i386 -o arg-count32 arg-count32.o

```

32-bit `__NR_exit` is 1, so the constant only takes a 1-byte `inc` (the kernel still zeros registers).

---

Note that `argc` includes the first arg passed by the shell which by convention is the name of the executable, but doesn't have to be. `execve` doesn't care if you exec a process with `argv[0]` being something other than the executable filename. It's a real arg, and some programs actually use it to figure out how they were invoked (useful for multiple hardlinks to one executable with different behaviours, like busybox can be `ls` or `mv` depending on `argv[0]`)

```
$ ./arg-count ; echo $?     # by convention, program name is passed as a first arg
1
$ ./arg-count a b c d; echo $?
5
$ ./arg-count {a..z} ; echo $?
27
$ ./arg-count $(seq 100); echo $?
101
$ ./empty-args ./arg-count ; echo $?     # runs with argc=0 / argv[0]=NULL
0

```

(`empty-args` is a wrapper program that calls `execve(argv[1], {NULL}, {NULL})`. It is possible to "call" the program with an empty argument list, just not from bash directly.)

Note that the `echo $?` is just how you can *see* the exit status printed to the screen. It's always returned to the shell by this program, whether you print it or not. The submission is the program's machine code, not the way I run it from the shell.
> 1 votes

# Answer
# 05AB1E, 2 bytes

```
|g

```

Try it online.

**Explanation:**

```
|     # Take all new-line separated inputs as a single list
 g    # Take the length of this list

```
> 1 votes

# Answer
# Pyth, 9 bytes

```
D[$*N$)lN

```

Try it online!

Variadic functions cannot be defined in pure Pyth, but using the raw Python override `$$`, it's easy. This translates to the Python program:

```
def list(*N):
    print(len(N))

```

Where `[` is the function defined.
> 1 votes

# Answer
## Spice, 23 bytes

```
;a;return@LEN a return;

```

## Un-golfed explanantion

Spice has no concept of functions - the closest would be a module which are called with the format:

`LOD .\module.spice (^)input result`

Where the result is set to the final value of the variable `return` in the module. The optional `^` character passes the input as the given value rather than flattening the array across all variables in the module. So in this case we can require `^` and:

```
;a;return@     - declare vars
LEN a return;  - Get length of our input, a, and store in result

```
> 1 votes

# Answer
# Flurry, 2 bytes

```
[]

```

### Run example

```
$ ./flurry -nin -c "[]" 4 7 2 5 3
5

```

The arguments are pushed to the stack before running the code, and `[]` nilad returns the stack height. Flurry can output via return value (ignoring the stack), so we don't need to do anything about the stack.
> 1 votes

# Answer
# Vyxal, 7 bytes

```
@f:*|!;

```

Try it Online!

Note the last number before the input called is the no. of arguments.

<sub>shoutout to @lyxal for helping me!</sub>
> 1 votes

# Answer
# Julia 1.0, 17 bytes

```
f(x...)=length(x)

```

Try it online!
> 1 votes

# Answer
# Ruby, 12 bytes

Nothing exciting here. The splat operator (`*`) gathers all of the arguments into an array.

```
->*a{a.size}

```

Attempt This Online!
> 1 votes

# Answer
# Go, 31 bytes

```
func(a...any)int{return len(a)}

```

Attempt This Online!

Same length as this Go answer and 2 bytes longer than this Go answer.

Returns a value instead of printing.
> 1 votes

# Answer
# tinylisp, 27 bytes

```
(load library
(q(A(length A

```

Try it online!

### Explanation

`(q (A (expr)))` creates a variadic anonymous function that binds its arglist to `A` and evaluates `(expr)`. Then we just use the `length` function from the library to return the length of `A`.

---

Non-library solution, **33 bytes**:

```
(d F(q(A(i A(a(v(c(q F)(t A)))1)0

```

Try it online!

```
(d F                                )  ; Define F as
    (q(A                          ))   ; a variadic function:
        (i A                     )     ; If the arglist is not empty:
                       (t A)           ;  Tail of arglist
                (c(q F)     )          ;  Cons the symbol F to the front
              (v             )         ;  Evaluate (calling the function again)
            (a                1)       ;  Add 1 to the result
                                0      ; Otherwise, return 0

```

This approach evaluates some of the arguments multiple times and may generate lots of warning messages; however, I believe it always ultimately returns the correct answer.
> 1 votes

# Answer
# Attache, 5 bytes

```
{#__}

```

Try it online!

This is an anonymous lambda. `__` simply represents the arguments passed to it, and `#` calculates the length.
> 0 votes

# Answer
# Clojure, 11 bytes

```
#(count %&)

```

Try it online!
> 0 votes

# Answer
# CJam, 4 bytes

```
{],}

```

This defines a code block (CJam's analogous construct to a function) that takes all the stack contents as inputs.

**Try it online!**

### Explanation

```
{  }    e# Define block
 ]      e# Concatenate all stack into a list
  ,     e# Length

```
> 0 votes

# Answer
# Go, 31 bytes

```
func a(b ...int){print(len(b))}

```

Only works with integers to save space.

Try it here
> 0 votes

# Answer
# Tcl, 27 bytes

```
proc F args {llength $args}

```

Try it online!
> 0 votes

# Answer
# SimpleTemplate, 23 bytes

In this language, all functions have some special variables.

Luckly, one of them is `argc`, which contains the number of arguments passed to the program or function.

```
{@fna}{@returnargc}{@/}

```

This could be written as `{@fna}{@returnargc}` if it was the last thing in the file.

Alternativelly, running `{@returnargc}` by itself gives you back the number of arguments passed to the program itself.

---

**Ungolfed:**

```
{@fn a}
    {@return argc}
{@/}

```

All whitespace present here is optional.

---

**Example:** count the arguments passed to the function

```
{@fna}{@returnargc}{@/}

{@call a into b 1, 2, 3, 4, 5, 6}

{@echo b}

```

---

**How to run:**

1. Get the code from https://github.com/ismael-miguel/SimpleTemplate
2. Run the following code:

```
<?php
    include 'SimpleTemplate.php';

    $template = new SimpleTemplate('<code>');

    $template->render();

```
3. Done!

(Shamelessly lifted from Print a word clock and adapted for this challenge)
> 0 votes

# Answer
# Jstx, 3 bytes

```
s£O

```

Try it online!
> 0 votes

# Answer
# Swift, 37 bytes

```
func r(s:Any...)->Int{return s.count}

```

Try it online!
> 0 votes

# Answer
# Visual Basic .NET (.NET Core), ~~54~~ 49 bytes

Unfortunately, lambda expressions do not allow ParamArray in VB.net.

```
Function F(ParamArray a())
F=a.Count:End Function

```

**Try it online!**
> 0 votes

# Answer
## REXX, 12 bytes

```
return arg()

```

`arg` without arguments returns the number of arguments.
> 0 votes

# Answer
# Wolfram Language (Mathematica), 9 bytes

```
Length@*f

```

Try it online!

`Composition` of the `Length` function, which returns the number of arguments of an expression, and the undefined function `f`.
> 0 votes

# Answer
# Scheme, 16 bytes

```
(λ a(length a))

```

Or defining a named function (25 bytes):

```
(define(f . a)(length a))

```
> 0 votes

# Answer
# Yabasic, 17 bytes

An anonymous function that takes input as discrete arguments and outputs to the console.

```
?peek("argument")

```

Try it online!
> 0 votes

# Answer
# Brainfuck, 27

```
>>,[>,]<[[-]<[<]<+>>[>]<].

```

Try it online!

"arguments" are single characters. output is in ASCII (eg 32 args outputs a space). In order to see output normally, add this thing that I stole from esolang wiki (204 bytes)

```
>>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]<

```

## Explanation

```
>> padding
,[>,] input all
<[ for each
  [-] delete
  <[<]< go back to beginning
  + add one
  >>[>] go to the end
<] go back
<. print

```
> 0 votes

# Answer
# Lua, 30 bytes

```
function f(...)return#{...}end

```

Try it online!

Explanation: `...` is used to pass variadic arguments, `{...}` creates a new table and expands the argument list into that table, and `#` is the length operator (for arrays, returns number of elements).
> 0 votes

# Answer
# C macro (gcc), 61

* 3 bytes saved thanks to @ceilingcat.

I think the only way to do this in is with a preprocessor macro:

```
#define f(a...) ({char*s=#a,i=!!*s;for(;*s;)*s++-44||i++;i;})

```

Any symbols and literal integers may be passed. But passing literal strings containing commas will certainly mess this up.

This can probably be golfed more, but for now its a proof-of-concept.

The arg counter is declared as a char, and is thusly size-limited.

Try it online!
> 0 votes

# Answer
# Funky, 10 bytes

```
(...a)=>#a

```

Funky does this pretty well. I first tried `@#arguments`, however, `arguments` is never actually used by `@` functions, and even if, that turned out larger...

Try it online!
> 0 votes

# Answer
# C#, 32 bytes

```
int X(params int[] y)=>y.Length;

```

Expression-bodied method with the `params` keyword.
> 0 votes

# Answer
# Python 2,~~22 21~~ 15 bytes

```
lambda*a:len(a)

```

EDIT: -1 byte by removing space between "lambda" and "\*a"

Edit 2: -6 thanks to @ppperry
> 0 votes

# Answer
## , 1 byte

If I'm understanding it correctly:

```
k

```

## Why does this work?

Assume that the program is a function (the program is technically a function). In this case, you pass arguments into the function in a list like this:

```
[[item1,item2,item3]]

```

Because the main list only supports at most 4 items, we put the arguments in a sub-list of that list (just an optimization, no effect for the source code).

Also, the program technically reads that list of arguments:

```
ak

```

Then it finds the length of a list of its arguments.
> 0 votes

# Answer
# K (ngn/k), 2 bytes

```
#:

```

Try it online!

This is a lame answer, honestly.
> 0 votes

# Answer
# Fig, \\$3\log\_{256}(96)\approx\\$ 2.469 bytes

```
L#X

```

Try it online!

```
L#X
L   # Length
 #X # Of the argument list

```
> 0 votes

# Answer
# J-uby, 7 bytes

```
:>>&:+@

```

Attempt This Online!

The `:>>` operator gathers all of the arguments into an array; `:+@` returns its length.
> 0 votes

# Answer
# Pip, 2 bytes

```
#G

```

Attempt This Online!

Note that Pip's function-call syntax does not support calling a function with zero arguments, so instead I'm using the `V` operator (call function with given argument list) with an empty list for that test case.

### Explanation

All functions in Pip are variadic. The list of arguments can be accessed through the local variable `g`.

```
 G  ; Variable preset to {g}, a function that returns its argument list
#   ; Length
    ; The result is a function that returns the length of its arglist

```
> 0 votes

# Answer
# TypeScript's type system, 57 bytes

```
interface F{o:this extends{i:{}[]}?this["i"]["length"]:0}

```

Try it at the TS playground!

I'm not entirely sure if this is valid, because it's not exactly a "function" in the traditional sense, but it is very similar.

Normal TypeScript type submissions are defined with the `type` keyword, and take input via generic type parameters:

```
type Greet<T extends string> = `Hello, ${T}!`
type Something = Greet<"World">
//   ^? "Hello, World!"

```

These work as functions in most cases, but there are two main cases in which they don't suffice:

* Higher order functions - you can't pass a generic type as an argument to another generic type.
* Variadic arguments - usually this is handled by taking a list as the argument.

There is actually another way to define "functions" in TypeScript, though- one which solves both of these problems, albeit in an *extremely* hacky way:

```
interface Greet {
  o: this extends { i: [infer S extends string] } ? `Hello, ${S}!` : never
}

type Something = (Greet & { i: ["World"] })["o"]
//   ^? "Hello, World!"

```

Within the `interface`, it checks if its own type has a property `i`, and if it does, does something with that value, otherwise returning nothing.

What's very hacky about this is that when you take the intersection type of `Greet` and a record type which has a property `i`, `Greet` takes its own type to have that property.

I couldn't tell you why the TypeScript team decided to make this be the behavior, but it comes in very handy in cases like this.

Since this behavior is rarely used and almost certainly unintentional, there isn't a very common calling convention for these, but the most common one I've seen is taking either a tuple of ordered arguments from a property, or taking a record of named arguments from that property. I've opted to use the former for this submission, as it makes the problem very convenient and short.
> 0 votes

# Answer
# RProgN 2, 2 bytes

```
)L

```

Same concept as many stack based answers; collects everything on the stack into a stack, and gets its length.

Try it online!
> 0 votes

# Answer
# Python, 3 bytes

```
len

```

Attempt This Online!

Using the new community default that multiple arguments to a function can be taken as a list instead.

Named function which accepts a list of variable length and returns its size.
> -1 votes

---
Tags: code-golf, functional-programming
---


title: Interquartile Mean

text:
# Question
Title: Interquartile Mean
### Task

Given (by any means) a sorted floating point dataset, return (by any means and within 1‰ of the correct value) the interquartile mean.

### One possible algorithm

1. Discard the lowest and highest quarters of the data points.
2. Calculate the average (sum divided by count) of the remaining data points.

**Note:** If the dataset size is not evenly split-able in four, you will have to weigh the datapoints that are shared by sub-sets. See *Example evaluation 2* below.

### Example evaluation 1

Given {1, 3, 4, 5, 6, 6, 7, 7, 8, 8, 9, 38}

1. Data count is 12, so we remove lowest and highest 3 datapoints:
{~~1, 3, 4,~~ 5, 6, 6, 7, 7, 8, ~~8, 9, 38~~}
2. Average of the remaining 6 datapoints:
(5 + 6 + 6 + 7 + 7 + 8) / 6 = **6.5**

### Example evaluation 2

Given {1, 3, 5, 7, 9, 11, 13, 15, 17}

1. Count is 9, so each quarter has 2¼ datapoints:
{~~1, 2, (0.25×5),~~ (0.75×5), 7, 9, 11, (0.75×13), ~~(0.25×13), 15, 17~~}
2. Average of the remaining 4.5 datapoints:
(0.75×5 + 7 + 9 + 11 + 0.75×13) / 4.5 = **9**

# Answer
# Scilab, 8 bytes

```
trimmean

```

See the documentation. By default, `discard=50`, so the IQM is computed.

EDIT: You know, this is a trivial built-in answer, so I’m marking it as CW.
> 5 votes

# Answer
# Pyth, ~~11~~ 10 bytes

```
~~.O><lQS*4Ql~~
.OsPtc4S*4

```

Test suite.

### How it works

It quadruplicates the input list to ensure that the data count is divisible by 4.

It still needs sorting, because `*4` applies to the whole list instead of to each individual element.

Then, it splits the list into four equal parts, then takes away the first and the last part.

The remaining list is flattened and the average is taken.
> 8 votes

# Answer
# MATL, ~~12~~ 11 bytes

```
4Y"G"6L)]Ym

```

Input is a horizontal vector, with the format

```
[1, 3, 4, 5, 6, 6, 7, 7, 8, 8, 9, 38]

```

or

```
[1 3 4 5 6 6 7 7 8 8 9 38]

```

**Try it online!**

### Explanation

```
4Y"    % Input horizontal vector implicitly. Repeat each element 4 times (run-length
       % decoding). The resulting array is still sorted.
G"     % Push input, for each: repeat as many times as the input size
  6L)  %   Remove first and last elements, by applying the index "2:end-1"
]      % End for each
Ym     % Compute mean. Display implicitly

```
> 8 votes

# Answer
# Python 3, 50 bytes

```
lambda n:sum(sorted(n*4)[len(n):-len(n)])/len(n)/2

```

Ideone it!

### How it works

It is a translation of my answer in Pyth.
> 6 votes

# Answer
## Snowman, 66 bytes

```
}vg","aS:10sB;aM4aRAsOal`,4nD,`aG0AaGal`NdE`AaL1AfL:nA;alaF,nDtSsP

```

Try it online!

Uses the same algorithm as @LeakyNun's answers.

```
}         enable variables b, e, and g
vg        read a line of input into b
","aS     split on commas (in-place)
:10sB;aM  convert each element in resulting array to number ("frombase(10)-map")
4aR       repeat the array 4 times
AsO       sort the array
al        take the length and put it in e without consuming b (the array)
`,        swap b and e, then move e to g; now b=length g=array
4nD       divide b by 4 (4 was stored in e, which is why the array was moved)
,`        move the array and length/4 back to their original positions
aG        split the array into groups of length (length/4)
0AaG      take all elements with index >0 (i.e. remove the first element)
al        store the length of the new array in e again
`NdE`     bring it up to b, decrement, and put it back
AaL       take all elements with index <length-1 (i.e. remove last)
1AfL      flatten the array 1 level deep
:nA;      push a block that adds two numbers (to e)
al        store the length of this new array in g
aF        fold b over e (sum the numbers)
,         move g (the length) into e
nD        divide the sum by the length, resulting in the average
tSsP      to-string and print

```
> 6 votes

# Answer
# Jelly, ~~14~~ ~~13~~ 12 bytes

```
~~x4ṫL‘$ḣLN$S÷LH~~
~~x4ṫLḊḣLN$S÷LH~~
x4œs4ḊṖFS÷LH

```

Try it online!

Test suite.

### How it works

It is a translation of my answer in Pyth.
> 5 votes

# Answer
## Pyke, ~~16~~ 13 bytes

```
4*S4ftOsDsRl/

```

Try it here!
> 4 votes

# Answer
# Brachylog, 21 bytes

```
:3jo@4brbcLl/N,L+:N*.

```

Try it online! or verify multiple test cases

### Explanation

This is basically @LeakyNun's Pyth answer algorithm.

```
:3j      Append 3 copies of the input to itself
o@4      Sort and split in 4 lists of equal length
brb      Remove the head and the tail of the list of lists
cL       Concatenate the 2 sublists into a list L
l/N,     N is the inverse of the length of L
L+:N*.   Output is the product of N and the sum of the elements of L

```

The only small trick there is in multiplying by the inverse of the length instead of dividing by the length, because division between 2 integers is integer division.
> 4 votes

# Answer
# , ~~20~~ 18 bytes

**2 bytes thanks to @miles**

```
~~#-:@%~-@#+/@}.#}.4#]~~
-@#(+/%#)@}.#}.4#]

```

Try it online! (Online interpreter)

### Usage

```
>> f =: -@#(+/%#)@}.#}.4#]
>> f 1 3 5 7 9 11 13 15 17
<< 9

```

### How it works

It is a translation of my answer in Pyth.
> 3 votes

# Answer
# Octave, 44 bytes

```
@(x)mean(reshape(~~(1:4)'*x,[],4)(:,2:3)(:))

```

This defines an anonymous function.

The input is a horizontal vector.

**Try it on ideone**.

### Explanation

The input horizontal vector is first matrix-multiplied (`*`) by a column vector of four ones (built with `~~(1:4)'`). The result is a four-column matrix where each row is a copy of the input vector. This is then reshaped, while maintaining the linear order of the elements, into a 4-column matrix (`reshape(...,[],4)`). The center two columns are kept (`(:,2:3)`) and linearized into a single column (`(:)`), of which the mean is computed (`mean(...)`).
> 3 votes

# Answer
# Actually, ~~20~~ ~~15~~ 13 bytes

```
~~;l╗;+;+S╜@t╜τ@HΣ╜τ@/~~
~~;l;τ;a;+;+StHΣ/~~
;l;τ;aττStHΣ/

```

Try it online!

### How it works

It is a translation of my answer in Pyth.
> 2 votes

# Answer
## JavaScript (ES6), 75 bytes

```
a=>a.concat(a,a,a).sort(g=(x,y)=>x-y).slice(l=a.length,-l).reduce(g,0)/l/-2

```

Uses the obvious quadruplicate-and-sort approach, and I get to use `reduce`, which is nice. The only trickery here is to save 4 bytes by reusing the sort comparator to subtract all the array elements from zero, which gives me `-2l` times the answer I want.
> 2 votes

# Answer
## Octave, 42bytes

Another anonymous function for Octave.

```
@(x)mean([x;x;x;x](:)((b=numel(x))+1:3*b))

```

You can try it online. Simply enter that command, and then do `ans([1 2 4 5 6 9])` or whatever numbers are required.

This one starts by creating from the input array one with 4 of each input element by first concatenating four copies vertically, and then flattening it vertically. This maintains the sort order.

Then is extracts the range of elements from the length of the input array plus 1 up to three times the length of the input array. Because the new array is four times longer, this chops off the upper and lower quartiles.

Finally the mean of the new array is returned.
> 2 votes

# Answer
## 05AB1E, 15 bytes

```
€D€D¹gô¦¨˜DOsg/

```

**Explanation**

```
€D€D             # quadruple each element in list
    ¹gô          # split into pieces the size of input
       ¦¨˜       # remove the first and last and flatten the middle 2
          DOsg/  # sum and divide by length

```

Try it online
> 2 votes

# Answer
# APL (Dyalog), 15 bytes

```
IQM←(+/÷≢)≢↓-∘≢↓4∘/

```

Try it online!

`4∘/` quadruplicate each element

`-∘≢↓` drop as many trailing elements as there are elements in the arguments

`≢↓` drop as many leading elements as there are element in the argument

`(``)` apply the following tacit function:

`+/` the sum

`÷` divided by

the tally
> 2 votes

# Answer
# Golfscript, ~~28~~ 29 bytes

```
~~~.4*$\,.@/1>2<{+}*{+}*'/'@2*~~
~.4*$\,.@/1>2<{+}*{+}*\2*-1?*

```

Try it online!
> 1 votes

# Answer
## Actually, 12 bytes

```
4α;l¼≈;±(Htæ

```

Try it online! (currently doesn't work because TIO is a few versions behind)

Explanation:

```
4α;l¼≈;±(Htæ
4α            repeat each element 4 times
  ;l¼≈        length divided by 4, as integer
      ;±      copy, unary negate
        (Ht   remove first and last quartiles
           æ  mean

```
> 1 votes

# Answer
## Mathematica, 51 bytes

```
Mean@#[[(l=1+Length@#/4);;-l]]&@Sort@Join[#,#,#,#]&

```

Sorts four copies of the list (to prevent issues with list length not multiples of four), takes part `"1 quarter the length of resulting list plus 1"` through to the `"1/4 length list + 1 from the end"`, takes their `Mean`.
> 1 votes

# Answer
# Java ~~146~~ 126 Bytes

Such java much verbose!

```
float m(float[]n){float r=0;int l=n.length,i=l/4;r-=(n[i])*(l%4)/4;r+=n[i*3]*(4-(l%4))/4;for(;i<l*3/4;r+=n[i],i++);return r/l*2;}

```

## Older Ungolfed partially readable with test cases

```
/**
 *
 * @author rohan
 */
public Golf{

float m(float[]n){
//declarations
float r=0;
int x,i=0,l=n.length;
//sum the array
for(float m:n){r+=m;}
//remove the excess
for(;i<l/4;r-=n[i]+n[l-i-1],i++);
//weight the quartiles
r-=(n[l/4]+n[l*3/4])*(l%4)/4;
//return the sum/length but multiply by two since only half of the set is averaged
return r/l*2;
    }
static void interQuartileMean(float... set){
    System.out.println(new Golf().m(set));
}
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
    //test cases pass with flying colours
        interQuartileMean(1, 3, 4, 5, 6, 6, 7, 7, 8, 8, 9, 38);
        interQuartileMean(1, 3, 5, 7, 9, 11, 13, 15, 17);
    }

}

```
> 1 votes

# Answer
## R, ~~17~~ 11 bytes

```
mean(n,0.25)

```

Assuming `n` is the input vector in the standard R form `n=c(1, 2, 3, ...)`.

This is in no way surprising since R can be considered “THE language for statistical computing” and has many statistical built-ins.

*UPDATE.* Saved 6 bytes thanks to rturnbull because `trim` is the first optional argument by default!

Test cases:

```
a <- c(1, 3, 4, 5, 6, 6, 7, 7, 8, 8, 9, 38)
b <- c(1, 3, 5, 7, 9, 11, 13, 15, 17)
mean(a,trim=0.25) # Returns 6.5
mean(b,trim=0.25) # Returns 9

```
> 1 votes

# Answer
## Clojure, ~~82~~ 81 bytes

Edit: 1 byte less by re-writing "didvide by 2 n" part.

```
#(let[n(count %)](*(/ n)0.5(apply +(subvec(vec(for[i % j(range 4)]i))n(* 3 n)))))

```

Previous:

```
#(let[n(count %)](/(apply +(subvec(vec(for[i % j(range 4)]i))n(* 3 n)))(* 2.0 n)))

```

Uses `for` to generate 4 repeated values, using float `2.0` not to have fractional results, the rest is just standard.
> 1 votes

# Answer
# Excel, 17 bytes

```
=TRIMMEAN(A:A,.5)

```

Relaxed input format make this easy. Input one per row in Column A.
> 0 votes

# Answer
# Perl 5, 80 + 2 `-pa` = 82 bytes

```
map{shift@F;pop@F}1..($b=@F/4);map$_*=1-($b-=0|$b),@F[0,-1];$_=sum(@F)/(@F-2*$b)

```

Try it online!
> 0 votes

# Answer
# Awk, 68 bytes

```
{while(++i%5)p[++a]=$0}END{for(l=a/4;l<3*a/4;)s+=p[++l];print 2*s/a}

```

Try it online!
> 0 votes

# Answer
# JavaScript (Node.js), 65 bytes

```
a=>eval(a.flatMap(x=>[x,x,x,x]).slice(n=a.length,-n).join`+`)/2/n

```

Try it online!
> 0 votes

---
Tags: code-golf, math, arithmetic, set-partitions, statistics
---