Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. $~#~
  2.  
  3. $~#~ Input: integer n
  4. #~ Create n copies of n
  5. $~ Shape n into an array with dimensions n copies of n
  6.  
  7. (t=Table)@@t[#,#+1]&
  8.  
  9. (* or *)
  10.  
  11. Table@@Table[#,#+1]&
  12.  
  13. @(N)ones(N+!(1:N))*N
  14.  
  15. @(N)ones(N*ones(1,N))*N
  16.  
  17. @(N)repmat(N,N*ones(1,N))
  18.  
  19. @(N)ones(num2cell(!(1:N)+N){:})*N
  20.  
  21. @(N)repmat(N,num2cell(!(1:N)+N){:})
  22.  
  23. n#0=show n
  24. n#l='[':tail((',':)=<<n#(l-1)<$[1..n])++"]"
  25. f n=n#n
  26.  
  27. n#l= n with the current level l is
  28. '[': a literal [ followed by
  29. n#(l-1)<$[1..n] n copies of n # (l-1)
  30. (',':)=<< each prepended by a , and flattened into a single list
  31. tail and the first , removed
  32. ++"]" followed by a literal ]
  33.  
  34. n#0=show n the base case is n as a string
  35.  
  36. f n=n#n main function, start with level n
  37.  
  38. n=scan();array(n,rep(n,n))
  39.  
  40. DF¹.D)
  41.  
  42. D # Duplicate the input (this leaves the input on the stack after the next command
  43. F # For 0 .. input
  44. ¹.D) # Push <input> copies of the result of the last step as an array
  45.  
  46. Object c(int n,int i){Object[]a=new Object[n];for(int j=0;j<n;)a[j++]=i<2?n:c(n,i-1);return a;}
  47.  
  48. public class N_Dim {
  49.  
  50. public static Object create(int n) {
  51. return create(n, n);
  52. }
  53.  
  54. public static Object create(int n, int i) {
  55. Object[] array = new Object[n];
  56. for(int j=0;j<n;j++) {
  57. array[j] = i<2?n:create(n, i - 1);
  58. }
  59. return array;
  60. }
  61.  
  62. public static void main(String[] args) {
  63. System.out.println(Arrays.deepToString((Object[]) create(3)));
  64. }
  65.  
  66. }
  67.  
  68. ri:X{aX*}X*p
  69.  
  70. ri:X Read an integer from input, store it in X (leaves it on the stack)
  71. { }X* Execute this block X times:
  72. a Wrap the top of stack in an array
  73. X* Repeat the array X times
  74. p Print nicely
  75.  
  76. ttY"l$l*
  77.  
  78. % Implicitly grab the input (N)
  79. tt % Make two copies of N
  80. Y" % Perform run-length decoding to create N copies of N
  81. l$1 % Create a matrix of ones that is this size
  82. * % Multiply this matrix of ones by N
  83. % Implicitly display the result
  84.  
  85. Wẋ³µ¡
  86.  
  87. Implicit input: N
  88. µ¡ Apply N times to input:
  89. Wẋ³ “N copies of”
  90.  
  91. ⁾Wẋẋv
  92.  
  93. ⁾Wẋẋv - Main link: n e.g. 3
  94. ⁾Wẋ - character pair literal ['W','ẋ'] "Wẋ"
  95. ẋ - repeat list n times "WẋWẋWẋ"
  96. v - evaluate as Jelly code with input n eval("WẋWẋWẋ", 3)
  97. - ...
  98. WẋWẋ... - toEval: n e.g. 3
  99. W - wrap [3]
  100. ẋ - repeat list n times [3,3,3]
  101. Wẋ - wrap and repeat [[3,3,3],[3,3,3],[3,3,3]]
  102. ... - n times total [[[3,3,3],[3,3,3],[3,3,3]],[[3,3,3],[3,3,3],[3,3,3]],[[3,3,3],[3,3,3],[3,3,3]]]
  103.  
  104. f=(n,m=n)=>m?Array(n).fill(f(n,m-1)):n
  105.  
  106. f=(n,m=n)=>m?[...Array(n)].map(_=>f(n,m-1)):n
  107.  
  108. ->n{eval'['*n+'n'+']*n'*n}
  109.  
  110. for(;$i++<$n=$argv[1];)$F=array_fill(0,$n,$F?:$n);print_r($F);
  111.  
  112. #(nth(iterate(fn[a](repeat % a))%)%)
  113.  
  114. func[n][array/initial append/dup copy[]n n n]
  115.  
  116. @set t=.
  117. @for /l %%i in (2,1,%1)do @call set t=%%t%%,.
  118. @set s=%1
  119. @for /l %%i in (1,1,%1)do @call call set s=[%%%%t:.=%%s%%%%%%]
  120. @echo %s%
  121.  
  122. (defmacro r[n]`(->> ~n ~@(repeat n`(repeat ~n))))
  123.  
  124. ->a{(z=a).times{z=[z]*a};z}
  125.  
  126. my $x=prompt(0);my @a=$x xx$x;"@a=[@a] xx $x;".EVAL xx$x-1;
  127.  
  128. (#(...) {input_no})
  129.  
  130. (((3 3 3) (3 3 3) (3 3 3)) ((3 3 3) (3 3 3) (3 3 3)) ((3 3 3) (3 3 3) (3 3 3)))
  131.  
  132. def f(x):
  133. r=[x for _ in range(x)]
  134. for _ in range(x-1):r=[r for _ in range(x)]
  135. print(r)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement