Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- A(0) = 0
- A(n) = A(n-1) - n if A(n-1) - n > 0 and is new, else
- A(n) = A(n-1) + n
- 0ali{_W=_I-__0<4$@#)|@I+@?+}fI1>`
- $ cjam <(echo '0ali{_W=_I-__0<4$@#)|@I+@?+}fI1>`') <<< 33
- [0 1 3 6 2 7 13 20 12 21 11 22 10 23 9 24 8 25 43 62 42 63 41 18 42 17 43 16 44 15 45 14 46]
- 0ali " Push S := [ 0 ] and read an integer N from STDIN. ";
- { }fI " For each I in [ 0 ... (N - 1) ]: ";
- _W= " X := S[-1]. ";
- _I- " Y := X - I ";
- _0< " A := (Y < 0) ";
- _ 4$@#) " B := (Y ∊ S) ";
- @I+ " Z := X + I ";
- | @? " C := (A || B) ? Z : Y ";
- + " S += [C] ";
- 1>` " Push str(S[1:]). ";
- f=->n{a=[0];(n-1).times{|i|a+=[[b=a[-1]-i-1]-a!=[]&&b>0?b:b+2*i+2]};a}
- int[]f(int n){int[]a=new int[n];a[0]=0;int i,j,k,m;for(i=0;i<n-1;){k=a[i++]-i;m=0;for(j=0;j<i;)if(k==a[j++])m=1;a[i]=m<1&k>0?k:k+2*i;}return a;}
- function s(n)a,b={1},{[0]=0}for i=1,n do k=b[i-1]-i c=k+i+i if(k>0)and(a[k]==nil)then b[i],a[k]=k,1 else b[i],a[c]=c,1 end end return b end
- function s(n)
- a,b={1},{[0]=0}
- for i=1,n do
- k=b[i-1]-i
- c=k+i+i
- if (k>0) and (a[k]==nil) then
- b[i],a[k]=k,1
- else
- b[i],a[c]=c,1
- end
- end
- return b
- end
- def f(x,t=0):
- if x:t=f(x-1);t+=2*x*(t*(t>0)in map(f,range(x)))
- return t
- G=n=>(i=>{for(r=[t=0];++i<n;)r[i]=t+=i>t|~r.indexOf(t-i)?i:-i})(0)||r
- G(11) -> 0,1,3,6,2,7,13,20,12,21,11
- m=p,=0,
- exec"p+=1;k=m[-1]-p;m+=k+2*p*(k*(k>0)in m),;"*input()
- print m
- (,1,{:~1$=~)-:^1<.^?)!!@|^{~)2*+}*+}/
- (, # push array [0 .. n-1]
- [0] # push sequence elements as [0] and reverse stack
- { # foreach element in [0 .. n-1] do:
- :m; # store current element in m and discard
- .m= # get the previous sequence element
- m)-:^ # subtract the current index from it and store in ^
- 0> # is that number greater than 0?
- .^?)! # is that number new to our sequence?
- @& # logically and both checks
- {^} # if true, push ^
- {^m)2*+} # otherwise, add the index twice and push
- if
- + # add new element to our sequence
- }/
- ` # make output pretty
- $n=Read-Host;$a=@(0);$n-=1;1..$n|%{$x=$a[-1]-$_;if($x-gt0-and!($a-like$x)){$a+=$x}else{$a+=$x+2*$_}};$a
- 0,1,3,6,2,7,13,20,12,21,11,22,10,23,9,24,8,25,43,62
- A=0;for i=1:n-1 b=A(i)-i;A(i+1)=b+2*i;if b>0&&~any(A==b) A(i+1)=b;end;end
- n=9;f
- function A=f(n)
- A=0;for i=1:n-1 b=A(i)-i;A(i+1)=b+2*i;if b>0&&~any(A==b) A(i+1)=b;end;end
- m=args[0] as int
- a=[0]
- (1..m-1).each{n->b=a[n-1];x=b-n;(x>0&!(x in a))?a[n]=x:(a[n]=b+n)}
- a.each{print "$it "}
- m = args[0] as int
- a = [0]
- (1..m-1).each { n->
- b = a[n-1]
- x = b-n
- ( x>0 & !(x in a) ) ? a[n] = x : (a[n] = b+n)
- }
- a.each{print "$it "}
- bash$ groovy Rec.groovy 14
- 0 1 3 6 2 7 13 20 12 21 11 22 10 23
- A=function(s,n,m,i){if(m==n){return(s)}else{t=i-m;if(t%in%s||t<0){t=i+m};s=c(s,t);A(s,n,m+1,t)}}
- A = function(s,n,m,i) {
- if(m==n){return(s)}
- else{
- t=i-m
- if(t%in%s||t<0){t=i+m}
- s=c(s,t)
- A(s,n,m+1,t)
- }
- }
- > An(0,34,1)
- [1] 0 1 3 6 2 7 13 20 12 21 11 22 10 23 9 24 8
- [18] 25 43 62 42 63 41 18 42 17 43 16 44 15 45 14 46 79
- int i,w,t,y;int[]F(int n){var r=new int[n--];for(;i<n;y=0){w=r[i++]-i;for(t=0;y<i&&t<1;)t=w==r[y++]?1:0;r[i]=w>0&&t<1?w:r[i-1]+i;}return r;}
- (defn f[m a](let[n(count a)b(last a)x(- b n)y(if(and(> x 0)(not(.contains a x)))x(+ b n))](if(= m n)a(f m(conj a y)))))(println(f(read-string(first *command-line-args*))[0]))
- (defn f[m a]
- (let [n (count a)
- b (last a)
- x (- b n)
- y (if (and (> x 0) (not (.contains a x))) x (+ b n)) ]
- (if (= m n) a (f m (conj a y))) ) )
- (println (f (read-string (first *command-line-args*)) [0]) )
- bash$ java -jar clojure-1.6.0.jar rec.clj 14
- [0 1 3 6 2 7 13 20 12 21 11 22 10 23]
- int a[5000000][2]={0},i,k,l;a[0][0]=0;a[0][1]=1;cin>>k;for(i=1;i<=k;i++){l=a[i-1][0];if(l-i>0&&a[l-i][1]!=1){ a[i][0]=l-i;a[l-i][1]=1;}else{ a[i][0]=l+i;a[l+i][1]=1;}cout<<a[i][0]<<endl;
- Fold[#~Append~(#[[-1]]+If[#[[-1]]>#2&&FreeQ[#,#[[-1]]-#2],-#2,#2])&,{0},Range@#]&
- Fold[#~Append~(#[[-1]]+If[#[[-1]]>#2&&FreeQ[#,#[[-1]]-#2],-#2,#2])&,{0},Range@#]&[30]
- {0,1,3,6,2,7,13,20,12,21,11,22,10,23,9,24,8,25,43,62,42,63,41,18,42,17,43,16,44,15,45}
- proc A n {lappend L [expr {$n?[set x [lindex [set L [A [expr $n-1]]] end]]>$n&&$x-$n ni$L?$x-$n:$x+$n:0}]}
Add Comment
Please, Sign In to add comment