Skip to content

Commit a82f7d3

Browse files
author
Todd Hogarth
committed
sum-of-digits puz
1 parent c792679 commit a82f7d3

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Bash/sum-of-digits.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
# https://www.codeeval.com/open_challenges/21/
3+
4+
file="$1"
5+
OLDIFS=$IFS
6+
IFS="\n"
7+
while read line || [[ -n "$line" ]]
8+
do
9+
c=0
10+
for((x=0; x<${#line}; x++))
11+
do
12+
d=${line:x:1}
13+
c=$((c + d))
14+
done
15+
echo $c
16+
done < "$file"
17+
IFS=$OLDIFS

data/challenge_21_data

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
23
2-
496
2+
555

0 commit comments

Comments
 (0)