Guest User

Untitled

a guest
Nov 19th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.34 KB | None | 0 0
  1. ×/¨1<⊂|⍳
  2.  
  3. ×/¨1<⊂|⍳ Right argument: h w
  4.  
  5. ⍳ Generate all index pairs (1-based) of a h×w array.
  6. ⊂ Enclose (h w), so it depth matches the one of the index array.
  7. | For each pair (i j) compute the remainders of the division by (h w).
  8. 1< Compare all remainders with 1.
  9. ×/¨ Reduce each pair of Booleans by multiplication.
  10.  
  11. 2$l3XyZ+3=
  12.  
  13. % Grab two input parameters implicitly
  14. 2$l % Create a matrix of ones that has the dimensions specified as inputs
  15. 3 % Number literal 3
  16. Xy % Create a 3x3 identity matrix
  17. Z+ % Perform 2D convolution (preserving size)
  18. 3= % Create a logical matrix where values == 3 are 1 and 0 otherwise (boundary)
  19. % Implicitly display output.
  20.  
  21. @(x)conv2(ones(x),eye(3),'s')>2
  22.  
  23. @(x)imagesc(conv2(ones(x),eye(3),'s')>8)
  24. ans([6,9])
  25.  
  26. 2$lO6Lt4$(
  27.  
  28. 2$l % Implicit inputs M, N. Generate M×N array of ones
  29. O % Push number 0
  30. 6Lt % Push [2 -1] twice, corresponding to index "2:end-1"
  31. 4$( % Fill the center of the array with value 0. Implicit display
  32.  
  33. 2$Ol6Lt4$(1YG
  34.  
  35. >> matl 2$Ol6Lt4$(1YG
  36. > 5
  37. > 7
  38.  
  39. p%€,>1P€G
  40.  
  41. p%€,>1P€sG Main link. Arguments: h (height), w (width)
  42.  
  43. p Cartesian product; return all pairs in [1, ..., h] × [1, ..., w].
  44. , Yield the pair [h, w].
  45. %€ For each pair [i, j] in the product, compute [i % h, j % w].
  46. >1 Compare all resulting moduli with 1.
  47. P€ Compute the product of each pair of Booleans.
  48. s Split the resulting flat list into rows of length w.
  49. G Display the results in a 2D grid.
  50.  
  51. julia> f(n,m)=[n>i>1<j<m for i=1:n,j=1:m]
  52. f (generic function with 1 method)
  53.  
  54. julia> f(4,4)
  55. 4x4 Array{Bool,2}:
  56. false false false false
  57. false true true false
  58. false true true false
  59. false false false false
  60.  
  61. julia> f(1,1)
  62. 1x1 Array{Bool,2}:
  63. false
  64.  
  65. julia> f(2,5)
  66. 2x5 Array{Bool,2}:
  67. false false false false false
  68. false false false false false
  69.  
  70. l~S*a*{3a.f|W%z}4*N*
  71.  
  72. l~ e# Read and evaluate input, dumping h and w on the stack.
  73. S* e# Create a string of w spaces.
  74. a* e# Create an array of h copies of that string.
  75. { e# Repeat this block 4 times...
  76. 3a.f| e# For each character in the first row, take its bitwise OR with 3, turning
  77. e# spaces into # and leaving # unchanged.
  78. W%z e# Reverse and transpose the grid, rotating it by 90 degrees.
  79. }4*
  80. N* e# Join the lines of the result with linefeeds.
  81.  
  82. jQ]Uajt%!RQt%!|
  83.  
  84. - Q = eval_input()
  85. j - j = eval_input()
  86. jQ] - [Q,j]
  87. U - create a 3d array sized Q by j with coords
  88. a - for each coord (2d for)
  89. jt%! - not (coord_1 % j-1)
  90. | - ^ or V
  91. Qt%! - not (coord_2 % Q-1)
  92.  
  93. jQ]Uajt%RQt%&
  94.  
  95. (n,m)=>Array(n).fill(' '.repeat(m).replace(/^ | $/g,0)).join`
  96. `.replace(/^.+|.+$/g,'0'.repeat(m))
  97.  
  98. d+
  99. $*
  100. S_`1(?=.* (1+))|.
  101. T`1`#`^.+|.+$|.?¶.
  102.  
  103. d+
  104. $*
  105.  
  106. S_`1(?=.* (1+))|.
  107.  
  108. T`1`#`^.+|.+$|.?¶.
  109.  
  110. ;'#*;))¬' *'#;)@+(+nXX(
  111.  
  112. ;'#*;))¬' *'#;)@+(+nXX(
  113. (implicit) push all input to stack
  114. ;'#* push a string containing X #s
  115. ;)) dupe, and push both to bottom of stack
  116. ¬' * push a string containing (X-2) spaces
  117. '#;)@+(+ add a # to the front and the back of the string
  118. nXX make (Y-2) copies
  119. ( bring one of the "#"*X strings back to the top
  120. (implicit) pop and print each stack item, separated by newlines
  121.  
  122. ->x,y{h=?#;puts t=h*x,y>1?[[h+(x<2?'':' '*(x-2)+h)]*(y-2),t]:p}
  123.  
  124. INPUT x,y
  125. FOR i=1TO y
  126. FOR j=1TO x
  127. ?i MOD y<2OR j MOD x<2;
  128. NEXT
  129. ?
  130. NEXT
  131.  
  132. ? 5,3
  133. -1 -1 -1 -1 -1
  134. -1 0 0 0 -1
  135. -1 -1 -1 -1 -1
  136.  
  137. INPUT x,y
  138. SCREEN 9
  139. FOR i=1TO y
  140. FOR j=1TO x
  141. PSET(j*3,i*3),i MOD y<2OR j MOD x<2
  142. NEXT
  143. NEXT
  144.  
  145. DECLARE @ INT=3,@y INT=5
  146.  
  147. PRINT REPLICATE(1,@)+ISNULL('
  148. '+REPLICATE('1'+ISNULL(SPACE(@-2),'')+'1
  149. ',@y-2)+REPLICATE(1,@),'')
  150.  
  151. P3G$PG@PS@S$B$T1B@T1B$T1B@
  152.  
  153. P3 Paint current square with 3
  154. G$P Get: sets $ from input P
  155. G@P Get: sets @ from input P
  156. S@ Subtract 1 from @
  157. S$ Subtract 1 from $
  158. B$ Brush $ more square[s]
  159. T1 Turn 1 right angle clockwise
  160. B@ Brush @ more square[s]
  161. T1 Turn 1 right angle clockwise
  162. B$ Brush $ more square[s]
  163. T1 Turn 1 right angle clockwise
  164. B@ Brush @ more square[s]
  165.  
  166. x0y9P3G$PG@PS@S$B$T1B@T1B$T1B@
Add Comment
Please, Sign In to add comment