Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- contract charNumberPair
- {
- string public char;
- uint256 public repeatCount;
- constructor(string memory ch) public {
- char = ch;
- repeatCount = 0;
- }
- function incrementRepeatCount() public
- {
- repeatCount++;
- }
- function getChar() public returns (string memory)
- {
- return char;
- }
- function getRepeatCount() public returns (uint256)
- {
- return repeatCount;
- }
- }
- contract main
- {
- string public txt;
- string public txtlength;
- function getSlice(uint256 begin, uint256 end, string memory text) public pure returns (string memory) {
- bytes memory a = new bytes(end-begin+1);
- for(uint i=0;i<=end-begin;i++){
- a[i] = bytes(text)[i+begin-1];
- }
- return string(a);
- }
- function compareStrings(string memory a, string memory b) public view returns (bool) {
- return (keccak256(abi.encodePacked((a))) == keccak256(abi.encodePacked((b))));
- }
- function setInput(string memory input, string memory lengthInput) public
- {
- txt = input;
- txtlength = lengthInput;
- }
- function mainFunc() public
- {
- uint len = 52;
- string memory alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
- charNumberPair[52] memory pairs;
- uint begin = 0;
- uint end = 2;
- for (uint i = 0; i < len; i++)
- {
- string memory temp = getSlice(begin, end, alphabet);
- pairs[i] = new charNumberPair(temp);
- begin++;
- end++;
- }
- for (uint i = 0; i < len; i++)
- {
- begin = 0;
- end = 2;
- for (uint i2 = 0; i2 < 0; i2++)
- {
- string memory temp = getSlice(begin, end, txt);
- string memory temp2 = pairs[i].getChar();
- if (compareStrings(temp2, temp))
- {
- pairs[i].incrementRepeatCount();
- }
- begin++;
- end++;
- }
- }
- for (uint write = 0; write < len; write++)
- {
- for (uint sort = 0; sort < len - 1; sort++)
- {
- uint256 t1 = pairs[sort].getRepeatCount();
- uint256 t2 = pairs[sort + 1].getRepeatCount();
- if (t1 > t2)
- {
- charNumberPair temp = pairs[sort + 1];
- pairs[sort + 1] = pairs[sort];
- pairs[sort] = temp;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment