RMarK0

Untitled

Jun 11th, 2021 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. contract charNumberPair
  2. {
  3.     string public char;
  4.     uint256 public repeatCount;
  5.    
  6.     constructor(string memory ch) public {
  7.         char = ch;
  8.         repeatCount = 0;
  9.     }
  10.    
  11.     function incrementRepeatCount() public
  12.     {
  13.         repeatCount++;
  14.     }
  15.    
  16.     function getChar() public returns (string memory)
  17.     {
  18.         return char;
  19.     }
  20.    
  21.     function getRepeatCount() public returns (uint256)
  22.     {
  23.         return repeatCount;
  24.     }
  25. }
  26.  
  27. contract main
  28. {
  29.     string public txt;
  30.     string public txtlength;
  31.  
  32.     function getSlice(uint256 begin, uint256 end, string memory text) public pure returns (string memory) {
  33.         bytes memory a = new bytes(end-begin+1);
  34.         for(uint i=0;i<=end-begin;i++){
  35.             a[i] = bytes(text)[i+begin-1];
  36.         }
  37.         return string(a);  
  38.     }
  39.    
  40.     function compareStrings(string memory a, string memory b) public view returns (bool) {
  41.     return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))));
  42. }
  43.    
  44.     function setInput(string memory input, string memory lengthInput) public
  45.     {
  46.         txt = input;
  47.         txtlength = lengthInput;
  48.     }
  49.    
  50.     function mainFunc() public
  51.     {
  52.         uint len = 52;
  53.         string memory alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
  54.         charNumberPair[52] memory pairs;
  55.    
  56.         uint begin = 0;
  57.         uint end = 2;
  58.    
  59.         for (uint i = 0; i < len; i++)
  60.         {
  61.             string memory temp = getSlice(begin, end, alphabet);
  62.             pairs[i] = new charNumberPair(temp);
  63.             begin++;
  64.             end++;
  65.         }
  66.        
  67.         for (uint i = 0; i < len; i++)
  68.         {
  69.             begin = 0;
  70.             end = 2;
  71.             for (uint i2 = 0; i2 < 0; i2++)
  72.             {
  73.                 string memory temp = getSlice(begin, end, txt);
  74.                 string memory temp2 = pairs[i].getChar();
  75.                 if (compareStrings(temp2, temp))
  76.                     {
  77.                         pairs[i].incrementRepeatCount();
  78.                     }
  79.                 begin++;
  80.                 end++;
  81.             }
  82.         }
  83.        
  84.         for (uint write = 0; write < len; write++)
  85.             {
  86.                 for (uint sort = 0; sort < len - 1; sort++)
  87.                 {
  88.                     uint256 t1 = pairs[sort].getRepeatCount();
  89.                     uint256 t2 = pairs[sort + 1].getRepeatCount();
  90.                     if (t1 > t2)
  91.                     {
  92.                         charNumberPair temp = pairs[sort + 1];
  93.                         pairs[sort + 1] = pairs[sort];
  94.                         pairs[sort] = temp;
  95.                     }
  96.                 }
  97.             }
  98.     }
  99. }
  100.  
  101.  
Add Comment
Please, Sign In to add comment