Questions tagged «math»

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

20
计算获得抛硬币一半头的概率。
编写一个程序,给定标准输入的一个小的正偶数,它计算出翻转多个硬币将导致正面数目减少一半的概率。 例如,给定2个硬币,可能的结果是: HH HT TH TT 其中H和T是头和尾。有2个结果(HT和TH)的正面数是硬币数量的一半。共有4个结果,因此概率为2/4 = 0.5。 这比看起来简单。 测试用例: 2 -> 0.5 4 -> 0.375 6 -> 0.3125 8 -> 0.2734375

2
飞机爆炸
该吹胀是代数几何中的有力工具。它可以去除奇点从代数集中同时保留其其余结构。 如果您对这些都不熟悉,请不要担心,实际的计算并不难理解(请参阅下文)。 下面我们考虑爆炸了点(0,0)(0,0)(0,0)2D中的代数曲线 二维的代数曲线由两个变量的多项式的零位给出(例如p(x,y)=x2+y2−1p(x,y)=x2+y2−1p(x,y) = x^2 + y^2 - 1 对于单位圆,或者 p(x,y)=y−x2p(x,y)=y−x2p(x,y) = y-x^2抛物线)。那条曲线的爆炸(在(0,0)(0,0)(0,0))由两个多项式给出 r,sr,sr,s如下定义。都rrr 和 sss 确实描述 ppp 具有(可能)的奇点 (0,0)(0,0)(0,0) 删除。 挑战 给定一些多项式 ppp, 找 rrr 和 sss 如下定义。 定义 首先请注意,我在这里所说的一切都是简化的,并不完全符合实际定义。 给定多项式 ppp 在两个变量中 x,yx,yx,y该爆破是由两个多项式给出r,sr,sr,s 再次在两个变量中每个。 要得到 rrr 我们首先定义 R(x,v):=p(x,vx)R(x,v):=p(x,vx)R(x,v) := p(x,vx)。然后R(x,v)R(x,v)R(x,v) 大概是 xxx,即 R(x,v)=xn⋅r(x,v)R(x,v)=xn⋅r(x,v)R(x,v) = x^n \cdot r(x,v) …

15
计算复杂的力量
破败不堪 给定任何输入x和y,执行复杂的操作,并打印相应的结果。 您的程序应如何工作 给定x和y的形式z = x + yi,找到z i-z 如果z i-z的绝对实际值大于绝对虚部,则打印该实部;否则,打印实部。反之亦然。如果两个值相等,则打印其中一个值。 例 x: 2 y: 0 因此: z = 2 z^(i-z) ~= 0.192309 + 0.159740i 由于实部的绝对值大于虚部的绝对值,因此程序返回 0.192309 更多例子 z = 1+i >> 0.5 z = i >> 1 z = 0.5 >> 1.08787 z = -2+8i >> 2.22964E7 z = …

17
设置两个列表的交集
您的目标是计算两个整数列表的集合相交。相交定义为在两个输入列表中至少发现一次的唯一无序整数组。 输入项 输入可以是所需的任何格式(功能参数,标准输入输出等),并且由两个整数列表组成。除了可能包含任何非负数的整数(即它们未排序,可能包含重复项,可能具有不同长度,甚至可能为空)之外,您可能不假设有关每个列表的任何内容。假定每个整数都适合您语言的本机带符号整数类型,长度可能超过1个十进制数字,并且已签名。 输入示例: 1 4 3 9 8 8 3 7 0 10 1 4 4 8 -1 输出量 输出是任何类似于列表的整数,代表将两个列表的交集设置为所需的任何格式(返回值,stdio等)。尽管欢迎您提供恰好总是被排序的实现,但是并不需要对输出进行排序。输出必须形成有效的无序集合(例如,它不得包含任何重复值)。 测试用例示例(请注意,输出顺序并不重要): 前两行是输入列表,第三行是输出。(empty)表示空白列表。 (empty) (empty) (empty) 1000 (empty) (empty) 3 1 2 4 3 1 1 1 1 3 3 1 -1 0 8 3 3 1 1 3 1 …

7
高尔夫代码:弗雷序列(I)
挑战 在此任务中,您将得到一个整数N(小于10 ^ 5),输出N阶的Farey序列。 输入N在单行中给出,输入由EOF终止。 输入项 4 3 1 2 输出量 F4 = {0/1, 1/4, 1/3, 1/2, 2/3, 3/4, 1/1} F3 = {0/1, 1/3, 1/2, 2/3, 1/1} F1 = {0/1, 1/1} F2 = {0/1, 1/2, 1/1} 约束条件 输入数量不会超过10 ^ 6个值 您可以使用任何选择的语言 最短的解决方案获胜!
10 code-golf  math  code-golf  math  code-golf  number  number-theory  code-golf  math  arithmetic  repeated-transformation  code-golf  geometry  popularity-contest  code-golf  code-golf  tips  haskell  math  fastest-algorithm  code-golf  combinatorics  code-golf  math  polynomials  rational-numbers  code-golf  code-golf  popularity-contest  javascript  code-golf  kolmogorov-complexity  code-golf  code-golf  math  combinatorics  permutations  code-challenge  restricted-source  random  array-manipulation  code-challenge  generation  code-golf  code-golf  ascii-art  arithmetic  division  code-challenge  number  code-golf  math  number  binary  code-golf  ascii-art  code-golf  interpreter  stack  code-golf  internet  networking  code-golf  math  code-golf  ascii-art  code-golf  math  sequence  code-golf  hello-world  restricted-source  code-golf  ascii-art  code-golf  geometry  code-golf  kolmogorov-complexity  pi  code-golf  math  combinatorics  permutations  code-golf  math  code-challenge  ascii-art  code-golf  string  code-golf  quine  code-golf  math  floating-point  golfscript  code-golf  string  code-golf  sliding-puzzle  code-challenge  arithmetic  code-golf  math  code-golf  geometry  optimized-output 

2
粉末玩具中打高尔夫球的技巧
玩得开心,“粉玩具”是高尔夫运动中一个有趣的挑战,尤其是在摆球逻辑方面。 使TPT成为挑战的是许多解决问题的方法: Should I use Cellular Automaton rules, SWCH logic, Filt logic, subframe filt logic, and/or wall logic? 这样,TPT高尔夫球技巧的位置将非常有帮助,因此我提出了这个问题。 该线程可能会使用很多缩写。其中很多都是游戏中的元素,因此在Wiki上进行搜索会带给您很多有关它们的信息,例如它们的外观。 这是您可能在此主题中看到的最常见的内容,并附有游戏内描述(及其全名),以供不希望搜索的人使用: SPRK:电力。TPT中所有电子设备的基础是沿着电线和其他导电元件传播的。 过滤:过滤。过滤光子,更改颜色。 ARAY:Ray Emitter。光线碰撞时会创建点。 BTRY:电池。产生无限电。 DRAY:复印机射线。复制前面的一行粒子。 CRAY:粒子射线发射器。创建由其ctype设置的粒子束,范围由tmp设置。 SWCH:切换。仅在打开时进行。(PSCN打开,NSCN关闭) 所有元素清单
9 code-golf  tips  the-powder-toy  code-golf  number  array-manipulation  integer  code-golf  string  decision-problem  boggle  code-golf  array-manipulation  average  code-golf  math  code-golf  decision-problem  restricted-source  code-golf  code-golf  math  primes  code-golf  random  code-golf  tips  perl  code-golf  string  parsing  code-golf  math  number  decision-problem  code-golf  math  number  code-golf  string  alphabet  code-golf  math  geometry  code-golf  interpreter  brainfuck  code-golf  code-golf  decision-problem  boggle  code-golf  math  number  sequence  code-golf  math  code-golf  ascii-art  code-challenge  restricted-source  quine  code-golf  math  decision-problem  number-theory  primes  code-golf  ascii-art  code-golf  integer  graph-theory  chess  code-golf  math  interpreter  code-golf  code-golf  code-golf  ascii-art  code-golf  arithmetic  number-theory  code-golf  string  kolmogorov-complexity  code-golf  string  decision-problem  code-golf  primes  factoring  encode  code-golf  decision-problem  code-golf  geometry  grid  code-golf  quine  code-golf  matrix  code-golf  matrix  code-golf  code-golf  number  array-manipulation  code-golf  array-manipulation  sorting  code-golf  matrix  code-golf  brain-flak 

1
工作时间计算器
这是基于我公司如何处理每个员工的工作时间监控。我们每个人都有一张可以在传感器前通过的卡,这样一来,时钟便记录了员工签到或签出办公室的时间。每次寄存器都链接到一个代码: 代码0:员工到达(或返回)办公室。 代码1:员工离开办公室吃午餐。 代码2:员工在一天结束时离开办公室。 代码3:员工出于工作原因离开办公室。 代码4:员工出于个人原因离开办公室。 代码0寄存器有时将被称为“零寄存器”,代码1至代码4寄存器有时将被称为“非零寄存器”。 因此,对于工人来说,正常的一天会生成如下的注册表: Code/Time ------------ 0 8:17 // The employee arrives at the office 4 11:34 // The employee leaves the office to smoke 0 11:41 // The employee returns to the office 1 13:37 // The employee leaves the office to have lunch 0 …

7
火车穿过一座标有商标的桥
考虑由标有级联的正整数的数字的图块形成的长度为B的桥。例如,如果B为41,则它将如下所示: ----------------------------------------- 12345678910111213141516171819202122232425 现在想象一列长度为T的火车过桥。火车的最左端开始于位置X(1索引)。为了更好地理解问题,让我们为事件制定一个方案,其中B = 41,T = 10,X = 10。使用等号(=)和线绘制火车: __________ | ======== | | ======== | ----------------------------------------- 12345678910111213141516171819202122232425 火车在每一步中都可以通过其所在的唯一图块的总和来前进。例如,火车在上面站立的磁贴为:[1, 0, 1, 1, 1, 2, 1, 3, 1, 4],唯一(重复数据消除)磁贴为:[1, 0, 2, 3, 4],其总和为10。因此,火车可以前进10。我们应该再次绘制它并重复该过程,直到火车的最左边的点通过最后一个图块: __________ | ======== | | ======== | ----------------------------------------- 12345678910111213141516171819202122232425 唯一区块的总和:1 + 5 + 6 + 7 + …

5
椭圆系统
介绍 给定平面中的五个点,您的任务是计算通过这些点的椭圆的面积。 您可以假设可以使用给定的输入值构造一个完全不变的椭圆。 规则 输入是10任何方便形式的整数,与点的x和y坐标相对应。例如,您可以将输入作为10整数列表[x1, y1, x2, y2, ..., x5, y5]或[[x1, y1], [x2, y2], ..., [x5, y5]],等等。您也可以处理十进制数字,但只需要整数。 输出是椭圆面积的表示。这可以是一些符号表达式,也可以8是精度至少为十进制的十进制值。 这是代码高尔夫球,因此最短的答案以字节为单位。 输入和输出示例 输入: [-2、3、2、5、5、3、4、0、1,-3 输出: 62.15326783788685 通过这些点的椭圆的描述: 更多示例: f(60, -92, -31, -10, 78, -19, -27, -35, 91, -37) = 9882.59540465108 f(-9, -4, 7, 7, 10, 1, -7, -10, 0, 7) = 269.5966648188643 …

7
打假素!
简介/背景 在最近一次关于加密聊天的讨论中,我被挑战去讨论/帮助Fermat素数测试和Carmichael数字。该测试基于a^(p-1) mod p==1始终适用于素数p而不适用于复合材料的前提。现在,carmichael号码本质上是Fermat考验的最大敌人:您必须选择一个号码,a以使其不与素数p相抵a^(p-1) mod p!=1。现在,如果a不是互质,则基本上可以发现一个非平凡的因子p众所周知,保理可能相当困难。特别是在所有因素都足够大的情况下。您现在可能已经意识到,为什么在实践中不经常使用Fermat测试(还有更好的算法),这是因为作为防御者(在安全性方面)您需要为某些数字做与攻击者(即数量)。 因此,既然我们知道为什么这些数字有些引人入胜,我们将以最短的方式生成它们,因此只要需要,我们就可以记住生成的代码! Carmichael编号在OEIS上也称为A002997。已经 存在一个相关的挑战,但是这里的条目没有竞争力,因为它们是针对速度而非大小进行了优化的。同样的论点也适用于反方向,此处的输入可能会在速度上做出取舍,而有利于大小。 规格 输入项 这是一个标准 序列挑战,因此您将正整数或非负整数n作为输入。n可以根据需要选择0或1的索引(请指出)。 输出量 根据需要,您的输出将是n-th carmichael数或第一个ncarmichael数(请指出)。 规格 一个整数x是卡迈克尔数当且仅当x是复合材料和所有的整数y与gcd(x,y)=1,它认为y^(x-1) mod x==1。 谁赢? 这是 代码高尔夫球,因此以字节为单位的最短代码获胜!适用标准IO和漏洞规则。 测试用例 前几个carmichael号码是: 561,1105,1729,2465,2821,6601,8911,10585,15841, 29341,41041,46657,52633,62745,63973,75361,101101, 115921,126217,162401,172081,188461,252601,278545, 294409,314821,334153,340561,399001,410041,449065, 488881,512461
9 code-golf  math  sequence  number-theory  primes  code-golf  string  code-golf  math  combinatorics  permutations  restricted-complexity  code-golf  array-manipulation  code-golf  number  sequence  code-golf  number  sequence  code-golf  binary-matrix  code-golf  math  tips  javascript  algorithm  code-golf  string  code-golf  number  sequence  code-golf  math  arithmetic  parsing  code-golf  number  sequence  primes  code-golf  string  ascii-art  geometry  integer  code-golf  geometry  code-golf  number  array-manipulation  code-golf  math  geometry  code-golf  number  sequence  arithmetic  integer  code-golf  string  kolmogorov-complexity  code-golf  number  code-golf  number  chess  code-golf  sequence  decision-problem  subsequence  code-golf  math  number  primes  code-golf  primes  permutations  code-golf  integer  probability-theory  statistics  code-golf  string  code-golf  sequence  decision-problem  parsing  board-game  code-golf  binary  graph-theory  code-golf  board-game  classification  tic-tac-toe  code-golf  ascii-art  polyglot  code-golf  date  code-golf  geometry 

13
扩大比较链
与大多数语言不同,Python a<b<c会像在数学中一样进行评估,实际上是比较三个数字,而不是将布尔值a<b与进行比较c。用C(以及许多其他语言)编写此代码的正确方法是a<b && b<c。 在这个挑战中,您的任务是将这样任意长度的比较链从Python /直观表示扩展到如何用其他语言编写。 技术指标 您的程序必须要处理运算符:==, !=, <, >, <=, >=。 输入将具有仅使用整数的比较链。 不用担心一路比较的真实性,这纯粹是语法/语法上的挑战。 输入将没有任何空格,以防止答案因分割空格而使解析变得琐碎。 但是,您的输出可能只有一个空格,要么仅包含&&,要么包含比较运算符和&&,或者两者都不包含,但是要保持一致。 测试用例 Input Output --------------------------------------------------------------- 3<4<5 3<4 && 4<5 3<4<5<6<7<8<9 3<4 && 4<5 && 5<6 && 6<7 && 7<8 && 8<9 3<5==6<19 3<5 && 5==6 && 6<19 10>=5<7!=20 10>=5 && 5<7 && 7!=20 15==15==15==15==15 …
9 code-golf  parsing  conversion  syntax  code-golf  sequence  primes  code-challenge  geometry  optimization  code-golf  graph-theory  code-golf  number-theory  primes  integer  code-golf  source-layout  cops-and-robbers  code-golf  source-layout  cops-and-robbers  code-golf  sequence  primes  integer  code-golf  math  number-theory  primes  rational-numbers  code-golf  math  sequence  number-theory  primes  code-golf  string  code-golf  math  combinatorics  permutations  restricted-complexity  code-golf  array-manipulation  code-golf  number  sequence  code-golf  number  sequence  code-golf  binary-matrix  code-golf  math  tips  javascript  algorithm  code-golf  string  code-golf  number  sequence  code-golf  math  arithmetic  parsing  code-golf  number  sequence  primes  code-golf  string  ascii-art  geometry  integer  code-golf  geometry  code-golf  number  array-manipulation  code-golf  math  geometry  code-golf  number  sequence  arithmetic  integer  code-golf  string  kolmogorov-complexity  code-golf  number  code-golf  number  chess  code-golf  sequence  decision-problem  subsequence  code-golf  math  number  primes  code-golf  primes  permutations  code-golf  integer  probability-theory  statistics  code-golf  string  code-golf  sequence  decision-problem  parsing  board-game  code-golf  binary  graph-theory  code-golf  board-game  classification  tic-tac-toe  code-golf  ascii-art  polyglot  code-golf  date  code-golf  geometry 

3
n位精度的近似浮点数
我们有一个r介于0和1之间的浮点数和一个整数p。 查找具有最小分母的整数分数,其分数近似r至少为- p位数。 输入:(r一个浮点数)和p(整数)。 输出:a和b整数,其中 a/b(以浮点数表示)近似r到p数字。 b 是可能的最小此类正整数。 例如: 如果r=0.14159265358979和p=9, 那么结果是a=4687和b=33102, 因为4687/33102=0.1415926530119026。 任何解决方案都必须在理论上适用于任意精度类型,但是由实现的固定精度类型引起的限制并不重要。 精度表示在“ 0.” 之后的数字位数r。因此,如果r=0.0123和p=3,a/b则应从开始0.012。如果的p小数部分的第一位数字为r0,则可以接受未定义的行为。 获胜标准: 算法上最快的算法获胜。速度以O(p)为单位。 如果有多个最快的算法,则最短者获胜。 我自己的答案被排除在可能的获胜者之外。 ps数学部分实际上看起来似乎容易得多,我建议您阅读这篇文章。

17
素数分解中的素数
我看到了PPCG 面临的另一个主要挑战,而且我确实爱我一些主要挑战。然后,我误读了介绍性文字,想知道这里的创造力是什么。 事实证明,提出的问题是微不足道的,但我想知道我(误读)的问题是否也是如此: 6可以用2 ^ 1 * 3 ^ 1表示,而50可以用2 ^ 1 * 5 ^ 2表示(其中^表示指数)。 你的任务: 编写程序或函数,以确定此数字表示形式中有多少个不同的质数。 输入: 通过任何常规方法获取的整数n,使得1 <n <10 ^ 12。 输出: 表示 n 的唯一素数所需的不同素数的数量。 测试用例: Input Factorisation Unique primes in factorisation representation 24 2^3*3^1 2 (2, 3) 126 2^1*3^2*7^1 3 (2, 3, 7) 8 2^3 2 …

30
给定int输入n,输出n * reversed(n)
给定一个整数n,打印输出n * reversed(n) reversed(n)是当您reverse的数字为时得到的数字n。 reverse(512) = 215 reverse(1) = 1 reverse(101) = 101 >>>>>>>> func(5) = 5*5 = 25 func(12) = 12*21 = 252 func(11) = 11*11 = 121 func(659) = 659*956 = 630004 最短的代码胜出! 排行榜 显示代码段 var QUESTION_ID=144816,OVERRIDE_USER=71625;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var …
9 code-golf  math  arithmetic  code-golf  math  integer  code-golf  arithmetic  integer  code-golf  sequence  base-conversion  palindrome  code-golf  math  primes  integer  code-golf  parsing  conversion  syntax  code-golf  sequence  primes  code-challenge  geometry  optimization  code-golf  graph-theory  code-golf  number-theory  primes  integer  code-golf  source-layout  cops-and-robbers  code-golf  source-layout  cops-and-robbers  code-golf  sequence  primes  integer  code-golf  math  number-theory  primes  rational-numbers  code-golf  math  sequence  number-theory  primes  code-golf  string  code-golf  math  combinatorics  permutations  restricted-complexity  code-golf  array-manipulation  code-golf  number  sequence  code-golf  number  sequence  code-golf  binary-matrix  code-golf  math  tips  javascript  algorithm  code-golf  string  code-golf  number  sequence  code-golf  math  arithmetic  parsing  code-golf  number  sequence  primes  code-golf  string  ascii-art  geometry  integer  code-golf  geometry  code-golf  number  array-manipulation  code-golf  math  geometry  code-golf  number  sequence  arithmetic  integer  code-golf  string  kolmogorov-complexity  code-golf  number  code-golf  number  chess  code-golf  sequence  decision-problem  subsequence  code-golf  math  number  primes  code-golf  primes  permutations  code-golf  integer  probability-theory  statistics  code-golf  string  code-golf  sequence  decision-problem  parsing  board-game  code-golf  binary  graph-theory  code-golf  board-game  classification  tic-tac-toe  code-golf  ascii-art  polyglot  code-golf  date  code-golf  geometry 

3
两根交织的链
在这个问题中,我将“链”功能定义为: 是一个排列,意味着每个值都映射到一个值,并被一个值恰好映射到该值。 并允许通过重复应用该函数或其反函数从任何其他值获得任何值。 有很多功能可以做到这一点,其中一些功能非常简单(请参阅该问题的答案)。现在,我们将定义一个单独的函数类,称之为“交织”函数。的交织功能是在一组的功能甲,具有两个无限分区一个0和一个1,使得该函数是在两个链功能一个0和一个1。 这意味着,在没有值一个0可映射到一个值一1的功能或反之亦然下。 任务 您的任务是编写一个在正整数上执行或定义交织函数的代码。只要满足交织的条件,您的功能就可以是任何东西。您应该在答案中包含有关为什么要交织功能的说明。 这是一个 代码高尔夫球 问题,因此答案将以字节计分,字节越少越好。

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.