PieCot
  • Member for 6 years
  • Last seen this week
Print a 10 by 10 grid of asterisks
16 votes

MATLAB, 14 bytes repmat('*',10)

View answer
Find the Cross Product
11 votes

LISP, 128 122 bytes Hi! This is my code: (defmacro D(x y)`(list(*(cadr,x)(caddr,y))(*(caddr,x)(car,y))(*(car,x)(cadr,y))))(defun c(a b)(mapcar #'- (D a b)(D b a))) I know that it isn't the shortest ...

View answer
Where's Blackhat?
8 votes

Matlab, 87,5% function hat=is_blackhat_here2(filepath) img_hsv = rgb2hsv(imread(filepath)); img_v = img_hsv(:,:,3); bw = imdilate(imerode( ~im2bw(img_v), strel('disk', 4, 8)), strel('disk', 4, 8)); ...

View answer
Enklactify these strings
8 votes

Python3, 59 bytes lambda l:{len({*d}):''.join(d)for d in zip(*l)}.get(len(l)) Returns a string with the enklact, None otherwise

View answer
Add comments to a Python script and make it a bilingual Python/C++ “program”
5 votes

Score 136 Only for the records: #include <cstdio> #define def class a{public #define greet() #define print(a) };int main(){puts(a);} Another (less efficient) way to handle the colon.

View answer
Generate a "GitHub" Avatar
4 votes

MATLAB, 102 bytes Hi, this is my matlab solution: p=@(x)(imwrite(floor(randi(2,5,2)*[eye(2) ones(2,1)./2 fliplr(eye(2))]),[0.9412*[1 1 1];rand(1,3)],x)) The input x of the function is the name of ...

View answer
Choose Scenes for a Movie
Accepted answer
4 votes

MATLAB, 100 bytes function X=o(m,s) X=find(bintprog(-1*s(:,3),[s(:,2)';s(:,1)';-1*s(:,1)'],[m(2);m(1)+5;5-m(1)])==1); The Binary Optimization problem is solved through the bintprog function, ...

View answer
Calculate the sum of all odd digits of pi in range
3 votes

Python3, 346 bytes Based on a recursive implementation of the Chudnovsky algorithm, one of the fastest algorithms to estimate pi. For each iteration, roughly 14 digits are estimated (take a look here ...

View answer
Pleasanortmanteaus
3 votes

Python 3, 156 150 bytes I've considered y as a consonant. lambda a,b:{a[:i]+b[j:]for i in range(1,len(a))for j in range(1,len(b))if((a[i-1]in'aeiou')^(b[j]in'aeiou'))*0**(a in a[:i]+b[j:]or b in a[:...

View answer
Pair and sort from two integer lists
Accepted answer
3 votes

Python O(mn log mn) The best pairs can be found computing the distances of all the possible pairs, and iteratively choosing the best pair among those remaining after filtering out the already chosen ...

View answer
Fastest yes in the west
2 votes

Rust, 49 48 bytes \$\times\,\frac{32186368}{744521728}\approx2.075\$ Plain Rust, compiled with -C target-cpu=native -C opt-level=3. Clearly not the winner, only for reference; not bad, btw :) fn ...

View answer
"DDoouubbllee ssppeeaakk!!"
2 votes

Octave, 32 25 bytes @(x)char(kron(x+0,[1,1])) Try it online! -7 bytes thanks to Giuseppe

View answer
"DDoouubbllee ssppeeaakk!!"
2 votes

Matlab >= r2015a, 16 bytes @(x)repelem(x,2) Credits to Giuseppe Note: I haven't found an online interpreter for MATLAB; this answer correctly works with MATLAB r2015a. Matlab <= r2014b, 23 ...

View answer
Nth subset of a set
2 votes

MATLAB/Octave, 31 29 27 bytes @(n)9-find(dec2bin(n,8)-48) reduced of 2 bytes thanks to alephalpha reduced of 2 bytes thanks to Giuseppe Try it online!

View answer
Last digit large number
2 votes

Python 3, 55 bytes p=lambda l,i=-1:not l or f'{l[0]**int(p(l[1:],0))}'[i:] Older versions p=lambda l,i=-1:len(l)and f'{l[0]**int(p(l[1:],0))}'[i:]or 1 (60 bytes)

View answer
Find the nth decimal of pi
2 votes

Python 3, 338 bytes This implementation is based on the Chudnovsky algorithm, one of the fastest algorithms to estimate pi. For each iteration, roughly 14 digits are estimated (take a look here for ...

View answer
How many bytes is it
2 votes

Python3, 90 bytes (76 70 bytes 3-most-significant-digits version) h=lambda v,u=0:v>999.4and h(v/1024,u+2)or"%.*f%sB"%(u and(v<10)+(v<100),v,"KiMiGi"[u-2:u]) Version whose outputs are ...

View answer
This is my pillow
2 votes

MATLAB, 58 44 bytes Thanks to @Stewie Griffin for saving a bunch of bytes ;) [repmat(kron(['/\';'\/'],ones(4,5)),3,6),''] Old version: p=@()char(47+45*kron(ones(3,6),kron([0 1;1 0],ones(4,5))))

View answer
Do X without Y​
2 votes

MATLAB, 86 bytes a=@(n)(char(changem(randi(92,n),33+[0:55 57:87 89:93],1:92).*(eye(n)|fliplr(eye(n))))) Some examples: >> a(1) ans = i >> a(3) ans = ~ { Z * ^ >>a(5) ans =...

View answer
The Doughnut Shop™
Accepted answer
2 votes

MATLAB, 231 bytes Here a matlab solution: function g=z(r,q,s,p);[x,y]=meshgrid(1:2*r,1:2*r);d=(x-r).^2+(y-r).^2;h=size(d);e=zeros(h);e(d<r^2 & d>=q^2)=1;f=bwperim(e,4);k=rand(h);j=numel(s);...

View answer
Print invisible text
1 votes

Octave / Matlab, 25 23 bytes @(x)repmat(' ',size(x)) Saved 2 bytes thanks to Giuseppe Try it online!

View answer
Integer Linear Programming
1 votes

Matlab, 226 bytes DISCLAIMER: Not an "original" implementation, only for fun. Simple solution taking advantage of the intlinprog function: function r=f(a);b=-1*a(1:end-1,end);p=a(end,1:end-1);c=a(1:...

View answer
set intersection of two lists
1 votes

Python3, 51 bytes lambda a,b:[v for v in a if{n:1 for n in b}.get(v)] If the input lists can contain duplicates: Python3, 67 bytes lambda a,b:list({v:1 for v in a if {n:1 for n in b}.get(v)}.keys()...

View answer
Atbash Self Palindromes
1 votes

MATLAB, 61 bytes Not the shortest solution, but still interesting f=@(a)~any(changem(upper(a),90:-1:65,65:90)-fliplr(upper(a)))

View answer
Merge two sorted lists
1 votes

LISP, 117 bytes The algorithm ends in n + 1 iterations, where n is the length of the shortest list in input. (defun o(a b)(let((c(car a))(d(car b)))(if(null a)b(if(null b)a(if(< c d)(cons c(o(cdr ...

View answer
Block-diagonal matrix from columns
1 votes

MATLAB, 69 68 bytes function h=d(a) [r,c]=size(a);h=repmat(a,c,1).*kron(eye(c),~~(1:r)') One byte was shaved off: thanks to Luis Mendo :)

View answer
Maximise the squared difference
1 votes

LISP, 86 bytes (defun g(n m)(if(= n m)(list n)(if(< m n)(cons m(reverse(cons n(g(- n 1)(+ m 1)))))))) The inputs of the function allow to choose the start (m) and the end (n) values of the ...

View answer
Find the largest and the smallest number in an array
0 votes

Python 3, 54 bytes Another Python solution: the mandatory solution using lambda was missing :) lambda y:[f(e for e in y if e*0==0)for f in (min,max)] Try it online! -10 bytes thanks to aeh5040

View answer
Roll the carpet
0 votes

MATLAB / Octave, 154 bytes Not the shortest one, but to golf in MATLAB/Octave is always fun :) function h=r(t,h);n=fliplr(h');s=size(n,2);q=numel(t);if s<=q h=r(t(max(s,1)+1:end),[n; t(1:max(s,1))...

View answer
Roll the carpet
0 votes

Python 3, 112 bytes r=lambda t,h=[[]]:len(h)>len(t)and h[:-1]+[h[-1]+list(t)]or r(t[len(h):],list(zip(*h[::-1]))+[list(t)[:len(h)]]) In this case, the output is the value of the function. Try it ...

View answer