Perform string shifts by intervals

Here given code implementation process.

/*
    Java program
    Perform string shifts by intervals
*/
public class Shifting
{
	public void shifts(String text, int intervals[], int n)
	{
		if (n != text.length())
		{
			return;
		}
		char[] result = text.toCharArray();;
		// Change intervals
		for (int i = n - 1; i >= 0; --i)
		{
			if (i < n - 1)
			{
				intervals[i] = (intervals[i] + intervals[i + 1]) % 26;;
			}
			else
			{
				intervals[i] = intervals[i] % 26;;
			}
		}
		// Change result value
		for (int i = 0; i < n; i++)
		{
			result[i] = (char)(97 + (((int) result[i] + intervals[i]) % 97) % 26);
		}
		System.out.println(" Given  text : " + text);
		System.out.println(" Result      : " + String.valueOf(result));
	}
	public static void main(String[] args)
	{
		Shifting task = new Shifting();
		// Given lowercase string text
		String text = "amount";
		/*
		    text     : amount  
		    interval : [4, 2, 14, 14, 13, 11]
		    ----------------------------------
		       a   m   o   u   n   t
		       ─   │   │   │   │   │
		    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
		       e   m   │   │   │   │ 
		    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
		       g   o   o   │   │   │
		  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
		       u   c   c   u   │   │ 
		  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
		       i   q   q   i   n   │
		  +13  ↓   ↓   ↓   ↓   ↓   │
		       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
		  +11  ↓   ↓   ↓   ↓   ↓   │  
		       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
		    ----------------------------
		       g   o   o   g   l   e
		    ----------------------------     

		*/
		int[] intervals = {
			4 , 2 , 14 , 14 , 13 , 11
		};
		int n = intervals.length;
		task.shifts(text, intervals, n);
	}
}

Output

 Given  text : amount
 Result      : google
// Include header file
#include <iostream>
#include <string>

using namespace std;
/*
    C++ program
    Perform string shifts by intervals
*/
class Shifting
{
	public: void shifts(string text, int intervals[], int n)
	{
		if (n != text.length())
		{
			return;
		}
		string result = text;
		// Change intervals
		for (int i = n - 1; i >= 0; --i)
		{
			if (i < n - 1)
			{
				intervals[i] = (intervals[i] + intervals[i + 1]) % 26;;
			}
			else
			{
				intervals[i] = intervals[i] % 26;;
			}
		}
		// Change result value
		for (int i = 0; i < n; i++)
		{
			result[i] = (char)(97 + (((int) result[i] + 
                               intervals[i]) % 97) % 26);
		}
		cout << " Given  text : " << text   << endl;
		cout << " Result      : " << result << endl;
	}
};
int main()
{
	Shifting *task = new Shifting();
	// Given lowercase string text
	string text = "amount";
	/*
			    text     : amount  
			    interval : [4, 2, 14, 14, 13, 11]
			    ----------------------------------
			       a   m   o   u   n   t
			       ─   │   │   │   │   │
			    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
			       e   m   │   │   │   │ 
			    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
			       g   o   o   │   │   │
			  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
			       u   c   c   u   │   │ 
			  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
			       i   q   q   i   n   │
			  +13  ↓   ↓   ↓   ↓   ↓   │
			       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
			  +11  ↓   ↓   ↓   ↓   ↓   │  
			       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
			    ----------------------------
			       g   o   o   g   l   e
			    ----------------------------     

			*/
	int intervals[] = {
		4 , 2 , 14 , 14 , 13 , 11
	};
	int n = sizeof(intervals) / sizeof(intervals[0]);
	task->shifts(text, intervals, n);
	return 0;
}

Output

 Given  text : amount
 Result      : google
// Include namespace system
using System;
/*
    Csharp program
    Perform string shifts by intervals
*/
public class Shifting
{
	public void shifts(String text, int[] intervals, int n)
	{
		if (n != text.Length)
		{
			return;
		}
		char[] result = text.ToCharArray();
		// Change intervals
		for (int i = n - 1; i >= 0; --i)
		{
			if (i < n - 1)
			{
				intervals[i] = (intervals[i] + intervals[i + 1]) % 26;;
			}
			else
			{
				intervals[i] = intervals[i] % 26;;
			}
		}
		// Change result value
		for (int i = 0; i < n; i++)
		{
			result[i] = (char)(97 + (((int) result[i] + intervals[i]) % 97) % 26);
		}
		Console.WriteLine(" Given  text : " + text);
      	String s = new String(result);
		Console.WriteLine(" Result      : " +s );
	}
	public static void Main(String[] args)
	{
		Shifting task = new Shifting();
		// Given lowercase string text
		String text = "amount";
		/*
				    text     : amount  
				    interval : [4, 2, 14, 14, 13, 11]
				    ----------------------------------
				       a   m   o   u   n   t
				       ─   │   │   │   │   │
				    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
				       e   m   │   │   │   │ 
				    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
				       g   o   o   │   │   │
				  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
				       u   c   c   u   │   │ 
				  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
				       i   q   q   i   n   │
				  +13  ↓   ↓   ↓   ↓   ↓   │
				       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
				  +11  ↓   ↓   ↓   ↓   ↓   │  
				       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
				    ----------------------------
				       g   o   o   g   l   e
				    ----------------------------     

				*/
		int[] intervals = {
			4 , 2 , 14 , 14 , 13 , 11
		};
		int n = intervals.Length;
		task.shifts(text, intervals, n);
	}
}

Output

 Given  text : amount
 Result      : google
package main

import "fmt"
/*
    Go program
    Perform string shifts by intervals
*/

func shifts(text string, intervals[] int, n int) {
	if n != len(text) {
		return
	}
	var result = [] byte(text)
	// Change intervals
	for i := n - 1 ; i >= 0 ; i-- {
		if i < n - 1 {
			intervals[i] = (intervals[i] + intervals[i + 1]) % 26
		} else {
			intervals[i] = intervals[i] % 26
		}
	}
	// Change result value
	for i := 0 ; i < n ; i++ {
		result[i] = byte((97 + (( int(result[i]) + intervals[i]) % 97) % 26))
	}
	fmt.Println(" Given  text :", text)
	fmt.Printf(" Result      : %s", result)
}
func main() {
	
	// Given lowercase string text
	var text string = "amount"
	/*
	    text     : amount  
	    interval : [4, 2, 14, 14, 13, 11]
	    ----------------------------------
	       a   m   o   u   n   t
	       ─   │   │   │   │   │
	    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
	       e   m   │   │   │   │ 
	    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
	       g   o   o   │   │   │
	  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	       u   c   c   u   │   │ 
	  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	       i   q   q   i   n   │
	  +13  ↓   ↓   ↓   ↓   ↓   │
	       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
	  +11  ↓   ↓   ↓   ↓   ↓   │  
	       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
	    ----------------------------
	       g   o   o   g   l   e
	    ----------------------------     
	*/
	var intervals = [] int {
		4,
		2,
		14,
		14,
		13,
		11,
	}
	var n int = len(intervals)
	shifts(text, intervals, n)
}

Output

 Given  text : amount
 Result      : google
<?php
/*
    Php program
    Perform string shifts by intervals
*/
class Shifting
{
	public	function shifts($text, $intervals, $n)
	{
		if ($n != strlen($text))
		{
			return;
		}
		$result = $text;
		// Change intervals
		for ($i = $n - 1; $i >= 0; --$i)
		{
			if ($i < $n - 1)
			{
				$intervals[$i] = ($intervals[$i] + 
                                  $intervals[$i + 1]) % 26;;
			}
			else
			{
				$intervals[$i] = $intervals[$i] % 26;;
			}
		}
		// Change result value
		for ($i = 0; $i < $n; $i++)
		{
			$result[$i] = chr((97 + (( ord($result[$i]) + 
                                      $intervals[$i]) % 97) % 26));
		}
		echo(" Given  text : ".$text.
			"\n");
		echo(" Result      : ".$result."\n");
	}
}

function main()
{
	$task = new Shifting();
	// Given lowercase string text
	$text = "amount";
	/*
			    text     : amount  
			    interval : [4, 2, 14, 14, 13, 11]
			    ----------------------------------
			       a   m   o   u   n   t
			       ─   │   │   │   │   │
			    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
			       e   m   │   │   │   │ 
			    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
			       g   o   o   │   │   │
			  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
			       u   c   c   u   │   │ 
			  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
			       i   q   q   i   n   │
			  +13  ↓   ↓   ↓   ↓   ↓   │
			       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
			  +11  ↓   ↓   ↓   ↓   ↓   │  
			       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
			    ----------------------------
			       g   o   o   g   l   e
			    ----------------------------     

			*/
	$intervals = array(4, 2, 14, 14, 13, 11);
	$n = count($intervals);
	$task->shifts($text, $intervals, $n);
}
main();

Output

 Given  text : amount
 Result      : google
/*
    Node JS program
    Perform string shifts by intervals
*/
class Shifting
{
	shifts(text, intervals, n)
	{
		if (n != text.length)
		{
			return;
		}
		var result = (text).split('');
		// Change intervals
		for (var i = n - 1; i >= 0; --i)
		{
			if (i < n - 1)
			{
				intervals[i] = (intervals[i] + intervals[i + 1]) % 26;;
			}
			else
			{
				intervals[i] = intervals[i] % 26;;
			}
		}
		// Change result value
		for (var i = 0; i < n; i++)
		{
			result[i] = String.fromCharCode((97 + 
                                           ((result[i].charCodeAt(0) +
                                           intervals[i]) % 97) % 26));
		}
		console.log(" Given  text : " + text);
		console.log(" Result      : " + result.join(""));
	}
}

function main()
{
	var task = new Shifting();
	// Given lowercase string text
	var text = "amount";
	/*
			    text     : amount  
			    interval : [4, 2, 14, 14, 13, 11]
			    ----------------------------------
			       a   m   o   u   n   t
			       ─   │   │   │   │   │
			    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
			       e   m   │   │   │   │ 
			    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
			       g   o   o   │   │   │
			  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
			       u   c   c   u   │   │ 
			  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
			       i   q   q   i   n   │
			  +13  ↓   ↓   ↓   ↓   ↓   │
			       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
			  +11  ↓   ↓   ↓   ↓   ↓   │  
			       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
			    ----------------------------
			       g   o   o   g   l   e
			    ----------------------------     

			*/
	var intervals = [4, 2, 14, 14, 13, 11];
	var n = intervals.length;
	task.shifts(text, intervals, n);
}
main();

Output

 Given  text : amount
 Result      : google
#    Python 3 program
#    Perform string shifts by intervals
class Shifting :
	def shifts(self, text, intervals, n) :
		if (n != len(text)) :
			return
		
		result = [char for char in text]
		i = n - 1
		#  Change intervals
		while (i >= 0) :
			if (i < n - 1) :
				intervals[i] = (intervals[i] + intervals[i + 1]) % 26
			else :
				intervals[i] = intervals[i] % 26
			
			i -= 1
		
		i = 0
		#  Change result value
		while (i < n) :
			result[i] = chr((97 + ((ord(result[i]) + intervals[i]) % 97) % 26))
			i += 1
		
		print(" Given  text : ", text)
		print(" Result      : ", ''.join(result))
	

def main() :
	task = Shifting()
	#  Given lowercase string text
	text = "amount"
	# 		    text     : amount  
	# 		    interval : [4, 2, 14, 14, 13, 11]
	# 		    ----------------------------------
	# 		       a   m   o   u   n   t
	# 		       ─   │   │   │   │   │
	# 		    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
	# 		       e   m   │   │   │   │ 
	# 		    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
	# 		       g   o   o   │   │   │
	# 		  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	# 		       u   c   c   u   │   │ 
	# 		  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	# 		       i   q   q   i   n   │
	# 		  +13  ↓   ↓   ↓   ↓   ↓   │
	# 		       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
	# 		  +11  ↓   ↓   ↓   ↓   ↓   │  
	# 		       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
	# 		    ----------------------------
	# 		       g   o   o   g   l   e
	# 		    ----------------------------     
	intervals = [4, 2, 14, 14, 13, 11]
	n = len(intervals)
	task.shifts(text, intervals, n)

if __name__ == "__main__": main()

Output

 Given  text :  amount
 Result      :  google
#    Ruby program
#    Perform string shifts by intervals
class Shifting 
	def shifts(text, intervals, n) 
		if (n != text.length) 
			return
		end

		result = text.chars
		i = n - 1
		#  Change intervals
		while (i >= 0) 
			if (i < n - 1) 
				intervals[i] = (intervals[i] + intervals[i + 1]) % 26
			else
 
				intervals[i] = intervals[i] % 26
			end

			i -= 1
		end

		i = 0
		#  Change result value
		while (i < n) 
			result[i] = ((97 + (( result[i].ord + 
                                 intervals[i]) % 97) % 26)).chr
			i += 1
		end

		print(" Given  text : ", text, "\n")
		print(" Result      : ", result.join(""), "\n")
	end

end

def main() 
	task = Shifting.new()
	#  Given lowercase string text
	text = "amount"
	# 		    text     : amount  
	# 		    interval : [4, 2, 14, 14, 13, 11]
	# 		    ----------------------------------
	# 		       a   m   o   u   n   t
	# 		       ─   │   │   │   │   │
	# 		    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
	# 		       e   m   │   │   │   │ 
	# 		    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
	# 		       g   o   o   │   │   │
	# 		  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	# 		       u   c   c   u   │   │ 
	# 		  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	# 		       i   q   q   i   n   │
	# 		  +13  ↓   ↓   ↓   ↓   ↓   │
	# 		       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
	# 		  +11  ↓   ↓   ↓   ↓   ↓   │  
	# 		       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
	# 		    ----------------------------
	# 		       g   o   o   g   l   e
	# 		    ----------------------------     
	intervals = [4, 2, 14, 14, 13, 11]
	n = intervals.length
	task.shifts(text, intervals, n)
end

main()

Output

 Given  text : amount
 Result      : google
import scala.collection.mutable._;
/*
    Scala program
    Perform string shifts by intervals
*/
class Shifting()
{
	def shifts(text: String, intervals: Array[Int], n: Int): Unit = {
		if (n != text.length())
		{
			return;
		}
		var result: Array[Char] = text.toCharArray();
		var i: Int = n - 1;
		// Change intervals
		while (i >= 0)
		{
			if (i < n - 1)
			{
				intervals(i) = (intervals(i) + 
                                intervals(i + 1)) % 26;;
			}
			else
			{
				intervals(i) = intervals(i) % 26;;
			}
			i -= 1;
		}
		i = 0;
		// Change result value
		while (i < n)
		{
			result(i) = (97 + ((result(i).toInt + 
                                intervals(i)) % 97) % 26).toChar;
			i += 1;
		}
		println(" Given  text : " + text);
		println(" Result      : " + String.valueOf(result));
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Shifting = new Shifting();
		// Given lowercase string text
		var text: String = "amount";
		/*
				    text     : amount  
				    interval : [4, 2, 14, 14, 13, 11]
				    ----------------------------------
				       a   m   o   u   n   t
				       ─   │   │   │   │   │
				    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
				       e   m   │   │   │   │ 
				    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
				       g   o   o   │   │   │
				  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
				       u   c   c   u   │   │ 
				  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
				       i   q   q   i   n   │
				  +13  ↓   ↓   ↓   ↓   ↓   │
				       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
				  +11  ↓   ↓   ↓   ↓   ↓   │  
				       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
				    ----------------------------
				       g   o   o   g   l   e
				    ----------------------------     

				*/
		var intervals: Array[Int] = Array(4, 2, 14, 14, 13, 11);
		var n: Int = intervals.length;
		task.shifts(text, intervals, n);
	}
}

Output

 Given  text : amount
 Result      : google
import Foundation;
/*
    Swift 4 program
    Perform string shifts by intervals
*/
class Shifting
{
	func shifts(_ text: String, _ intervals: inout[Int], _ n: Int)
	{
		if (n  != text.count)
		{
			return;
		}
		var result: [Character] = Array(text);
		var i: Int = n - 1;
		// Change intervals
		while (i >= 0)
		{
			if (i < n - 1)
			{
				intervals[i] = (intervals[i] + intervals[i + 1]) % 26;
			}
			else
			{
				intervals[i] = intervals[i] % 26;
			}
			i -= 1;
		}
		i = 0;
		// Change result value
		while (i < n)
		{
          	let data = Int(UnicodeScalar(String(result[i]))!.value);
			result[i] =  Character(UnicodeScalar(97 + 
                         ((data + intervals[i]) % 97) % 26)!);
			i += 1;
		}
		print(" Given  text : ", text);
		print(" Result      : ", String(result));
	}
}
func main()
{
	let task: Shifting = Shifting();
	// Given lowercase string text
	let text: String = "amount";
	/*
	    text     : amount  
	    interval : [4, 2, 14, 14, 13, 11]
	    ----------------------------------
	       a   m   o   u   n   t
	       ─   │   │   │   │   │
	    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
	       e   m   │   │   │   │ 
	    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
	       g   o   o   │   │   │
	  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	       u   c   c   u   │   │ 
	  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	       i   q   q   i   n   │
	  +13  ↓   ↓   ↓   ↓   ↓   │
	       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
	  +11  ↓   ↓   ↓   ↓   ↓   │  
	       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
	    ----------------------------
	       g   o   o   g   l   e
	    ----------------------------     
	*/
	var intervals: [Int] = [4, 2, 14, 14, 13, 11];
	let n: Int = intervals.count;
	task.shifts(text, &intervals, n);
}
main();

Output

 Given  text :  amount
 Result      :  google
/*
    Kotlin program
    Perform string shifts by intervals
*/
class Shifting
{
	fun shifts(text: String, intervals: Array < Int > , n: Int): Unit
	{
		if (n != text.length)
		{
			return;
		}
		var result = text.toCharArray();
		var i: Int = n - 1;
		// Change intervals
		while (i >= 0)
		{
			if (i < n - 1)
			{
				intervals[i] = (intervals[i] + intervals[i + 1]) % 26;
			}
			else
			{
				intervals[i] = intervals[i] % 26;
			}
			i -= 1;
		}
		i = 0;
		// Change result value
		while (i < n)
		{
			result[i] = (97 + ((result[i].toInt() + intervals[i]) % 97) % 26).toChar();
			i += 1;
		}
		println(" Given  text : " + text);
		println(" Result      : " +result.joinToString(""));
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Shifting = Shifting();
	// Given lowercase string text
	val text: String = "amount";
	/*
	    text     : amount  
	    interval : [4, 2, 14, 14, 13, 11]
	    ----------------------------------
	       a   m   o   u   n   t
	       ─   │   │   │   │   │
	    +4 ↓   │   │   │   │   │  ('a'+4) = 'e'
	       e   m   │   │   │   │ 
	    +2 ↓   ↓   │   │   │   │  ('e' + 2 = 'g'),('m'+2 = 'p') 
	       g   o   o   │   │   │
	  +14  ↓   ↓   ↓   │   │   │  ('g' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	       u   c   c   u   │   │ 
	  +14  ↓   ↓   ↓   ↓   │   │  ('o' + 14 = 'o'),('p'+14 = 'd') ,('o'+14 = 'i') 
	       i   q   q   i   n   │
	  +13  ↓   ↓   ↓   ↓   ↓   │
	       v   d   d   v   a   t ('i' + 13 = 'v'),('q'+13 = 'd') => 2-time ,('i'+13 = 'v') ,('n'+13 = 'a') 
	  +11  ↓   ↓   ↓   ↓   ↓   │  
	       g   o   o   g   l   e ('v' + 11 = 'g'),('d'+11 = 'o') => 2-time ,('v'+11 = 'g')  ,                              ('a'+13 = 'l'), ('t'+11 = 'e)
	    ----------------------------
	       g   o   o   g   l   e
	    ----------------------------     
	*/
	var intervals: Array < Int > = arrayOf(4, 2, 14, 14, 13, 11);
	val n: Int = intervals.count();
	task.shifts(text, intervals, n);
}

Output

 Given  text : amount
 Result      : google


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved