Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Input : [5,5,5,5,5] 100
- Output : 5*5*5-5*5
- Input : [1,2,3,4,5] 0
- Output : 12-3-4-5
- fqeQvTms.ihQd^"+-*/"lth
- DECLARE @ varchar(max)= '5,5,5'
- DECLARE @a varchar(20) = '125'
- ,@ varchar(max)='';WITH D as(SELECT @a a UNION ALL SELECT STUFF(a,charindex(',',a),1,value)FROM STRING_SPLIT('*,+,./,-,',',')x,d WHERE a like'%,%')SELECT @+=a+','''+REPLACE(a,'.','')+'''),('FROM D WHERE a not like'%,%'EXEC('SELECT y FROM(values('+@+'null,null))g(x,y)WHERE x='+@b)
- DECLARE @a varchar(max)= '5,5,5'
- DECLARE @b varchar(20) = '5'
- ,@ varchar(max)=''
- ;WITH D as
- (
- SELECT @a a
- UNION ALL
- SELECT STUFF(a,charindex(',',a),1,value)
- FROM STRING_SPLIT('*,+,./,-,',',')x,d
- WHERE a like'%,%'
- )
- SELECT @+=a+','''+REPLACE(a,',','')+'''),('
- FROM D
- WHERE a not like'%,%'
- EXEC('SELECT y FROM(values('+@+'null,null))g(x,y)WHERE x='+@b)
- a=>o=>(c=[],i=c=>{for(j=0;!((c[j]?++c[j]:c[j]=1)%5);)c[j++]=0},eval(`while(eval(e=(a+'').replace(/,/g,(_,j)=>'+-*/'.charAt(c[~-j/2])))!=o)i(c);e`))
- n=length(x)-1
- k=n*2+2
- p=unique(nchoosek(repmat('*-+/',1,n),n),'rows')
- p=[p char(' '*~~p(:,1))]'
- c=char(x'*~~p(1,:))
- o=p(:,r==cellfun(@eval,mat2cell(reshape([c(:) p(:)]',k,[]),k,0|p(1,:))))
- reshape([repmat(x',size(o,2),1) o(:)]',k,[])'
- 1*2*3+4+5
- 1+2+3+4+5
- 1-2*3+4*5
- n=length(x)-1;
- p=unique(nchoosek(repmat(['*','-','+','/'],1,n),n),'rows');
- l=length(p);
- p=[p repmat(' ',l,1)]';
- c=reshape([repmat(x',l,1) p(:)]',n*2+2,[]);
- o = p(:,r == cellfun(@eval, mat2cell(c,n*2+2,ones(l,1))));
- reshape([repmat(x',size(o,2),1) o(:)]',n*2+2,[])'
- from itertools import*
- def f(n,o):print({k for k in[''.join(map(str,sum(j,())))[1:]for j in[zip(x,n)for x in product('+-*/',repeat=len(n))]]if eval(k)==o})
- def x(i,r):
- t=""
- from random import choice as c
- while True:
- for j in i:
- t+=str(j)
- if c([0,1]):t+="."+c("+-/*")
- t=t.strip("+-*/.")+"."
- v=eval(t)
- if v == r:print t
- t=""
- a=>o=>eval(`while(eval(e=(a+'').replace(/,/g,_=>'+-*/'.charAt(Math.random()*5)))!=o);e`)
Add Comment
Please, Sign In to add comment