Guest User

Untitled

a guest
Nov 17th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. A(0) = 0
  2. A(n) = A(n-1) - n if A(n-1) - n > 0 and is new, else
  3. A(n) = A(n-1) + n
  4.  
  5. 0ali{_W=_I-__0<4$@#)|@I+@?+}fI1>`
  6.  
  7. $ cjam <(echo '0ali{_W=_I-__0<4$@#)|@I+@?+}fI1>`') <<< 33
  8. [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]
  9.  
  10. 0ali " Push S := [ 0 ] and read an integer N from STDIN. ";
  11. { }fI " For each I in [ 0 ... (N - 1) ]: ";
  12. _W= " X := S[-1]. ";
  13. _I- " Y := X - I ";
  14. _0< " A := (Y < 0) ";
  15. _ 4$@#) " B := (Y ∊ S) ";
  16. @I+ " Z := X + I ";
  17. | @? " C := (A || B) ? Z : Y ";
  18. + " S += [C] ";
  19. 1>` " Push str(S[1:]). ";
  20.  
  21. f=->n{a=[0];(n-1).times{|i|a+=[[b=a[-1]-i-1]-a!=[]&&b>0?b:b+2*i+2]};a}
  22.  
  23. 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;}
  24.  
  25. 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
  26.  
  27. function s(n)
  28. a,b={1},{[0]=0}
  29. for i=1,n do
  30. k=b[i-1]-i
  31. c=k+i+i
  32. if (k>0) and (a[k]==nil) then
  33. b[i],a[k]=k,1
  34. else
  35. b[i],a[c]=c,1
  36. end
  37. end
  38. return b
  39. end
  40.  
  41. def f(x,t=0):
  42. if x:t=f(x-1);t+=2*x*(t*(t>0)in map(f,range(x)))
  43. return t
  44.  
  45. G=n=>(i=>{for(r=[t=0];++i<n;)r[i]=t+=i>t|~r.indexOf(t-i)?i:-i})(0)||r
  46.  
  47. G(11) -> 0,1,3,6,2,7,13,20,12,21,11
  48.  
  49. m=p,=0,
  50. exec"p+=1;k=m[-1]-p;m+=k+2*p*(k*(k>0)in m),;"*input()
  51. print m
  52.  
  53. (,1,{:~1$=~)-:^1<.^?)!!@|^{~)2*+}*+}/
  54.  
  55. (, # push array [0 .. n-1]
  56. [0] # push sequence elements as [0] and reverse stack
  57. { # foreach element in [0 .. n-1] do:
  58. :m; # store current element in m and discard
  59. .m= # get the previous sequence element
  60. m)-:^ # subtract the current index from it and store in ^
  61. 0> # is that number greater than 0?
  62. .^?)! # is that number new to our sequence?
  63. @& # logically and both checks
  64. {^} # if true, push ^
  65. {^m)2*+} # otherwise, add the index twice and push
  66. if
  67. + # add new element to our sequence
  68. }/
  69. ` # make output pretty
  70.  
  71. $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
  72.  
  73. 0,1,3,6,2,7,13,20,12,21,11,22,10,23,9,24,8,25,43,62
  74.  
  75. 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
  76.  
  77. n=9;f
  78.  
  79. function A=f(n)
  80. 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
  81.  
  82. m=args[0] as int
  83. a=[0]
  84. (1..m-1).each{n->b=a[n-1];x=b-n;(x>0&!(x in a))?a[n]=x:(a[n]=b+n)}
  85. a.each{print "$it "}
  86.  
  87. m = args[0] as int
  88. a = [0]
  89. (1..m-1).each { n->
  90. b = a[n-1]
  91. x = b-n
  92. ( x>0 & !(x in a) ) ? a[n] = x : (a[n] = b+n)
  93. }
  94. a.each{print "$it "}
  95.  
  96. bash$ groovy Rec.groovy 14
  97. 0 1 3 6 2 7 13 20 12 21 11 22 10 23
  98.  
  99. 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)}}
  100.  
  101. A = function(s,n,m,i) {
  102. if(m==n){return(s)}
  103. else{
  104. t=i-m
  105. if(t%in%s||t<0){t=i+m}
  106. s=c(s,t)
  107. A(s,n,m+1,t)
  108. }
  109. }
  110.  
  111. > An(0,34,1)
  112. [1] 0 1 3 6 2 7 13 20 12 21 11 22 10 23 9 24 8
  113. [18] 25 43 62 42 63 41 18 42 17 43 16 44 15 45 14 46 79
  114.  
  115. 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;}
  116.  
  117. (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]))
  118.  
  119. (defn f[m a]
  120. (let [n (count a)
  121. b (last a)
  122. x (- b n)
  123. y (if (and (> x 0) (not (.contains a x))) x (+ b n)) ]
  124. (if (= m n) a (f m (conj a y))) ) )
  125.  
  126. (println (f (read-string (first *command-line-args*)) [0]) )
  127.  
  128. bash$ java -jar clojure-1.6.0.jar rec.clj 14
  129. [0 1 3 6 2 7 13 20 12 21 11 22 10 23]
  130.  
  131. 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;
  132.  
  133. Fold[#~Append~(#[[-1]]+If[#[[-1]]>#2&&FreeQ[#,#[[-1]]-#2],-#2,#2])&,{0},Range@#]&
  134.  
  135. Fold[#~Append~(#[[-1]]+If[#[[-1]]>#2&&FreeQ[#,#[[-1]]-#2],-#2,#2])&,{0},Range@#]&[30]
  136. {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}
  137.  
  138. 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