Created with <3 with dartpad.dev.
Created
August 23, 2023 14:10
-
-
Save halka9000stg/552802bbd114445333046194efadfb9d to your computer and use it in GitHub Desktop.
T Material Stones
This file contains 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
import "dart:convert"; | |
import "dart:math" as math; | |
void main() { | |
run("YMO","TMS"); | |
} | |
void run(String a, String b){ | |
print(a.asLIB); | |
print(b.asLIB); | |
print(a.asLI - b.asLI); | |
} | |
extension on String{ | |
List<int> get asLI{ | |
List<int> asc = ascii.encode(this); | |
if(!asc.every((int e)=>(65<=e&&e<=122)&&!(90<e&&e<97))){ | |
return []; | |
} | |
return asc.map((int e)=>e<=90?(e-65)*2:(e-97)*2+1).toList(); | |
} | |
MapEntry<List<int>, String> get asLIB => MapEntry<List<int>, String>(this.asLI, this.asLI.toBinStr(6)); | |
} | |
extension on List<int>{ | |
List<int> operator -(List<int> other){ | |
List<int> ret = []; | |
for(int i=0;i<math.max(this.length,other.length);i++){ | |
ret.add((i<this.length?this[i]:0) - (i<other.length?other[i]:0)); | |
} | |
return ret; | |
} | |
String toBinStr([int padLen = 0]) => this.map<String>((int e) => e.toRadixString(2).padLeft(padLen, "0")).join(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment