Questions tagged «math»

挑战涉及数学。还可以考虑使用更具体的标签:[数字] [数字理论] [算术] [组合] [图形理论] [几何] [抽象代数]。

4
使用停止的Oracle解决三个未解决的问题
您将获得以下函数:h1(f,* args)和h2(f,* args) 两者都是已经为您定义的方法(此处的星号表示可变数量的参数) f是一个函数,* args是要传递给该函数的参数列表 h1返回一个布尔值:如果在* args上调用f时函数停止,则返回true;否则返回False(假定正在运行的计算机具有无限的时间和内存,并且您正在编写的语言的解释器/编译器)知道如何处理无限的时间和记忆)。 如果f(* args)曾经调用过h1或h2,则h1会引发异常 h2的行为与h1完全相同,只是如果f调用了h1,则h2不会引发异常 用尽可能少的字符编写一个无需输入且应输出的程序: The Collatz Conjecture is {True/False} Goldbach's Conjecture is {True/False} The Twin Primes Conjecture is {True/False} 基于每个猜想的有效性。 以下是解释每个猜想的维基百科链接: http://en.wikipedia.org/wiki/Collat​​z_conjecture http://en.wikipedia.org/wiki/Goldbach%27s_conjecture http://en.wikipedia.org/wiki/Twin_prime 您可以假设任何以您选择使用的语言编写的大整数库都将成功表示任意大整数。换句话说,我们假设任何能够表达的语言/库3**(3**10)也能够3**(3**(3**10))在足够强大的机器上表达。 显然,由于无法运行您的程序,请与代码一起说明其工作方式
23 code-golf  math 

6
乐高齿轮比
我正在构建一个大型的乐高机器人,我需要使用一组齿轮来生成一些特定的齿轮比。我有很多常见的乐高齿轮规格的齿轮:8齿,16齿,24齿或40齿。编写一个可以在输入齿轮比的地方使用的程序,该程序会告诉我应该使用哪种齿轮组合来获得所需的齿轮比。 输入比例将在标准输入(或您的语言的等效输入)上指定,并且两个整数之间用冒号分隔。比率a:b表示输出轴的旋转a/b时间应与输入轴的旋转速度相同。 输出到标准输出应该是包含齿轮比的一个空格分隔列表中的单个线路,在的形式x:y,其中x是在输入轴上的齿轮的尺寸和y是在输出轴的齿轮的尺寸。对于给定的传动比,必须使用尽可能少的齿轮数。每个x和y必须的一个8,16,24,40。 例子: 1:5 -> 8:40 10:1 -> 40:8 16:8 9:4 -> 24:16 24:16 7:1 -> IMPOSSIBLE 7:7 -> 6:15 -> 16:40 如果不可能达到所需的传动比,则打印“不可行”。如果不需要齿轮,请打印空字符串。 这是代码高尔夫,最短答案胜出。
23 code-golf  math 

7
将中缀表达式转换为后缀表示法
当我看到这个封闭问题的标题时,我认为它看起来像是一个有趣的高尔夫挑战代码。因此,让我这样介绍一下: 挑战: 编写一个程序,表达式或子例程,给定一个用infix表示的算术表达式,例如1 + 2,以后缀表示即输出相同的表达式1 2 +。 (注意:类似的挑战在1月初发布。 但是,我确实觉得这两个任务在细节上有很大不同,足以证明这个单独的挑战是正确的。而且,我只在键入下面的所有内容后才注意到另一个线程,我宁愿不只是把它扔掉。) 输入: 输入包括由以下组成的有效缀算术表达式的数目(非负整数表示为一个或多个十进制数字序列),平衡括号来指示分组的子表达式,和四个缀二进制运算符 +,-,*和/。这些中的任何一个都可以由任意数量的空格字符分隔(并且整个表达式都被包围),应将其忽略。1个 对于那些喜欢形式语法的人,这里有一个简单的类似于BNF的语法,定义了有效的输入。为了简洁起见,语法不包含可选空格,该空格可能出现在任意两个标记之间(数字中的数字除外): expression := number | subexpression | expression operator expression subexpression := "(" expression ")" operator := "+" | "-" | "*" | "/" number := digit | digit number digit := "0" | "1" | "2" | …
23 code-golf  math 

30
完全是素数的素数测试
编写一个程序,该程序将测试指定数字的素数,并将输出作为布尔值给出(True是素数)。您的主要测试可以(但不一定)对数字1有效。 要注意的是:您的程序本身必须求和一个质数。将每个字符(包括空格)转换为其Unicode / ASCII值(表)。然后,将所有这些数字相加,得出程序的总和。 例如,采用我在Python 3.3中编写的不太好的程序: q=None y=int(input()) for x in range(2,int(y**0.5)+1): if y%x==0: q=False if not q: q=True print(q) 如果将所有字符转换为相应的Unicode / ASCII值,则会得到: 113 61 78 111 110 101 10 121 61 105 110 116 40 105 110 112 117 116 40 41 41 10 102 111 114 32 120 …

19
迪克斯特拉的挑战
为纪念APL成为今年50岁的互动工具而颁发 背景 肯·艾弗森(Ken [Iverson])在1963年8月于新泽西州普林斯顿举行的机械语言结构工作会议上发表了他的论文《程序语言形式化》。(巴克斯,库里,迪克斯特拉,弗洛伊德,艾弗森,纽厄尔,玻璃市,威尔克斯)。该文件还记录了演讲后的讨论,最后在Ken和[Edsger] Dijkstra之间进行了交流,其中Ken对Dijkstra问题的答复是单线的。 挑战 您将如何表示一个更复杂的操作,例如,矩阵M中所有元素的总和等于相应的行索引和列索引的总和? 编写一个代码段或表达式(不需要完整的程序或函数)以计算给定整数矩阵中每个元素的总和,该整数等于其索引的总和。或者,如FryAmTheEggman所说:给定一个矩阵中号的元素一个 IJ返回每个的总和一个 IJ其中一个 IJ = I + J。 您可以假定矩阵已经在变量或存储位置中,或者可以将其用作参数或输入。您可以使用基于0或1的索引。 测试用例 0 用于空矩阵 2 0基于0的索引或2基于1的索引 1 5 2 9 4 2 5 9 6 2基于0或10基于1 0 3 0 4 0 4 1 4 4 3 1 2 -2 4 -2 -1 11 3 -1 …

13
is_gaussian_prime(z)?
任务 编写一个函数,该函数接受a,b代表高斯整数z = a+ib(复数)的两个整数。程序必须根据a+ib是高斯素数来返回true或false 。 定义: a + bi 当且仅当满足以下条件之一时,它是高斯素数: a且b均为非零且a^2 + b^2为素数 a是零,|b|是素数,|b| = 3 (mod 4) b是零,|a|是素数,|a| = 3 (mod 4) 细节 您应该只编写一个函数。如果您的语言没有函数,则可以假定整数存储在两个变量中,然后打印结果或将结果写入文件。 您不能使用语言的内置功能,例如isprime或prime_list或nthprime或factor。最低字节数获胜。程序必须a,b在a^2+b^232位(带符号)整数的where 处工作,并且结束时间不应超过30秒。 首要清单 点表示高斯平面上的质数(x=实数,y=虚轴): 一些较大的素数: (9940, 43833) (4190, 42741) (9557, 41412) (1437, 44090)

1
是否可以使钳位函数比JS中的三元函数短?
想象一下这个短函数将一个数字钳位在0到255之间: c = n => n > 0 ? n < 255 ? n : 255 : 0 这是使用JavaScript(没有ES.Next功能)的钳位函数的最短版本吗? PS:不确定是否相关,但是0和255不是随机的,其想法是将数字钳位为8位无符号整数。

23
倒置的金字塔加法…反转!
倒置金字塔加法是获取一个数字列表并将其连续加在一起直到达到一个数字的过程。 给出数字后,2, 1, 1将发生以下过​​程: 2 1 1 3 2 5 这以数字结尾5。 你的任务 给定“颠倒金字塔”(升序)的右侧,编写将返回原始列表的程序或函数。 新的额外挑战:尝试在小于O(n ^ 2)的范围内进行操作 例 f([5, 2, 1]) => [2, 1, 1] f([84,42,21,10,2]) => [4,7,3,8,2] 注意:倒置金字塔永远不会为空,并且将始终仅由正整数组成。

28
做一个简单的自动包装
(注意:这是我有史以来第一个关于高尔夫的代码问题,但是据我所知,没有人能完全做到这一点,所以我应该很好。) 您的任务是制作一个程序或函数,该程序或函数接受一个字符串s和一个整数n,并返回或输出包装成多行的文本。每个单词必须全部在一行上;即中间没有字。每行的n字符长度不能超过字符,并且每行中必须包含尽可能多的单词。 例: s = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed eget erat lectus. Morbi mi mi, fringilla sed suscipit ullamcorper, tristique at mauris. Morbi non commodo nibh. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Sed at iaculis mauris. Praesent a …
22 code-golf  string  code-golf  string  parsing  apl  math  primes  integer  fastest-code  code-golf  math  primes  integer  code-golf  ascii-art  kolmogorov-complexity  code-golf  string  array-manipulation  code-golf  number  code-golf  sequence  code-golf  math  arithmetic  code-golf  date  conversion  code-golf  geometry  combinatorics  grid  code-golf  string  code-golf  counting  java  code-golf  chess  code-golf  path-finding  conversion  atomic-code-golf  logic-gates  code-golf  fibonacci  code-golf  ascii-art  fractal  code-golf  quine  code-golf  string  code-golf  array-manipulation  decision-problem  code-golf  quine  code-golf  code-challenge  array-manipulation  code-challenge  word-search  code-golf  binary  conversion  code-golf  code-golf  restricted-source  code-golf  kolmogorov-complexity  restricted-source  code-golf  kolmogorov-complexity  random  animation 

23
ASCII艺术八边形
给定输入整数n > 1,输出边长由n字符组成的ASCII八角形。请参阅以下示例: n=2 ## # # # # ## n=3 ### # # # # # # # # # # ### n=4 #### # # # # # # # # # # # # # # # # #### n=5 ##### # # # # # # …
22 code-golf  ascii-art  code-golf  geometry  code-golf  balanced-string  code-golf  cops-and-robbers  code-challenge  cops-and-robbers  code-golf  code-golf  random  cryptography  code-golf  array-manipulation  number  code-challenge  integer  code-golf  math  integer  code-golf  math  math  parsing  image-processing  test-battery  math  number  combinatorics  fastest-code  code-golf  code-golf  math  number-theory  rational-numbers  polynomials  code-golf  math  geometry  code-golf  code-golf  number-theory  primes  factoring  code-golf  restricted-source  code-golf  string  decision-problem  counting  code-golf  math  sequence  fibonacci  code-golf  array-manipulation  counting  code-golf  array-manipulation  number-theory  code-golf  array-manipulation  code-golf  random  code-golf  string  hexadecimal  code-golf  string  code-challenge  sorting  code-golf  number  floating-point  code-golf  sorting  code-golf  decision-problem  fibonacci  code-golf  number  combinatorics  code-golf  string  code-golf  math  code-golf  electrical-engineering  code-golf  javascript  code-golf  base-conversion  code-golf  array-manipulation  matrix  binary-matrix  code-golf  kolmogorov-complexity  python  perl  ruby  code-golf  number  code-golf  optimization  integer-partitions  code-golf  string  code-golf  ascii-art 

16
找出3 x 3矩阵的逆矩阵
挑战 给定九个数字,a, b, c, d, e, f, g, h, i作为与平方矩阵相对应的输入: M=⎛⎝⎜adgbehcfi⎞⎠⎟M=(abcdefghi)\mathbf{M} = \begin{pmatrix}a& b& c\\ d& e& f\\ g& h& i\end{pmatrix} 求矩阵的逆M− 1M−1个\mathbf{M}^{-1}并输出其分量。 逆矩阵 矩阵3乘3的逆遵循以下方程式: M M− 1= M− 1M =我 = ⎛⎝⎜1个0001个0001个⎞⎠⎟中号中号-1个=中号-1个中号=一世=(1个0001个0001个)\mathbf{MM}^{-1} = \mathbf{M}^{-1}\mathbf{M} = \mathbf{I} = \begin{pmatrix}1&0&0\\0&1&0\\0&0&1\end{pmatrix} 可以计算为: 中号− 1= 1det (M)CŤ中号-1个=1个t(中号)CŤ\mathbf{M}^{-1} = \frac{1}{\det(\mathbf{M})}\mathbf{C}^T 其中是辅助因子的矩阵:CC\mathbf{C} C = ⎛⎝⎜e …

24
ogl-edocf挑战
输入项 一个非空的字符串,由范围内的ASCII字符组成。[ 32..126 ][32..126][32..126] 输出量 通过对输入字符串进行连续旋转来获得输出。 对于[a-zA-Z]输入字符串中的每个字母(),从左到右: 如果字母是大写字母,请将其前面的所有字符向左旋转一个位置 如果字母是小写字母,请将其前面的所有字符向右旋转一个位置 例 输入:“ Cb-Ad” 第一个字母是“ C ”。我们应该向左旋转,但是这个“ C ” 之前没有字符。因此,没有任何旋转。 下一个字母是“ b ”。我们向右旋转“ C ”。因为它是单个字符,所以它保持不变。 字符“ - ”不会触发任何旋转,因为它不是字母。 下一个字母是“ A ”。我们轮流“ CB- ”到左边,这给“ 公元前广告” 第四个也是最后一个字母是“ d ”。我们向右旋转“ b-CA ”,即为“ Ab-C d” 因此,预期输出为“ Ab-Cd ”。 规则 您可以将输入作为字符串或字符数组进行输入-根据您的语言,输入内容可能相同也可能不同。 您也可以输出字符数组而不是字符串。 这是ogl-edocf 代码高尔夫 测试用例 "cbad" -> …
22 code-golf  string  code-golf  string  code-golf  string  parsing  brainfuck  code-challenge  python  hello-world  error-message  code-golf  string  code-golf  number  integer  counting  subsequence  code-golf  string  cipher  code-golf  array-manipulation  arithmetic  integer  matrix  code-golf  math  sequence  code-golf  restricted-source  pi  popularity-contest  cops-and-robbers  polyglot  popularity-contest  cops-and-robbers  polyglot  code-golf  file-system  king-of-the-hill  code-golf  number  sequence  integer  rational-numbers  string  code-challenge  source-layout  code-golf  ascii-art  king-of-the-hill  code-golf  array-manipulation  sorting  code-golf  string  code-golf  restricted-source  source-layout  tips  math  code-challenge  permutations  logic-gates  code-golf  number  random  integer  code-golf  math  code-golf  math  number  decision-problem  king-of-the-hill  python  board-game  code-challenge  brainfuck  busy-beaver  code-golf  number  cops-and-robbers  polyglot  obfuscation  answer-chaining  code-golf  number  integer  conversion  code-golf  string  parsing  code-golf  ascii-art  number  king-of-the-hill  javascript  code-golf  source-layout  radiation-hardening  code-golf  array-manipulation  matrix  code-golf  string  graph-theory  code-golf  array-manipulation  decision-problem  code-golf  string  ascii-art  code-golf  string  code-golf  array-manipulation 

18
数字的RTA(逆向加法)根
逆序加法(RTA)序列是通过在逆序上加一个数字,并对结果重复该过程而获得的序列。例如 5+5=10⇒10+01=11⇒11+11=22⇒22+22=44⇒ ...5+5=10⇒10+01=11⇒11+11=22⇒22+22=44⇒ ... 5 + 5 = 10 \Rightarrow 10 + 01 = 11 \Rightarrow 11 + 11 = 22 \Rightarrow 22 + 22 = 44 \Rightarrow\text{ }... 因此,5的RTA序列包含10、11、22、44、88、176等。 数字n的RTA根是等于n或在其RTA序列中加n的最小数字。nnnnnnnnn 例如,在RTA序列5、10、11、13、22、31等中找到44。其中5是最小的,因此RTA​​root(44)= 5。 72不是任何数字的RTA序列的一部分,因此被视为其自己的RTA根。 输入是您的语言自然可以处理的范围内的正整数。 如上所述,输出是给定数字的RTA根。 测试用例 Input Output 44 5 72 72 132 3 143 49 1111 1 999 …
22 code-golf  math  number 

17
生成沃尔什矩阵
一个Walsh矩阵是一种特殊的具有方阵在量子计算的应用程序(也可能是其他地方,但我只关心量子计算)。 沃尔什矩阵的性质 尺寸是2的相同的功率。因此,我们可以用2的指数是指这些矩阵这里,美其名曰W(0),W(1),W(2)... W(0)定义为[[1]]。 对于n>0, W(n)看起来像: [[W(n-1) W(n-1)] [W(n-1) -W(n-1)]] 因此W(1): [[1 1] [1 -1]] 并且W(2)是: [[1 1 1 1] [1 -1 1 -1] [1 1 -1 -1] [1 -1 -1 1]] 模式还在继续... 你的任务 编写一个程序或函数,将整数作为输入n并W(n)以任何方便的格式打印/返回。.svg只要是正确的,它就可以是一个数组数组,一个布尔值的扁平数组,一个图像,您可以为其命名。 禁止出现标准漏洞。 几件事: 对于W(0),1甚至不需要包装一次。它可以仅仅是一个整数。 您可以对1个索引的结果进行查询- W(1)然后为[[1]]。 测试用例 0 -> [[1]] 1 -> [[1 1] [1 -1]] …
22 code-golf  math  matrix 

13
哈夫尼亚人Codegolf
挑战是为矩阵的Hafnian写codegolf 。对称矩阵的2nHafnian 定义为:2nA 下面就2N代表了一组整数的所有排列的,从1到2n,那就是[1, 2n]。 Wikipedia链接讨论了邻接矩阵,但是您的代码应适用于任何实值对称输入矩阵。 对于那些对Hafnian应用程序感兴趣的人,mathoverflow链接讨论了更多内容。 您的代码可以随意输入,并以任何合理的格式提供输出,但是请在答案中包括一个完整的示例,其中包括有关如何向代码提供输入的明确说明。 输入矩阵始终为正方形,最大为16 x16。无需处理空白矩阵或奇数维矩阵。 参考实施 这是Xcoder先生提供的一些示例python代码。 from itertools import permutations from math import factorial def hafnian(matrix): my_sum = 0 n = len(matrix) // 2 for sigma in permutations(range(n*2)): prod = 1 for j in range(n): prod *= matrix[sigma[2*j]][sigma[2*j+1]] my_sum += prod return my_sum / …

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.