最小的多样化指数


20

pandigital数是包含从0每个数字至9至少一次的整数。1234567890、1902837465000000和9023289761326634265都是pandigital。出于此挑战的目的,诸如123456789之类的数字不是pandigital,因为它们不包含0,即使123456789 = 0123456789。

一个多样化的整数对是一对整数(a,b),因此ab是泛指的。b被称为多样化指数

挑战:给定整数a,找到最小的对应分散指数b。这是一个,因此以字节为单位的最短程序获胜。

(您可以假设存在这样的指数,也就是说,不会为您的程序提供无效的输入,例如10的幂。)

您的解决方案必须至少能够处理给定的测试用例,但理论上应该能够处理所有有效的输入。

这是OEIS上的A090493

测试用例

2 -> 68
3 -> 39
4 -> 34
5 -> 19
6 -> 20
7 -> 18
8 -> 28
9 -> 24
11 -> 23
12 -> 22
13 -> 22
14 -> 21
15 -> 12
16 -> 17
17 -> 14
18 -> 21
19 -> 17
20 -> 51
21 -> 17
22 -> 18
23 -> 14
24 -> 19
25 -> 11
26 -> 18
27 -> 13
28 -> 11
29 -> 12
30 -> 39
31 -> 11
32 -> 14
33 -> 16
34 -> 14
35 -> 19
36 -> 10
1234567890 -> 1

3
我想指出一个特例1234567890 -> 1
Bubbler

@Bubbler添加了。
科纳·奥布莱恩

负指数是否超出限制?
sudo rm -rf斜线

1
123456789pandigital 这样的东西算吗?等于0123456789,这绝对是泛指的。
wastl

1
@wastl不,不是。
科纳·奥布莱恩

Answers:


9

Brachylog(v2),9个字节

;.≜^dl10∧

在线尝试!

这是函数提交。TIO链接包含一个包装器,该包装器将一个函数变成完整的程序。

说明

;.≜^dl10∧
 .≜        Brute-force all integers, outputting the closest to 0
;  ^         for which {the input} to the power of the number
    d        has a list of unique digits
     l10     of length 10
        ∧  (turn off an unwanted implicit constraint)


5

Perl 6,32个字节

{first ($_** *).comb.Set>9,1..*}

在线尝试!

很不言自明。

说明

{                              }  # Anonymous code block
first                     ,1..*   # First positive number that
      ($_** *)    # When the input is raised to that power
              .comb.Set    # The set of digits
                       >9  # Is longer than 9



4

Haskell,50个字节

f a=until(\b->all(`elem`show(a^b))['0'..'9'])(+1)1

在线尝试!

相同字节数:

f a=[b|b<-[1..],all(`elem`show(a^b))['0'..'9']]!!0

3

J,25个字节

>:@]^:(10>#@~.@":@^)^:_&1

在线尝试!

单声道动词。输入应为扩展精度整数(例如2x)。

怎么运行的

>:@]^:(10>#@~.@":@^)^:_&1    Monadic verb. Input: base a
    ^:              ^:_      Good old do-while loop.
                       &1    Given 1 as the starting point for b,
>:@]                         increment it each step
      (            )         and continue while the condition is true:
               ":@^          Digits of a^b
            ~.@              Unique digits
          #@                 Count of unique digits
       10>                   is less than 10

(]+10>#@=@":@^)^:_*
FrownyFrog


2

球拍110 96字节

-14字节的感谢UltimateHawk!

(define(f n[b 1])(if(= 10(length(remove-duplicates(string->list(~v(expt n b))))))b(f n(+ b 1))))

在线尝试!


1
这可以通过递归的函数,而不是缩短为96个字节(define(f n[b 1])(if(= 10(length(remove-duplicates(string->list(~v(expt n b))))))b(f n(+ b 1))))
终极霍克

@UltimateHawk谢谢!我忘记了默认参数...(尽管辅助函数也使用了默认参数b ...)
Galen Ivanov

2

Python 3中52 47字节

感谢@BMO

f=lambda n,i=1:len({*str(n**i)})>9or 1+f(n,i+1)

在线尝试!


请注意,但是您可以删除旧代码,并在标题行中添加“ <s> 52 </ s> 47”。如果有人好奇,编辑日志将保留旧版本
Veskah


1

木炭,19字节

WΦχ¬№IXIθLυIκ⊞υωILυ

在线尝试!链接是详细版本的代码。说明:

WΦχ¬№IXIθLυIκ⊞υω

重复将空字符串推入空列表,直到没有任何数字表示输入长度不包含列表的长度。

ILυ

打印列表的长度。


为什么要下票?
路易斯·门多

1

K(ngn / k),76字节

{#{10>#?(+/|\0<|x)#x}{{+/2 99#,/|0 10\x,0}/+/99 99#,/a*\:x,0}\a::|(99#10)\x}

在线尝试!

{ } 带参数的功能 x

|(99#10)\x 我们将数字表示为99个十进制数字的反向列表-对参数执行此操作

a::分配给全局变量a(k没有闭包。我们需要a是全局的,以便可以在子函数中使用它)

{ }{ }\ 当第一个函数返回falsey时,继续应用第二个函数(又名while循环),保留中间结果

a*\:x每个a数字乘以每个x数字(“外部乘积”)

99 99#a*\:x,0 添加额外的0列并再次调整为99x99,这会将第i行向右移动i项,在左侧插入0(这对于测试有效,对于较大的输入99x99可能会导致溢出)

+/

{+/2 99#,/|0 10\x,0}/ 传播进位:

  • { }/ 继续申请直到收敛

  • 0 10\x divmod除以10(一对列表)

  • |0 10\x 10的moddiv

  • 2 99#,/|0 10\x,0 moddiv减10,“ div”部分向右移1位

  • +/

{10>#?(+/|\0<|x)#x} -检查(而不是)pandigital:

  • |x 相反 x

  • 0< 哪些数字不为零

  • |\ 局部最大值

  • +/ sum-这将计算前导0的数量 x

  • 10> 少于10吗?

# 幂序列的长度-这是结果


1

PowerShell,107字节

param([bigint]$a)for([bigint]$b=1;-join("$([bigint]::pow($a,$b))"|% t*y|sort -u)-ne-join(0..9);$b=$b+1){}$b

在线尝试!

非常简单,只是我们需要在[bigint]所有地方使用的一种耻辱。我们接受输入$a,然后for使用初始值设定项建立循环$b=1

每次迭代,我们增量$b检查是否经过$a ^ $b(通过pow)发送toCharArra ysort编与-uNIQUE标志,那么-join编在一起成一个字符串是-nOT eQUAL到的范围内0..9-join编入的字符串。

满嘴 例如,这会比7 ^ 5 = 16807 --> "01678""0123456789",确定他们不是平等的,并继续循环。

一旦脱离循环,我们就确定了$b适合我们输入的内容,因此将其留在管道中。输出是隐式的。


1

Java,108个字节

a->{int b=0;while(new java.math.BigDecimal(a).pow(++b).toString().chars().distinct().count()<10);return b;};

在线尝试!

说明

蛮力,循环a ^ b直到找到具有10个(或更多,但只有0到9个)唯一字符的字符串。

BigDecimal之所以需要,是因为Math.pow不够准确(大小写失败11),还因为Double默认情况下将a转换为String会显示科学计数法,这打破了这种查找pandigital数的方法。


Java vars默认不是从0开始吗?通过消除初始化可以节省2个字节。
Darrel Hoffman '18

@DarrelHoffman实例变量可以,是的。局部作用域变量没有。
Hypino

嗯好吧 自从我从事Java工作以来已经有一段时间了,忘记了这种技术性。
Darrel Hoffman '18

您可以通过将更new java.math.BigDecimal(a).pow(++b).toString()改为来节省6个字节(new java.math.BigDecimal(a).pow(++b)+"")(lambda函数不必在末尾加上分号)。在线尝试
Kevin Cruijssen 18/12/22

1

Pyth,10 8字节

fq;l{`^Q

在这里在线尝试。

fq;l{`^QT   Implicit: Q=eval(input())
            Trailing T inferred
f           Return (and print) the first positive integer where the following is true:
      ^QT     Raise input to the current number-th power
     `        Convert to string
    {         Deduplicate
   l          Take the length
 q            Is the above equal to...
  ;           10

由于先前的代码FryAmTheEggman,节省了2个字节 fq;l{j^QT;


您可以使用反引号将数字转换为字符串,而不是进行基数转换,这将使您省去T电源操作。
FryAmTheEggman

0

果冻12 11字节

1*@ṾØDfƑʋ1#

在线尝试!

怎么运行的

1*@ṾØDfƑʋ1#  Main link. Argument: n

1            Set the return value to 1.
         1#  Call the link to the left for k = 1, 2, ... and with right argument n,
             until it returns a truthy value.
        ʋ      Combine the four links to the left into a dyadic chain.
 *@              Compute n**k.
   Ṿ             Convert it to its string representation.
    ØD           Yield "0123456789".
      fƑ         Filter and return 1 is the result is equal to the left argument.

0

干净107个 101字节

import StdEnv,Data.Integer
$a=hd[b\\b<-[1..]|length(removeDup[c\\c<-:toString(prod(repeatn b a))])>9]

在线尝试!

将输入作为Integer,返回Int



0

附件,27字节

${Generate{#Unique[x^_]>9}}

在线尝试!

说明

${Generate{#Unique[x^_]>9}}
${                        }    lambda, input: x
  Generate{              }     first natural number _ satisfying...
                   x^_             the input to that number
            Unique[   ]          unique digits of ^
           #                   length of ^
                       >9      is greater than 9
                               i.e.: has 10 distinct digits

备择方案

28个字节: ${Generate{Unique@S[x^_]@9}}

29个字节: ${Generate{Unique[S[x^_]]@9}}

30个字节: ${Generate{#Unique[S[x^_]]>9}}

31个字节: Generate@${{#Unique[S[x^_]]>9}}

32个字节: ${Generate[{#Unique[S[x^_]]>9}]}

33个字节: ${If[#Unique[x^y]>9,y,x&$!-~y]}&0

34个字节: ${If[#Unique[x^y]>9,y,$[x,y+1]]}&0

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.