Questions tagged «array-manipulation»

通过使用和操纵数组来解决特定问题的竞赛。

16
修剪那些分散注意力的背景!
拍照时会很烦人,但背景会损害图像的实际内容吗?我会说是的。我需要知道应该种植多少,这样我才能摆脱这个问题!但是-像往常一样-我很懒,所以我需要有人替我做... 任务与规则 给定一个表示图像的二进制矩阵,输出包含原始矩阵中所有111 s 的最小子矩阵的尺寸(宽度和高度)。甲子矩阵是从原始的矩阵相邻条目的块。等效地,它是通过重叠原始行的相邻行的子集和相邻列的子集而形成的新矩阵。 也可以将矩阵的宽度和高度作为输入。 该输入保证至少包含一个111。 您可以通过任何标准方法进行输入并提供输出,同时请注意,默认情况下,这些漏洞是禁止的。这是代码高尔夫,因此请尝试以您选择的语言可以管理的最少字节来完成任务。 例 ⎡⎣⎢⎢⎢⎢⎢⎢000000110000110010000011000100⎤⎦⎥⎥⎥⎥⎥⎥⟶⎡⎣⎢110011100011010⎤⎦⎥⟶(5,3)[000000010100011011001010000000]⟶[101001101101010]⟶(5,3)\left[\begin{matrix} \color{red}0&\color{red}0&\color{red}0&\color{red}0&\color{red}0&\color{red}0\\ \color{red}0&\color{blue}1&\color{blue}0&\color{blue}1&\color{blue}0&\color{blue}0\\ \color{red}0&\color{blue}1&\color{blue}1&\color{blue}0&\color{blue}1&\color{blue}1\\ \color{red}0&\color{blue}0&\color{blue}1&\color{blue}0&\color{blue}1&\color{blue}0\\ \color{red}0&\color{red}0&\color{red}0&\color{red}0&\color{red}0&\color{red}0\end{matrix}\right] \longrightarrow \left[\begin{matrix}1&0&1&0&0\\1&1&0&1&1\\0&1&0&1&0\end{matrix}\right]\longrightarrow(5,3) 测试用例 输入| 输出量 [[0,1,0,0,0,1,0]] ->(5,1)或(1,5) [[0,0,0,0,0],[0,1,0,1,0],[0,0,1,0,0]] ->(3,2)或(2,3) [[1,1,1,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]] ->(4,4) [[0,0,0,0,0,0],[0,1,0,1,0,1],[0,0,0,0,0,0]] ->(5,1)或(1,5) [[0,0,0,0,0],[0,1,0,1,0],[0,0,1,0,0],[0,1,0,1,0],[ 0,0,0,0,0]] ->(3,3) [[0,0,0,0,0,0],[0,1,0,1,0,0],[0,1,1,0,1,1],[0,0,1, 0,1,0],[0,0,0,0,0,0]] ->(5,3)或(3,5)

15
手动逻辑门
编写一个模拟基本逻辑门的程序。 输入:一个全大写单词,后跟2个1位二进制数字,以空格分隔,例如OR 1 0。门OR,AND,NOR,NAND,XOR,和XNOR需要。 输出:输入的逻辑门的输出将被赋予两个数字:1或0。 例子: AND 1 0成为0 XOR 0 1变得1 OR 1 1成为1 NAND 1 1成为0 这是codegolf,所以最短的代码获胜。
13 code-golf  logic-gates  hashing  code-golf  code-golf  number  array-manipulation  integer  code-golf  string  unicode  text-processing  cops-and-robbers  boggle  cops-and-robbers  boggle  code-golf  ascii-art  code-golf  word-puzzle  king-of-the-hill  python  code-golf  sequence  kolmogorov-complexity  code-golf  source-layout  code-golf  string  kolmogorov-complexity  math  number  code-golf  date  code-golf  combinatorics  recursion  game  king-of-the-hill  javascript  code-golf  array-manipulation  code-golf  radiation-hardening  self-referential  code-golf  integer  code-golf  number  code-golf  set-theory  code-golf  sequence  code-golf  string  sorting  natural-language  code-golf  decision-problem  number-theory  primes  code-golf  code-golf  ascii-art  code-challenge  array-manipulation  sorting  rubiks-cube  regular-expression  code-golf  counting  file-system  recursion  code-golf  string  kolmogorov-complexity  color  code-golf  game  code-challenge  permutations  encode  restricted-time  decode  code-golf  math  decision-problem  matrix  integer  palindrome  code-golf  matrix  statistics  king-of-the-hill  king-of-the-hill  python  card-games  code-golf  string  natural-language  code-golf  sequence  number-theory 

1
FIFO缓存异常
这是从随访挑战这一个,如果你困惑,请首先检查一出。 首先,假设为高速缓存未命中的次数,假设我们的高速缓存具有容量k并在充满时使用先进先出(FIFO)弹出方案,那么资源访问序列s就会丢失。m (s ,k )m(s,k)m(s, k)sssķkk 然后给定的比率,返回资源的访问的一个非空序列小号使得存在ķ > Ĵ与米(小号,ķ )≥ [R ⋅ 米(小号,Ĵ )。r>1r>1r > 1sssk>jk>jk > jm(s,k)≥r⋅m(s,j)m(s,k)≥r⋅m(s,j)m(s, k) \geq r \cdot m(s, j) 用简单的英语,构建一个序列资源的访问,从而有二级缓存的大小,其中较大的高速缓存有(至少)[R倍以上用于解决在高速缓存未命中小号。sssrrrsss 为一个例子,有效输出是序列(3 ,2 ,1 ,0 ,3 ,2 ,4 ,3 ,2 ,1 ,0 ,4 ),因为它会导致9个为高速缓冲存储器大小的高速缓存未3,但是10次未命中,高速缓存大小为4。r=1.1r=1.1r = 1.1(3,2,1,0,3,2,4,3,2,1,0,4)(3,2,1,0,3,2,4,3,2,1,0,4)(3, 2, 1, 0, 3, 2, 4, 3, 2, 1, 0, …

30
从原动力中恢复原动力
定义:素数幂是自然数,可以以p n的形式表示,其中p是素数,n是自然数。 任务:给定素数p n > 1,返回素数p。 测试用例: input output 9 3 16 2 343 7 2687 2687 59049 3 计分:这是代码高尔夫球。以字节为单位的最短答案将获胜。
13 code-golf  arithmetic  primes  king-of-the-hill  python  board-game  code-golf  number  subsequence  code-golf  ascii-art  code-golf  array-manipulation  decision-problem  grid  fastest-algorithm  logic-gates  logic  code-golf  cards  code-golf  rational-numbers  code-golf  math  number  sequence  code-golf  array-manipulation  integer  code-golf  number  array-manipulation  code-golf  number  sequence  decision-problem  code-golf  ascii-art  number  code-challenge  sequence  arithmetic  sorting  code-golf  date  fastest-algorithm  code-golf  string  number  random  combinatorics  code-golf  combinatorics  code-golf  ascii-art  base-conversion  code-golf  array-manipulation  code-golf  string  code-golf  string  number  arithmetic  code-golf  kolmogorov-complexity  code-golf  string  array-manipulation  json  code-golf  puzzle-solver  code-golf  binary  graph-theory  code-golf  arithmetic  haskell  code-golf  string  cipher  code-golf  code-golf  string  parsing  alphabet  code-golf  string  code-golf  ascii-art  code-golf  string  number  code-golf  string  balanced-string 

13
分组数组数据
给定一个整数矩阵a和一个非负整数i,输出的映射b,所述不同值映射在i的列a到列a谁具有在该值i列。 您可以假定该i值在半开范围内[0, num_cols(a))(或者[1, num_cols(a)]如果您选择使用基于1的索引),并且所有整数都在您的语言可表示的范围内。只要满足挑战的基本要求即可进行输入和输出(2D数组->从int到int的2D数组的映射)。只要映射清晰且一致,就不需要在输出中包含键。 例子 [[1]], 0 -> {1: [[1]]} [[3, 4, 5], [1, 4, 2], [5, 5, 5], [7, 7, 7], [1, 5, 9]], 1 -> {4: [[3, 4, 5], [1, 4, 2]], 5: [[5, 5, 5], [1, 5, 9]], 7: [[7, 7, 7]]} [[1, 2, 3, 4, 5], …

3
从数组中删除条目以对其进行排序并最大程度地增加元素总数
这个挑战是从入学考试到封闭数字网络安全课程。无论如何,它与网络安全无关,只是为了测试学生的逻辑和编码技能。 任务 编写一个程序,该程序从数组中删除条目,以便以严格的降序对其余值进行排序,并且在所有其他可能的降序中将其总和最大化。 输入输出 输入将是整数值的数组严格地大于0和所有彼此不同。您可以自由选择是从文件,命令行还是标准输入中读取输入。 输出将是输入之一的降序子数组,其总和大于任何其他可能的降序子数组。 注意: [5, 4, 3, 2]是的子数组[5, 4, 1, 3, 2],即使4和3不相邻。只是因为1弹出了。 暴力解决方案 当然,最简单的解决方案是在给定数组的所有可能组合中进行迭代,并搜索具有最大和的排序后的数组,即在Python中: import itertools def best_sum_desc_subarray(ary): best_sum_so_far = 0 best_subarray_so_far = [] for k in range(1, len(ary)): for comb in itertools.combinations(ary, k): if sum(comb) > best_sum_so_far and all(comb[j] > comb[j+1] for j in range(len(comb)-1)): best_subarray_so_far …

20
计算最佳平方矩阵
的最佳矩阵(对于这一挑战的相当窄的范围)是通过获得“拉上”从正方形矩阵和获得最大的每一对中的所述对应的行和列中的元素。 例如,给定以下矩阵: 4 5 6 1 7 2 7 3 0 您可以将其与其转置组合以得到:[[[4,5,6],[4,1,7]],[[1,7,2],[5,7,3]],[[7,3,0],[6,2,0]]]。如果压缩每对列表,则会获得以下信息:[[(4,4),(5,1),(6,7)],[(1,5),(7,7),(2,3)],[(7,6),(3,2),(0,0)]]。最后一步是获取每对中的最大值以获取最佳矩阵: 4 5 7 5 7 3 7 3 0 您的任务是输出作为输入给出的方阵的最佳矩阵。矩阵将仅包含整数。I / O可以采用任何合理的格式进行。以字节为单位的最短代码(采用UTF-8或该语言的自定义编码)获胜! 测验 [[172,29],[29,0]]-> [[172,29],[29,0]] [[4,5,6],[1,7,2],[7,3,0]]-> [[4,5,7],[5,7,3],[7,3,0 ]] [[1,2,3],[1,2,3],[1,2,3]]-> [[1,2,3],[2,2,3],[3,3,3 ]] [[4,5,-6],[0,8,-12],[-2,2,4]]-> [[4,5,-2],[5,8,2],[- 2,2,4]]

4
拉伸数组
之前我定义了粉碎数组的过程 迷恋我们从左到右读取数组。如果在某一点上我们连续遇到两个相同的元素,则将第一个删除,将第二个加倍。 例如,这是粉碎以下数组的过程 [5,2,2,4] ^ [5,2,2,4] ^ [5,2,2,4] ^ [5,4,4] ^ [5,4,4] ^ [5,8] ^ 请注意,同一元素可以折叠多次。在该示例中,2,2,4一次折叠就崩溃了8。 现在,粉碎阵列很容易,但要取消粉碎却很困难。您的任务是将一个正整数数组作为输入,并输出在重复压碎后可以形成输入的最大数组。例如,阵列[4]通过压碎形成,而压碎[2,2]又通过压碎形成[1,1,1,1]。由于我们不能有非整数值,[1,1,1,1]因此无法进一步展开,这就是我们的答案。 您将永远不会0在输入数组中收到a ,因为此类数组可以无限扩展。您也永远不会收到两个奇数彼此相邻的案件,这些案件不可能是压碎的结果。 这是代码高尔夫,因此答案将以其来源的大小(以字节为单位)进行评分,而字节越少越好。 在开始回答之前,我只想说这个挑战比看起来要困难得多。在进行过程中检查您的直觉,并确保您的答案通过了所有测试用例。 测试用例 [] -> [] [5] -> [5] [6] -> [3,3] [8] -> [1,1,1,1,1,1,1,1] [4,8] -> [1,1,1,1,1,1,1,1,1,1,2] [2,8] -> [1, 1, 1, 1, 2, 1, 1, 1, 1] [4,4] -> …

28
数组分解
给定一个正整数数组,输出这些整数的不同素数的稳定数组。换句话说,对于输入中的每个整数,按顺序获取其质数因子,对其进行排序,然后将输出中尚未存在的任何质数附加到输出中。 测试用例 [1,2,3,4,5,6,7,8,9,10] -> [2,3,5,7] [10,9,8,7,6,5,4,3,2,1] -> [2,5,3,7] [100,99,98,1,2,3,4,5] -> [2,5,3,11,7] [541,60,19,17,22] -> [541,2,3,5,19,17,11] [1,1,2,3,5,8,13,21,34,45] -> [2,3,5,13,7,17] [6,7,6,7,6,7,6,5] -> [2,3,7,5] [1] -> [] [8] -> [2] [] -> [] 输出可以是整数或字符串的数组或列表,定界输出或输出数字的有序列表的任何其他标准方式。 这是代码高尔夫球,因此最短答案以字节为单位。

26
从无序列表中找到两个整数以求和
这是Google的面试问题,请参阅此处的youtube链接。 任务: 从无序列表中找到2个整数,这些整数相加得出给定的整数。 给定一个无序的整数列表,找到2个总和为给定值的整数,打印这2个整数,并指示成功(退出0)。它们不需要是任何特定的数字(即,前2个整数加起来为正确的数字),任何与该值加起来的对都可以使用。 整数为正且大于零。 整数列表可以采用任何数据结构,包括整数文件-每行一个整数。 如果找不到整数,则指示失败(出口1)。 必须返回列表中不同位置的两个整数。(即,您不能从同一位置两次返回相同的数字) (注意:在视频中,这些不完全是要求。“采访者”多次更改了他的位置。) 例如。 sum2 8 <<EOF 1 7 4 6 5 3 8 2 EOF 打印3和5退出状态为0。请注意,在此状态下1,7,2,6还将允许结果。 sum2 8 <<EOF 1 2 3 4 由于没有可能的组合,因此返回退出状态1。4,4根据规则5,不允许。

11
将此数组变成矩阵
将非嵌套数组作为输入。使用以下方法将其转换为矩阵: 假设我的数组是 [1, 2, 3, 4, 5] 首先,我将该数组重复5次:(长度) [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 2, 3, 4, 5]] 然后,我沿对角线阅读: [[1], [2, 1], [3, 2, 1], [4, 3, 2, 1], [5, 4, 3, 2, 1], [5, …

11
解释松散范围
解释松散范围 ListSharp是一种解释型编程语言,具有许多功能,其中一个功能是基于1索引的范围创建器,其工作方式如下: 您可以将范围定义为(INT) TO (INT)或仅定义(INT)两个int可以从min到max int32值的范围 然后,您可以使用这些范围来提取数组的元素,而不必担心会超出其边界 因此: 1 TO 5 产生: {1,2,3,4,5} 3 产生: {3} 范围可以使用AND运算符相加 1 TO 5 AND 3 TO 6 产生: {1,2,3,4,5,3,4,5,6} 记住这也适用于负数 3 TO -3 产生: {3,2,1,0,-1,-2,-3} 挑战如下: 输入值 字符数组和先前定义的range子句作为字符串 输出量 范围中基于1索引位置的元素(不存在/负索引会转换为空字符) 如何取胜 作为代码高尔夫球挑战,您应该创建具有最少字节数的程序以获胜 有人指出不存在空字符,因此您应该忽略它们(我仅在此处显示它们是为了使它们更易于理解,但却使人感到困惑) 测试用例: input array is: {'H','e','l','l','o',' ','W','o','r','l','d'} range clause: "1 TO …
13 code-golf  array-manipulation  parsing  code-golf  string  ascii-art  kolmogorov-complexity  code-challenge  code-golf  sequence  code-golf  number  array-manipulation  sorting  code-golf  string  function  code-golf  arithmetic  code-golf  math  sequence  number-theory  primes  restricted-source  javascript  code-challenge  polyglot  rosetta-stone  code-golf  code-golf  regular-expression  code-golf  math  code-golf  math  primes  code-golf  ascii-art  kolmogorov-complexity  binary  code-golf  math  sequence  code-golf  sequence  subsequence  code-golf  string  code-golf  parsing  music  code-golf  grid  game  path-finding  board-game  code-golf  string  binary  code-golf  array-manipulation  balanced-string  code-golf  code-golf  algorithm  code-golf  string  number  arithmetic  array-manipulation  code-golf  array-manipulation  binary-tree  tree-traversal  code-golf  code-golf  tips  code-golf  string  base-conversion  code-golf  tips  s.i.l.o.s  code-golf  string  ascii-art  code-golf  code-challenge  code-golf  game 

13
斐波那契产品
您可以将大于0的数字分解为正Fibonacci数字的唯一和。在这个问题中,我们通过重复减去最大可能的正斐波那契数来做到这一点。例如: 1 = 1 2 = 2 3 = 3 4 = 3 + 1 12 = 8 + 3 + 1 13 = 13 100 = 89 + 8 + 3 现在,我将斐波那契乘积称为与上面相同的列表,但加法运算被乘积代替。例如,f(100) = 89 * 8 * 3 = 2136。 编写一个给定正整数n的程序或函数,该函数将返回该数字的斐波那契乘积。 测试用例: 1: 1 2: 2 3: 3 4: …
13 code-golf  math  sequence  fibonacci  code-golf  word  code-golf  cipher  code-golf  string  math  subsequence  code-golf  regular-expression  code-golf  brainfuck  assembly  machine-code  x86-family  code-golf  math  factorial  code-golf  math  geometry  code-golf  math  arithmetic  array-manipulation  math  number  optimization  stack  metagolf  code-golf  tips  assembly  code-golf  tips  lisp  code-golf  number-theory  path-finding  code-golf  number  sequence  generation  code-golf  math  geometry  code-golf  grid  permutations  code-golf  code-golf  graphical-output  geometry  fractal  knot-theory  code-golf  math  arithmetic  code-golf  interpreter  balanced-string  stack  brain-flak  code-golf  math  set-theory  code-golf  math  array-manipulation  code-golf  code-golf  string  natural-language  code-golf  code-golf  math  linear-algebra  matrix  code-golf  string  encode 

21
遍历数组
我们大家经常听到“遍历数组”这个成语的意思是“将函数映射到以下数组”。不过,我需要它做(现在!),所以我希望你能运行通过数组。 我该如何跑步? 想象在你身后有一群野狼 在数组中运行就像遍历一个数组,只是可以跳过元素。是的,有时会很混乱,但是(通常)可以正常工作。您可能会问:“跳过了哪些元素?”。好吧,这是随机完成的。让我们逐步遍历整个数组! 让e是当前元素。 让我们在中random生成一个随机浮点数[0,1)。如果是random() < 0.5,则转到下一个元素,然后转到步骤1。(您可以通过其他方式生成数字,只要它们是(理想情况下)跳过和保留的机会相等即可。例如,您可以使用从一个元素中选择一个元素两人一组,并根据结果执行操作。) 否则,您将在f上执行功能e。 目的 给定一个数组或列表/字符串(如A和)和一个数字K,遍历该数组,并添加K到所访问的每个成员中。输出/返回该数组。A将仅包含非负整数,并且K将永远是非负整数。这是一个代码高尔夫球,因此以字节为单位的最短程序获胜。 测试用例(示例) K, A => possible K' [1, 2, 3, 4], 0 => [1, 2, 3, 4] [1, 2, 3, 4], 1 => [1, 3, 3, 5] [0, 0, 0, 0], 2 => [2, 0, 0, 2]

6
谁是比赛的王者?
背景 考虑一个循环锦标赛,其中每个参赛者与其他参赛者进行一场比赛。没有平局,因此每场比赛都有赢家和输家。如果对其他每位竞争者B来说,A击败B或A击败另一位竞争者C,而竞争者C又击败B,那么竞争者A是比赛的王者。可以证明,每场比赛都有至少一位国王(尽管可能有几位)。在这个挑战中,您的任务是找到给定锦标赛的国王。 输入输出 您输入的是N × N布尔矩阵T,还可以N ≥ 2是参赛者人数。每个条目T[i][j]代表选手之间的比赛的胜负i和j,值为1代表一胜i0一胜j。请注意,T[i][j] == 1-T[j][i]如果i != j。的对角线T包括0。 您的输出应为T代表比赛的国王列表,使用基于0或基于1的索引。国王的顺序无关紧要,但不应重复。 输入和输出都可以采用任何合理的格式。 规则和计分 您可以编写完整的程序或函数。最低字节数获胜,并且不允许出现标准漏洞。 测试用例 这些测试用例使用基于0的索引。对于基于1的索引,增加每个输出值。 2 [[0,0],[1,0]] -> [1] 3 [[0,1,0],[0,0,0],[1,1,0]] -> [2] 3 [[0,1,0],[0,0,1],[1,0,0]] -> [0,1,2] 4 [[0,1,1,1],[0,0,1,0],[0,0,0,0],[0,1,1,0]] -> [0] 4 [[0,1,1,0],[0,0,1,0],[0,0,0,1],[1,1,0,0]] -> [0,2,3] 5 [[0,1,0,0,1],[0,0,0,0,1],[1,1,0,0,0],[1,1,1,0,1],[0,0,1,0,0]] -> [3] 5 [[0,1,0,1,0],[0,0,1,1,1],[1,0,0,0,0],[0,0,1,0,1],[1,0,1,0,0]] -> [0,1,4] 5 [[0,0,0,0,0],[1,0,1,1,0],[1,0,0,0,1],[1,0,1,0,1],[1,1,0,0,0]] -> [1,3,4] …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.