Created
February 18, 2019 22:52
-
-
Save gavr123456789/c5bf37d704294903a27f04281af75ab8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
string exponentiation(string str, int n){ | |
string result=""; | |
for (int i=0;i<n;i++) result+=str; | |
return result; | |
} | |
string take_root(string str, int n){ | |
int temp = (str+str)[0:-1].index_of(str,1); | |
if(temp != -1 && (str.char_count()>=str[0:temp].char_count()*n)){ | |
return exponentiation (str[0:temp],str.char_count()/temp /n); | |
} | |
else return "NULL"; | |
} | |
void main(string[] args) { | |
stdout.printf (@"abcd*5 = $(exponentiation("abcd",5))\n"); | |
stdout.printf (@"sassassas√3 = $(take_root("sassassas",3))\n"); | |
stdout.printf (@"aabbaabbaabb√3 = $(take_root("aabbaabbaabb",3))\n"); | |
stdout.printf (@"abababab√4 = $(take_root("abababab",4))\n"); | |
stdout.printf (@"abababab√2 = $(take_root("abababab",2))\n"); | |
stdout.printf (@"abccbaabc√3 = $(take_root("abccbaabc",3))\n"); | |
stdout.printf (@"abccbaabc√3 = $(take_root("abccbaabc",3))\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Найти шаблон в строке
Возведение в степень строки
Корень строки