如何在APL中将数字分成数字 [英] How to split a number into its digits in APL
本文介绍了如何在APL中将数字分成数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在APL中,如何将整数或数字拆分为包含数字的向量?最简洁(最短)的方法是什么?
解决方案
您可以将Decode
的倒数设为10:
10⊥⍣¯1⊢
由于Decode
将根据需要输入尽可能多的数字并对其进行解码,因此它的逆运算将采用一个数字并将其编码为所需的任意数字,
,或者使用⎕IO←0
,您可以尝试在数字矢量内查找带格式的数字的索引:
⎕D⍳⍕
You can use the inverse of Decode
with base 10:
10⊥⍣¯1⊢
since Decode
would take in as many digits as needed and decode them, its inverse would take a number and encode it to as many digits as needed,
or, with ⎕IO←0
, you can try to find the indexes of the formatted number inside the digits vector:
⎕D⍳⍕
This is better than the uglier use of Encode
with custom length derived by shaping an array of 10 to the length of the log10 of the input:
{⍵⊤⍨10⍴⍨⌈10⍟1+⍵}
这篇关于如何在APL中将数字分成数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文