Created
September 3, 2017 09:42
-
-
Save linkin-park/b80da1465763ea83cb0a69e7cdd752e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Enter your code here. Read input from STDIN. Print output to STDOUT | |
% Your class should be named solution | |
-module(solution). | |
-export([main/0]). | |
main() -> | |
{ok,[N,K]} = io:fread("","~s~d"), | |
P = ktimes(N,K,""), | |
{Num,_} = string:to_integer(P), | |
io:format("~p",[splitONum(Num)]). | |
%string:concat is ++ operator | |
ktimes(_,0,R)-> R; | |
ktimes(IntStr,K,R)-> ktimes(IntStr,K-1,string:concat(IntStr,R)) . | |
splitONum(N)when N < 10 -> N; | |
splitONum(N)-> splitONum(foo(N,0)). | |
%N denotes the number , S as SUM | |
foo(0,S)-> S; | |
foo(N,S) -> foo(N div 10,(N rem 10) + S). |
Author
linkin-park
commented
Sep 4, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment