Advertisement
Guest User

Untitled

a guest
Jul 17th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. 10 9 8 7 6 5 4 3 2 1
  2. 0 1 2 3 1 5 4 3 2 1
  3.  
  4. 8 18 6 11 14 3 15 10 6 19 12 3 7 5 5 19 12 12 14 5
  5. 0 0 0 3 4 3 1 2 6 9 1 3 7 5 5 3 12 12 14 5
  6.  
  7. 1
  8. 0
  9.  
  10. 1 1
  11. 0 1
  12.  
  13. f={l=_this;r=[];i=0;while{i<count l}do{r=r+[(l select i)%(i+1)];i=i+1};r}
  14.  
  15. numList = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1];
  16. hint format["%1n%2", numList, numList call f];
  17.  
  18. %J
  19.  
  20. %J
  21. J List 1 .. len(input). This is results in a list of the indexes.
  22. % Modulo.
  23.  
  24. pryr::f(x%%seq(x))
  25.  
  26. function (x)
  27. x%%seq(x)
  28.  
  29. ;ww.1I!@s%Ow;)Sow.$
  30.  
  31. ; w
  32. w .
  33. 1 I ! @ s % O w
  34. ; ) S o w . $ .
  35. . .
  36. . .
  37.  
  38. ā%
  39.  
  40. ā # Push the range(1, len(a) + 1)
  41. % # Mod each element in the input by the same one in this list
  42.  
  43. #&@@@Mod~MapIndexed~#&
  44.  
  45. tn:
  46.  
  47. +` , + + * + + + +* + * . + + .'
  48.  
  49. + Push 1. This is the initial value of the counter
  50. ` Mark label
  51. , Read number from input and push it. Gives 0 if no more input
  52. + Duplicate top of the stack
  53. + Duplicate top of the stack
  54. * Pop two numbers and push their division. Error if divisor is 0
  55. + Pop (discard) top of the stack
  56. + Swap top two numbers
  57. + Duplicate top of the stack
  58. + Push 1
  59. * Pop two numbers and push their sum. This increases the counter
  60. + Rotate stack down, to move increased counter to bottom
  61. * Pop two numbers and push their modulus
  62. . Pop a number and print it as a number
  63. + Push 10
  64. + Duplicate top of the stack
  65. . Pop a number (10) and print it as ASCII character (newline)
  66. ' If top of the stack is non-zero (it is, namely 10) go to label
  67.  
  68. l⟦₁;?↔z%ᵐ
  69.  
  70. l⟦₁ [1, ..., length(Input)]
  71. ;?↔z Zip the Input with that range
  72. %ᵐ Map mod
  73.  
  74. ®%°T
  75.  
  76. :Implicit input of array U
  77. ® :Map over the array
  78. % :Modulo of the current element
  79. °T :T (0, initially) incremented by 1
  80.  
  81. pryr::f(x%%1:sum(x|1))
  82.  
  83. zipWith(flip mod)[1..]
  84.  
  85. #~Mod~Range@Length@#&
  86.  
  87. #~Mod~Range@Tr[1^#]&
  88.  
  89. {_,,:).%}
  90.  
  91. { } e# Define block
  92. _ e# Duplicate
  93. , e# Length
  94. , e# Range, 0-based
  95. :) e# Add 1 to each entry
  96. .% e# Vectorized modulus
  97.  
  98. >:@i.@#|[
  99.  
  100. a=>a.map((x,y)=>x%++y)
  101.  
  102. {print $1%NR}
  103.  
  104. lmap l $L {puts [expr $l%[incr i]]}
  105.  
  106. (⍳⍴R)|R←⎕
  107.  
  108. a->[a[n]%n|n<-[1..#a]]
  109.  
  110. .e%bh
  111.  
  112. hk # 1-based index of (implicit) lambda variable
  113. b # element
  114. % # element mod (1-based index)
  115. .e Q # enumerated map over (implicit) input
  116.  
  117. V1R&,{v.m1+v%}&,=;
  118.  
  119. V1R&,{v.m1+v%}&,=; Implicit input from commandline args
  120. V1R Create stack2, push 1 to it, and return to stack1
  121. &, Reverse stack1
  122. {.......} Foreach loop, runs for each item in stack1
  123. v Switch to stack2
  124. .m Duplicate last item on stack and move duplicate to stack1
  125. 1+ Increment last item on stack
  126. v% Return to stack1, pop last 2 items and push modulus result
  127. &, Reverse stack1
  128. = Output stack1
  129. ; Suppress implicit output
  130.  
  131. a->{for(int i=0;i<a.length;a[i]%=++i);}
  132.  
  133. a=>{for(int i=0;i<a.Length;a[i]%=++i);}
  134.  
  135. a->{ // Method with integer-array parameter and no return-type
  136. for(int i=0;i<a.length; // Loop over the indexes of the array (0-indexed)
  137. a[i]%=++i // And replace every integer with itself mod (1+i)
  138. ); // End of loop
  139. } // End of method
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement