Skip to content

Instantly share code, notes, and snippets.

@gavr123456789
Created February 18, 2019 22:52
Show Gist options
  • Save gavr123456789/c5bf37d704294903a27f04281af75ab8 to your computer and use it in GitHub Desktop.
Save gavr123456789/c5bf37d704294903a27f04281af75ab8 to your computer and use it in GitHub Desktop.
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");
}
@gavr123456789
Copy link
Author

Найти шаблон в строке
Возведение в степень строки
Корень строки

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment