Skip to content

Instantly share code, notes, and snippets.

@halka9000stg
Created August 23, 2023 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halka9000stg/552802bbd114445333046194efadfb9d to your computer and use it in GitHub Desktop.
Save halka9000stg/552802bbd114445333046194efadfb9d to your computer and use it in GitHub Desktop.
T Material Stones
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