Search Results
Search type | Search syntax |
---|---|
Tags | [tag] |
Exact | "words here" |
Author |
user:1234 user:me (yours) |
Score |
score:3 (3+) score:0 (none) |
Answers |
answers:3 (3+) answers:0 (none) isaccepted:yes hasaccepted:no inquestion:1234 |
Views | views:250 |
Code | code:"if (foo != bar)" |
Sections |
title:apples body:"apples oranges" |
URL | url:"*.example.com" |
Saves | in:saves |
Status |
closed:yes duplicate:no migrated:no wiki:no |
Types |
is:question is:answer |
Exclude |
-[tag] -apples |
For more details on advanced search visit our help page |
Tasks involving random numbers and/or output.
0
votes
Randomly capitalize half of a string
Python 3, 124 bytes:
import random as r
j=range
f=lambda s:(lambda v:''.join(chr(ord(s[i])-32*(i in v))for i in j(l)))(r.sample(j(l:=len(s)),l//2)) …
2
votes
Random point inside boundary
Python3, 770 bytes:
import random as U
E=enumerate
def T(b,x,y):
D={}
for i in b:D[i[x]]=D.get(i[x],[])+[i[y]]
return D
def B(b):
P=[(x,y)for x,r in E(b)for y,k in E(r)if' '! …
1
vote
Cambridge Transposition
=\w)',lambda x:''.join(r.sample(g:=x.group(),len(g))),x)
import re,random as r
Try it online! …
1
vote
Shuffle a subsequence
Python3, 142 bytes:
from random import*
r=range
def f(s):g=sample(r(l:=len(s)),randint(1,l));j=g[:];shuffle(j);return[s[j.pop(0)]if i in g else s[i]for i in r(l)]
Try it online! …
1
vote
Shuffle an array, a little bit
Python3, 178 bytes:
lambda a,k:f([*enumerate(a)],k,a,0,[])
def f(a,k,l,j,c):
if len(a)==j:yield c;return
for x,y in a:
if abs(x-j)<=k and(C:=list.count)(l,y)>C(c,y):yield from f(a,k,l,j+1,c+[y])
…
2
votes
Totally random Catan number distributions
Python 3, 391 bytes:
from random import*
R=range
P=lambda i:' '*int((9-(i*2-1))/2)
def b():
while 1:
t=[*'2C.'+'345689AB'*2];shuffle(t)
B,f=[P(i)+' '.join(t.pop(0)for _ in R(i))+P(i)for i in[3,4,5,4,3 …
2
votes
Simulate weathering of a rock
Python 3, 356 bytes
import random as r,re
y=lambda _:[' ','#'][r.choice([0,1])]
g=lambda x:[*map(''.join,zip(*[(' '*(len(x)-i.count('#')))+('#'*i.count('#'))for i in zip(*x)]))]
f=lambda x:[w:=g([re.sub …