Robin Ryder
  • Member for 2 years, 10 months
  • Last seen this week
Print 0 to 100 without 1-9 characters
Accepted answer
123 votes

R, 9 bytes F:volcano Try it online! The sequence operator : coerces its arguments to integers. F is the boolean FALSE, which gets coerced to 0. volcano is one of the many built-in datasets (it gives ...

View answer
Random point on a sphere
24 votes

R, 23 bytes x=rnorm(3) x/(x%*%x)^.5 Try it online! Generates 3 realizations of the \$\mathcal N(0,1)\$ distribution and normalizes the resulting vector. Plot of 1000 realizations:

View answer
Average of your code
23 votes

Unreadable, 111 bytes '"'""'""'""'""'""'""'""'""'""'""'""'""'""'&...

View answer
Print the last, middle and first character of your code
22 votes

Grass, 17 bytes wWWwwwVVwWWwWWWww Try it online! -2 bytes thanks to jimmy23013. Outputs www. Grass ignores all characters apart from w, W and v. The two Vs are thus ignored; they are there to ...

View answer
Demonstrate some advanced abstract algebra
Accepted answer
20 votes

Proof of impossibility The only anti-distributive operator when \$S=\mathbb Z\$ is such that \$\forall a, \forall b, a*b=0\$. Indeed, suppose that \$*\$ is anti-distributive. Then \$*\$ has the ...

View answer
Do I have a twin with permutated remainders?
20 votes

R, 63 59 bytes s=scan()%%c(2,3,5,7);i=which(s<c(0,2,3,5));any(s[i]-s[i-1]) Try it online! -4 bytes thanks to Giuseppe (The explanation contains a spoiler as to how to solve the problem without ...

View answer
Triangular code, triangular output
19 votes

R, 34 bytes # d= cat d(9^ (1:7) ,sep=" ")##### Try it online! Outputs \$9^1\$ to \$9^7\$: 9 81 729 6561 59049 531441 4782969

View answer
Tex Quotes(UVa 272)
18 votes

Unreadable, 789 777 bytes -12 bytes by using variable X34 rather than X6. '""""""'""'"""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'""'"""'"""""...

View answer
I multiply the source, you (probably) multiply the output!
16 votes

R, 66 35 bytes -29 bytes thanks to digEmAll. -2 bytes thanks to Giuseppe. +0->A x=!0:F F=F+1 sample(F*x+!x,1) Try it online! Check the distribution for N=4. The key is the rightwards ...

View answer
xkcd 2385 KoTH (Final Exam)
15 votes

Random 50-90 If the average is \$m\$, the optimal play is \$50+0.4m\$. If we assume the average is uniformly distributed over \$[0, 100]\$, the optimal play is uniformly distributed over \$[50, 90]\$. ...

View answer
1, 2, miss a few, 99, 100
14 votes

R, 43 41 bytes cat(T+F:T,"miss a few",3*33+F:T,sep=", ") Try it online! T and F are equal to TRUE and FALSE. They get coerced to integers 1 and 0 by the operators + and :.

View answer
Golf the smallest circle!
14 votes

R, 59 bytes function(x)nlm(function(y)max(Mod(x-y%*%c(1,1i))),0:1)[1:2] Try it online! Takes input as a vector of complex coordinates. Mod is the distance (modulus) in the complex plane and nlm is ...

View answer
Infinitely many ℕ
13 votes

R, 26 25 24 bytes -1 byte thanks to Dominic van Essen repeat cat(rpois(9,9)+1) Try it online! Outputs a random infinite sequence of integers, drawn from the \$Poisson(9)\$ distribution (+1 to avoid ...

View answer
Multiply or Divide by n
13 votes

Shakespeare Programming Language, 221 bytes ,.Ajax,.Puck,. Act I:.Scene I:.[Enter Ajax and Puck] Ajax:You cat. Scene V:. Puck:You is the sum ofYou a cat. Ajax:Open heart.Is I nicer you?If notYou is ...

View answer
How many of each pill to take to achieve the total daily dose
13 votes

R, 53 38 bytes function(x)c(x%/%5,2*x%%1,(x<20)*x%%5) Try it online! Output is in the order (5mg, 2.5mg, 1mg). For the 2.5mg pills: if the dose is an integer, we need 0 such pills. Indeed, 1 ...

View answer
Is it almost-prime?
13 votes

Shakespeare Programming Language, 329 bytes ,.Ajax,.Page,.Act I:.Scene I:.[Enter Ajax and Page] Ajax:Listen tothy. Page:You cat. Scene V:. Page:You is the sum ofYou a cat. Is the remainder of the ...

View answer
Approximate when you are going to die
12 votes

R, score=67.47 47.92 30 bytes, MSE = 0.54587 -1 byte (and -1.47 in score) thanks to Dominic van Essen. pnorm(scan(),31,41,F)*scan()-2 Try it online! The input format is: age as an integer, then a ...

View answer
Generate a Nine-Ball Pool rack
12 votes

R, 61 bytes cat(paste0(c(" 1 ",""," ","9 "," ",""," "),sample(2:8))) Try it online! Prints alternately the proper whitespace/newline (with 1 and 9 included) and elements of a random ...

View answer
I shift the source code, you shift the input!
12 votes

R, 82 75 67 62 bytes -4 bytes thanks to Giuseppe. !-1->i c(tail(s<-el(strsplit(scan(,""),"")),1/i),head(s,-i))#! Try it online! ry it online!T !Try it online Uses rightwards assignment -&...

View answer
Simulating Exploding Dice
12 votes

R, 39 bytes n=scan();n*rgeom(1,1-1/n)+sample(n-1,1) Try it online! Explanation: this solution avoids recursion/while loops by directly calculating the distribution of the number of explosions that ...

View answer
Converting Strings to Decimals (Gone Wrong)
11 votes

Shakespeare Programming Language, 258 252 bytes -6 bytes thanks to the default. ,.Ajax,.Puck,.Act I:.Scene I:.[Exeunt][Enter Ajax and Puck] Ajax:Open mind. Puck:Is I nicer zero?If soYou is the sum ofI ...

View answer
Antisymmetry of a Matrix
11 votes

R, 23 bytes function(m)!any(m+t(m)) Try it online! Checks whether there are any non-zero elements in \$M+M^T\$.

View answer
Create a uniquely solvable crossword ... without clues
11 votes

180 white squares My strategy was simply to find a smaller rectangle with no black squares, such that it can be filled in uniquely. All 2×k rectangles have multiple solutions. For 3×k rectangles, ...

View answer
Rotated Position of Integers
11 votes

R, 114 107 bytes -5 bytes thanks to Giuseppe. Outgolfed by digEmAll. function(l){for(j in seq(l))l[j]=rep(l[j]%/%(e=10^(b=nchar(l[j]):1-1))%%10,j+1)[j+0:b]%*%e sum(sort(l)==l)} Try it online! 0-...

View answer
Multiply or Divide by n
10 votes

R, 43 39 bytes -4 bytes thanks to Giuseppe. for(i in 1:scan())T=T%/%i^(2*(i<T)-1);T Try it online! Outputs the \$n\$th term, 1-indexed. Initializing the sequence with \$a(0)=1\$ also works, as ...

View answer
Guess my password (cops' thread)
10 votes

R, 60 bytes, cracked by Paul function(x) chartr("zyxwvu", "RRRRRR", tolower(x[1] + x[2])) Try it online! As in my previous challenge, the flag to output is the string "R&...

View answer
(RGS 4/5) Inverting matrices modulo m
10 votes

R, 68 bytes function(M,m,n,A=M){while(any(A%*%M%%m!=diag(n)))A[]=rpois(n^2,9) A} Try it online! Strikingly slow. Will most likely time out for all test cases on TIO, but is guaranteed to give an ...

View answer
Are the beams above or below the notes?
10 votes

R, 40 bytes function(x)min(x)+max(x)+mean(sign(x))<0 Try it online! If min(x)+max(x) is non-zero, its sign corresponds to the note farthest from the centre and gives the direction of the beam. ...

View answer
Find the C-factor of a vote
10 votes

R, 23 bytes function(o,v)mean(o!=v) Try it online! The challenge boils down to computing the proportion of values in v different from o (i.e. mean(xor(o,v))). We can therefore avoid using abs.

View answer
Calculate the Mean mean of two numbers
10 votes

R, 70 69 67 bytes x=scan();`?`=mean;while(x-?x)x=c((?x^2)^.5,?x,2^?log2(x),1/?1/x);?x Try it online! -1 byte with better conditioning.-2 bytes by switching to base 2. Like some other answers, this ...

View answer
1
2 3 4 5
7