硬币和其他货币一样是一种货币。Multibaseania的居民(一个经济稳健的城邦体系,在一个遥远的星系中只有很少的居民),他们使用康姆钱币进行他们之间的交易。硬币是用特殊的非纸条上的唯一代码来表示的,当你付款时,你给了卖主你的单据。
然而,就像任何一种货币一样,也有一些邪恶的类型试图利用这个系统来膨胀货币,因为他们感到无聊。
为了打击这种毫无疑问的非法行为,多基地国家的政府聚集在一起,想出一种方法来证明这笔钱是合法的。智囊团的主要想法是:无论何时,只要向一个供应商提供一枚Com硬币,供应商就会运行一个程序,检查它是否合法。人们怎么知道一枚硬币是否合法?
合法的组合硬币是这样一种情况:当组合硬币的唯一代码被转换为2-10基(包括在内)时,该数字是复合的(即不是素数)。此外,基10中的所有唯一代码的数字都是1或0,基10中的长度包含在1和5之间。
非常重要的例子:在基数5中,111是421。即使111不是素数,421也是素数,所以Com硬币是无效的。
挑战
编写一个函数或程序,该函数或程序接受Com投币的代码(一个数字),它位于基数10,是一个整数。然后,打印或返回一个真实或虚假的价值,这分别取决于该硬币是否合法(以上标准)。
Input Output
101 False // because it is prime in base 2
1010 True
10101 True
1010111 False // because it is longer than 5 digits
123 False // because it does not contain *only* 0's and 1's
10111 False // because it is prime in base 6这是代码高尔夫,所以最短的代码以字节为单位获胜!
一个硬币不是一个不是素数的数字,而是一个合成的数字。
发布于 2016-04-11 09:26:27
n6<G50<9:Q"G@ZAZp~vA输入是一个字符串。
在网上试试!
n6< % take input implicitly. Is length less than 6?
G50< % push input again. Array that contains true for digits less than 2
9:Q % push array of bases: [2,3,...,10]
" % for each
G % push input again
@ % push current base
ZA % interpret input as if it were in that base, and convert to decimal
Zp~ % true for composite numbers
v % concatenate vertically all results up to now
A % true if all results were
% end for each implicitly
% display implicitly发布于 2016-04-11 11:00:28
#<1*^5&&Tr@DigitCount[#][[2;;-2]]<1&&FromDigits@IntegerDigits[#,a+1]~Table~{a,9}~NoneTrue~PrimeQ&嘿,至少我试过..。
#<1*^5&&Tr@DigitCount[#][[2;;-2]]<1&&FromDigits@IntegerDigits[#,a+1]~Table~{a,9}~NoneTrue~PrimeQ&
#<1*^5&& less than 100000?
Tr@DigitCount[#][[2;;-2]]<1&& no digits 2-9?
FromDigits@IntegerDigits[#,a+1]~Table~{a,9}~NoneTrue~PrimeQ& composite in all bases?发布于 2016-04-11 02:17:30
[ dup [| a | 2 10 [a,b] [ a swap base> prime? not ] all? ] swap [ [ [ 49 = ] [ 48 = ] bi or ] all? ] [ length 6 < ] bi and and ]我一会儿再打这个球。
嗯,这是我认为更少的金色版本,但它是133个字节.
[ [ [let :> a 2 10 [a,b] [ a swap base> prime? not ] all? ] ] [ [ [ [ 49 = ] [ 48 = ] bi or ] all? ] [ length 6 < ] bi ] bi and and ]实际上不打高尔夫球的:
: comcoin? ( a -- t/f )
[
[let :> a
2 10 [a,b] [ a swap base> prime? not ] all?
]
] [
[ [ [ 49 = ] [ 48 = ] bi or ] all? ]
[ length 6 < ] bi
] bi
and and ;https://codegolf.stackexchange.com/questions/77556
复制相似问题