7 kyu

Give me a Crazy Formula!

208 of 296Arthur GC

Description:

Given a non-negative number, sum all its digits using the following rules:

  1. If the number of digits is even, remove the last digit

  2. a. If the middle digit is odd, subtract it instead of adding

    b. If both the middle digit and the last digit are even, subtract the last digit instead of adding

    c. If the middle digit is even but the last digit is odd, the first digit must be squared

Repeat this process until only 1 digit is left.

Note: if at some point the number becomes negative, remove the minus sign.

Examples

5  =>  5

214  =>  2 - 1 + 4 = 5   =>  5
126  =>  1 + 2 - 6 = -3  =>  3

2234  =>  223  =>  2^2 + 2 + 3 = 9  =>  9
Mathematics
Algorithms
Puzzles

Stats:

CreatedDec 4, 2015
PublishedDec 4, 2015
Warriors Trained966
Total Skips58
Total Code Submissions1218
Total Times Completed296
C# Completions95
Python Completions208
Total Stars20
% of votes with a positive feedback rating91% of 97
Total "Very Satisfied" Votes82
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes3
Total Rank Assessments8
Average Assessed Rank
7 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • Arthur GC Avatar
  • KataSideKick Avatar
  • FArekkusu Avatar
  • a.kozhanov Avatar
  • hobovsky Avatar
  • albertogcmr Avatar
  • dfhwze Avatar
Ad