Problem 20. Summing digits
解决方案统计数据
Problem Comments
-
6 Comments
The test suite was broken, as many of you suspected. I fixed it and rescored the problems.
I like this problem:)
非常有趣的问题
Good
The test case 3 is totally wrong. It needs immediate correction. The code maker didn't notice that b=25 is a number not a single digit. If you're doing the sum of digits it always ends up with a single digit, it will never end up with number cause number itself is carrying multiple digits.
只是为了徽章;的)
解决方案评论
-
2评论
函数b = sumdigits(n)
pow=2^n;
b = 0;
虽然pow〜= 0
b = b + mod(pow,10);
pow=floor(pow/10);
结尾
结尾
The code is wrong. Cause the while doest have a stopping condition.
-
1条评论
This is cheating, you didn't even solve the problem, you just passed parameters to the test suite
-
2评论
-
1条评论
我们的程序没有得到批准,直到我们强迫B键成为Int8功能的整数
-
1条评论
good job
-
1条评论
函数b = sumdigits(n)
%SUMDIGITS Given n, find the sum of the digits that make up 2^n
在= num2str(2 ^ n);
b = sum(str2num(在(:)));
结尾
-
1条评论
该解决方案不涵盖整个范围的n。
-
1条评论
This codes gives expected result verified in matlab, dont know why it is considered as incorrect answer
-
1条评论
Clunky, but I'm happy ^_^
-
2评论
Interesting problem. I guess it´s rarely applied.
great! learning the existence of arrayfun
-
1条评论
在qs中,传递变量是'n',在解决方案中它是'a'
-
3评论
-
1条评论
This solution takes advantage of the fact that the ASCII character set is nicely ordered.
-
2评论
Extremely clever! Why didn't I think of that!?
Great: to transpose a char row into a char column makes the work...
-
2评论
How does this work?
这是预兆,查找表。相当常见的方法,当输入变量来自小集(和计算长期和硬)时。现在我认为这是欺骗这场比赛,对不起:]
-
2评论
很好但这个解决方案不适用于总和> 47
所以在mod和sum之间切换应该很好吗?
-
2评论
please explain why the digits get separated when (num2str(2^n)-'0') is performed
Num2STR将整数号码转换为该数字的字符串表示:1234变为“1234”,其与['1','2','3','4']相同。现在你有一个数组条目每位。从那里减去'0',然后Char数组将成为一个双数组,其中值为0,其中Char为'0'等。
-
1条评论
我没有让什么我的解决方案失败了a = 16
b = sum(str2num(num2str(2 ^ a)')为a = 16,但它失败了
-
1条评论
Buggy
-
1条评论
这只有(显然)如果n的数字加入到9的数字,这对于当前的测试用例而言,这很好,但在以后没有保持。
-
1条评论
这不应该有效,因为你应该总结2 ^ n的数字