Questions tagged «array-manipulation»

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

4
获取吸气剂
任务 我想每个人都喜欢自动代码生成并节省工作时间。您白天必须创建许多类和成员,而又不想getters手动创建所有这些类和成员。 任务是编写一个程序或函数,该程序或函数getters将为您自动为所有类成员生成。 输入 在我们的语言中,对象非常简单。类和成员的名称必须以字符开头,[a-zA-Z]并且只能包含字符[a-zA-Z0-9]。这是一个例子: class Stack { public overflow; protected trace; private errorReport; } 输出 这是基于给定示例的有效输出: class Stack { public overflow; protected trace; private errorReport; public function getOverflow() { return this->overflow; } public function getTrace() { return this->trace; } public function getErrorReport() { return this->errorReport; } } 吸气剂 getter方法的要求是: …
13 code-golf  string  syntax  code-golf  math  primes  rational-numbers  code-golf  graphical-output  image-processing  code-golf  kolmogorov-complexity  music  audio  code-golf  string  code-golf  math  geometry  code-golf  math  sequence  combinatorics  code-golf  game  grid  board-game  code-golf  restricted-source  array-manipulation  source-layout  code-golf  base-conversion  binary  code-golf  math  physics  code-golf  math  number  date  expression-building  code-golf  array-manipulation  graph-theory  decision-problem  popularity-contest  error-correction  code-golf  kolmogorov-complexity  geometry  grid  code-challenge  arithmetic  combinatorics  set-partitions  code-golf  kolmogorov-complexity  sequence  fibonacci  code-golf  restricted-source  pristine-programming  code-golf  code-golf  string  kolmogorov-complexity  code-golf  arithmetic  code-golf  string  parsing  code-golf  code-golf  sorting  counting  permutations  3d  code-golf  code-golf  ascii-art  music  code-golf  string  code-golf  string  ascii-art  code-golf  string  code-golf  quine  polyglot  code-golf  math  string  code-golf  internet 

3
Brainfuck中的按位运算符
您的任务是为以下每个二进制运算符创建一个Brainfuck程序。每个程序应从输入中获取一个或两个8位数字(A和B)并计算指定的运算: A XOR B A AND B A OR B A Shifted Left by 1 (circular shift) NOT A 您不必全部实施5。得分的计算方式为: #totalCharacters + {4000 * #problemsNotCompleted} 因此,有效分数是从零(最佳)到20,000(未完成)。 我不在乎您将结果存储在哪里,也不管您是否保留输入。假设8位单元以及仅在右侧需要的空单元数。 您可能会认为数字已经在最适合您的任何内存位置中,因此您无需担心IO操作。
13 code-golf  binary  brainfuck  code-golf  code-golf  ascii-art  random  code-golf  code-golf  code-challenge  sorting  code-golf  code-challenge  java  code-golf  statistics  code-golf  code-challenge  fastest-code  code-golf  math  code-golf  math  kolmogorov-complexity  code-golf  code-golf  array-manipulation  combinatorics  code-golf  kolmogorov-complexity  popularity-contest  underhanded  code-golf  math  floating-point  code-golf  interpreter  code-golf  music  code-golf  code-golf  cryptography  code-challenge  scrabble  code-golf  code-challenge  popularity-contest  quine  code-golf  quine  cryptography  code-golf  kolmogorov-complexity  code-golf  printable-ascii  code-golf  chess  code-golf  math  number-theory  code-challenge  c  code-golf  random  popularity-contest  hello-world  code-shuffleboard  code-golf  compression  grammars  code-golf  tips  code-golf  sequence  code-golf  string  code-challenge  sorting  permutations  code-golf  string  code-challenge  optimization  code-golf  interpreter  code-challenge  string  code-golf  math  number  fibonacci  string  compression  c#  code-golf  chemistry  popularity-contest  math  c  c++  java  code-golf  math  function  code-golf  complex-numbers  code-golf  geometry 

13
计算连续的子矩阵
从聊天迁移 给定两个非空非负整数矩阵甲和乙,回答的次数甲出现作为连续的,可能重叠,子矩阵在乙。 范例/规则 0.可能没有任何子矩阵 答: [[3,1], [1,4]] B: [[1,4], [3,1]] 回答: 0 1.子矩阵必须是连续的 答: [[1,4], [3,1]] B: [[3,1,4,0,5], [6,3,1,0,4], [5,6,3,0,1]] 答:( 1以粗体显示) 2.子矩阵可能重叠 答: [[1,4], [3,1]] B: [[3,1,4,5], [6,3,1,4], [5,6,3,1]] 答:( 2分别以粗体和斜体标出) 3.(子)矩阵的大小可能为1-by-1或更大 答: [[3]] B: [[3,1,4,5], [6,3,1,4], [5,6,3,1]] 答:( 3以粗体显示) 4.矩阵可以是任何形状 答: [[3,1,3]] [[3,1,3,1,3,1,3,1,3]] 答:( 4两个粗体,两个斜体)

6
确定最宽的山谷
想象一下,我们得到了一些山区的一片,这将导致类似于以下的形状: 4 _ 3 _ _ __/ \ 2 / \__/ \ _/ \_ / 1 / \ / \_/ 0 \/ 12322223210012233343221112 如我们所见,我们可以(在一定程度上)用整数序列表示这一点。 出于此挑战的目的,我们将山谷定义为一个连续的子序列,在该子序列中,值最初是减小的,从某个点开始它们是增大的。更正式地为一个序列(一个一世)ñ我= 1(ai)i=1n(a_i)_{i=1}^n的波谷将指数1 ≤ 小号&lt; ř &lt; 吨≤ Ñ1≤s&lt;r&lt;t≤n1 \leq s < r < t \leq n的量,下式成立: 山谷的起点和终点相同:一个s= 一个Ťas=ata_s = a_t 谷开始和结束一次的区域变得更低:一个s&gt; 一个s + 1∧ 一t − …

11
查找整数数组之间的最小成本匹配
考虑两个分别为整数和且的整数和的排序数组。例如,。ÿ 米Ñ 米&lt; Ñ X = (1 ,4 )ÿ = (2 ,10 ,11 )XXXÿYY米mmñnnm &lt; nm&lt;nm < nX= (1 ,4 )X=(1,4) X = (1,4)ÿ= (2 ,10 ,11 )Y=(2,10,11)Y = (2,10,11) 我们说一个匹配配对的每个元素的一些方法使用的元素以这样一种方式,没有两个元素都具有相同的元素配对 。匹配的成本只是对中差异的绝对值之和。Y X YXXXÿYYXXXÿYY 例如,使用,我们可以制作成对的对其成本为。如果我们将成对则成本将为。如果我们将成对则成本将为。ÿ = (2 ,10 ,11 )(7 ,2 ),(11 ,10 )5 + 1 = 6 (7 ,10 …

3
优化我的消零器
我是《爬行者世界》游戏的忠实粉丝,尤其是续集。您无需知道该游戏如何回答问题,我只想提及我的问题源自何处。 在游戏中,您的目标是使用被称为“消音器”的武器消灭正在产生爬行者的发射器。 消零器可以破坏该半径范围内的任何发射器: eee eeeee eenee eeeee eee 每个无效器可以针对多个发射器。 你的目标 给定一个模拟2D映射的数组,该映射由空无和带有您想要的任何字符的发射器组成,可以是空格,e或数字-只需确保它们是可区分的,输出具有最佳数量的nullifiers n(或您想要的内容)的同一映射)放置,以便使用最少数量的无效符销毁发射器。 如果有多种最佳方式可以做到这一点,那么只输出一种就可以了。但是,如果任务无法解决,例如说发射器太多,没有布局会碰到所有发射器,则必须输出明显不同的东西,null就足够了 快速规则: 输入:多维数组 输入将包含两个字符,分别表示无意义和发射器,包括答案中的内容 输出:多维数组 输出将包含三个字符,表示无,发射器和无效器,或者如果输入不可解决则为可区分的输出 您只能用无效符替换无字符 无效符可以击中多个发射器,并且始终击中范围内的所有 无效词可以击中上面指定的区域,并且将始终击中它可以瞄准的所有发射器 以字节为单位的最短答案获胜 禁止出现标准漏洞 例子 输入: [[ , ,e, , ], [ , , , , ], [e, , , ,e], [ , , , , ], [ , ,e, , …

15
交替数字
考虑正整数数组: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ... 然后,将它们串联: 1234567891011121314151617181920212223242526... 然后将它们分成可变长度的块,每个长度等于第N个正整数: [1][23][456][7891][01112][131415][1617181][92021222][324252627][2829303132] ... --------------------------------------------------------------------------- 1 2 3 4 5 6 7 8 9 10 ... 任务 给定整数N(对于1索引为正数或对于0索引为非负数),您的任务是输出第N个块中的数字增量(和连续数字之间的差)。 默认情况下禁止使用漏洞。 适用标准输入和输出方法。 您可以为N选择0或1索引。 序列必须以1开始。 这是代码高尔夫球,以字节为单位的最短代码获胜。 范例与测试案例 1个索引的测试用例。如果您希望索引为0,则只需将N减1。 N, Chunk, Deltas, Sum 1 -&gt; 1 -&gt; [] …

13
像青蛙一样跳!
给定非负整数数组,您的任务是仅保留其某些元素,如下所述。 假设数组为[1, 3, 2, 4, 11, 5, 2, 0, 13, 10, 1]。 首先获取数组的第一个元素n。保留第一个n元素并丢弃下一个元素(丢弃n+1th)。新数组为[1, 2, 4, 11, 5, 2, 0, 13, 10, 1]。 然后,您在删除的元素后面抓取元素,并执行完全相同的操作。重新应用该过程,我们得到[1, 2, 11, 5, 2, 0, 13, 10, 1] 重复此过程,直到到达数组范围之外/数组中没有剩余元素。我们停止,因为11它大于数组的长度。 现在,您应该输出结果。 输入/输出可以任何标准形式获取/提供。该数组永远不会为空,并且将仅包含非负整数。禁止所有标准漏洞。 这是代码高尔夫球,因此以字节为单位的最短代码胜出! 测试用例 输入-&gt;输出 [1、2、3、4、5]-&gt; [1、3、4] [6,1,0,5,6]-&gt; [6,1,0,5,6] [1、2、3、2、4、11、5、2、0、13、10、1]-&gt; [1、2、11、5、2、0、13、10、1] [2,2,2,2,2,2]-&gt; [2,2] [1、2、3、1、2、3、1、2、3]-&gt; [1、2] [3,1,2,4,0]-&gt; [] * …

6
找出有理生成函数的系数
如果我们写一个数字序列作为幂级数的系数,则该幂级数称为该序列的(普通)生成函数(或Gf)。也就是说,如果对于某些函数F(x)和整数系列,a(n)我们有: a(0) + a(1)x + a(2)x^2 + a(3)x^3 + a(4)x^4 + ... = F(x) 然后F(x)是的生成函数a。例如,几何级数告诉我们: 1 + x + x^2 + x^3 + x^4 + ... = 1/(1-x) 因此,的生成函数1, 1, 1, ...为1/(1-x)。如果我们对上面方程的两边求和并乘以x得到以下等式: x + 2x^2 + 3x^3 + 4x^4 + ... = x/(1-x)^2 因此,的生成函数1, 2, 3, ...为x/(1-x)^2。生成函数是一个非常强大的工具,您可以使用它们来做很多有用的事情。在这里可以找到简短的介绍,但是要获得真正彻底的解释,请参见惊人的图书生成功能学。 在此挑战中,您将有理函数(两个具有整数系数的多项式的商)作为两个整数系数数组的输入作为输入,首先是分子,然后是分母。例如,功能f(x) = x …
12 code-golf  math  integer  polynomials  code-golf  math  abstract-algebra  restricted-time  code-golf  math  primes  code-golf  math  number  arithmetic  code-golf  quine  code-golf  number  sequence  code-golf  string  number  code-golf  array-manipulation  code-golf  number  code-golf  string  code-golf  arithmetic  code-golf  string  array-manipulation  rubiks-cube  code-golf  math  number  code-golf  tips  bash  code-golf  ascii-art  music  code-golf  arithmetic  code-golf  math  number  arithmetic  integer  code-golf  number  array-manipulation  code-golf  geometry  grid  set-partitions  code-golf  math  number  code-golf  combinatorics  code-golf  regular-expression  code-golf  permutations  code-golf  ascii-art  code-golf  number  array-manipulation  matrix  code-golf  kolmogorov-complexity  compile-time  cops-and-robbers  polyglot  cops-and-robbers  polyglot  code-golf  string  code-golf  string  ascii-art  matrix  animation  code-golf  ascii-art  code-golf  string  balanced-string  code-golf  integer  integer-partitions  expression-building 

11
将列表列表解析为悲伤列表
在此挑战中,您必须将列表列表解析为更简单的列表格式。 这项挑战基于我的sadflak解析器。在我的sadflak解析器中,它删除了所有(),并在列表的开头替换为()的总和,以使程序运行更快。 要解析为悲伤列表,您必须执行以下操作(Python实现的事情,使用一个元组的元组): def sadlistfunc(list): new-sadlist = [0] for i in list: if i == (): new-sadlist[0]+=1 else: new-sadlist.append(sadlistfunc(i)) 这是一个递归函数。对于列表,请从列表输入中的()数量开始创建一个新列表,然后该列表的其余部分依次是每个列表的悲伤列表版本,而不是列表输入中的()。返回列表。 输入: 您可以采用几种不同的格式输入: 您可以将其作为列表 你可以把它当成元组 你可以把它当作一个字符串 如果将其作为字符串使用,则应使用一些括号,如出现在脑筋急转弯中的括号。您不能使用字符1和2 只是合理 输入将始终在一个列表内,但是您的程序可能会在输入之外假设一个隐式列表层,即()()()=(()()()),或者可能选择不包含。示例将带有明确的外部列表 输出: 可以是列表,元组或字符串,或其他任何形式。您可以使用任何合理的输出格式,例如元共识。 例: (()()()) = [3] (((()))) = [0,[0,[1]]] ((())()(())) = [1, [1], [1]] () = invalid input, if the outside bracket …

14
用零填充文件
今天的任务是获取一个现有文件,并将零添加到该文件,直到达到一定大小为止。 您必须编写一个程序或函数,该程序或函数采用当前目录中文件的名称f和字节数b。在保留的原始内容的同时f,您必须在末尾写入零(空字节,而不是ascii 0),以便其新大小为b字节。 您可以假设名称中f仅包含字母数字的ascii,您对此具有完全权限,其初始大小不大于b,但可能与一样大b,并且有无限的可用磁盘空间。 您可能不会假设f它是非空的,或者它不已经包含空字节。 执行结束后,不应修改其他现有文件,也不应该存在新文件。 测试用例 f的内容| b | f的结果内容 12345 | 10 | 1234500000 0 | 3 | 000 [空] | 2 | 00 [空] | 0 | [空] 123 | 3 | 123
12 code-golf  file-system  code-golf  code-golf  string  code-golf  string  code-golf  random  game  compression  code-golf  array-manipulation  sorting  code-golf  number  arithmetic  primes  code-golf  geometry  code-golf  code-golf  decision-problem  regular-expression  code-golf  string  math  code-challenge  restricted-source  integer  palindrome  code-golf  string  palindrome  code-challenge  busy-beaver  code-golf  ascii-art  code-golf  string  code-golf  string  permutations  code-golf  code-golf  string  permutations  code-golf  number  primes  function  set-theory  code-challenge  hello-world  code-golf  math  number  decision-problem  code-golf  code-golf  sequence  arithmetic  integer  code-golf  math  number  arithmetic  decision-problem  code-golf  kolmogorov-complexity  alphabet  code-golf  combinatorics  graph-theory  tree-traversal  code-golf  set-theory  code-golf  interpreter  brainfuck  substitution  code-golf  quine  permutations 

6
翻倒沙堆
(存在有关无限沙堆以及查找沙堆的标识元素的相关问题。) 给定非负整数矩阵,返回尺寸相同但倒塌的矩阵: 如果矩阵不包含任何大于4的值,则将其返回。 每个大于3的“单元”都会减少4,并且所有直接相邻的单元(上方,下方,左侧和右侧)(如果存在)都会递增。 转到1。 例子: 0 1 0 0 2 0 2 4 0 -&gt; 3 0 1 0 0 3 0 1 3 1 2 3 2 3 4 2 5 1 4 1 2 0 3 3 0 3 3 0 3 3 4 5 6 -&gt; …

1
分组这些单元格!
该挑战基于游戏Layerz。 给定,在stdin上或作为函数参数,单元格的2D矩形数组,其中每个单元格包含一个空格(可以选择使用0代替空格,而不会受到任何惩罚),1、2、3或4 ; 找到一种方法将其划分为有效区域(如下所述),以使每个非空白单元格仅包含一个区域。然后,以任何合理的格式输出找到的解决方案。如果没有解决方案,则要么停止而不产生输出,要么输出一个假值,然后停止。 以下任何内容均构成有效区域: 包含1的单个单元格 包含2个且恰好是其非空白正交邻居之一的像元 包含3个和正好两个非空白正交邻居的像元 包含4个且恰好是其三个非空白正交邻居的像元 这是code-golf,因此以字节为单位的最短有效答案为准。 一些测试用例: 1.一个相当琐碎的: 这是解决方案,每个区域使用不同的颜色: 2.一个更有趣的 这是一个以上的解决方案,但这是其中之一: 3.较小的一个,包含空格,没有任何解决方案(取决于您是使用二进制之一来“捕获”这三个,还是使用三个来获取两者中的两个,要么留下一个一对不相邻的(因此不可分组的)对或单独一个对): 由于此网格没有解决方案,因此在指定该网格的情况下,您的程序应暂停而不产生任何输出。 4.这个(顶部2个向左移动一个单元格)确实有一个解决方案: 解: (右下角的2用于“捕获” 3) 5.因为我们需要一个包含四个方面的测试用例: 一种解决方案:

30
查找列表的“展开大小”
让我们通过以下规则定义u嵌套列表l(仅包含列表)的“展开大小”功能: 如果l为空,u(l)则为1。 如果l为非空,u(l)则等于中每个元素的展开大小的总和l。 您的任务是编写一个将列表作为输入并输出(或返回)列表未包装大小的程序(或函数)。 测试用例: [] -&gt; 1 [[[]],[]] -&gt; 4 [[[]],[[[[]],[]]],[[[]],[[[[]],[[],[[]]]]]]] -&gt; 19 [[[[]]]] -&gt; 4 这是代码高尔夫球,因此最短的程序(以字节为单位)获胜。

30
输出字符串的累积斜率
挑战 给定一个字符串,例如Hello World!,将其分解为字符值:72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33。 然后计算每对连续字符之间的差:29, 7, 0, 3, -79, 55, 24, 3, -6, -8, -67。 最后,对它们求和并打印最终结果:-39。 规则 适用标准漏洞 请勿使用执行此确切任务的预制函数 鼓励创意解决方案 玩得开心 这被标记为code-golf,以字节为单位的最短答案将获胜,但不会被选择。

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.