فهرست منبع

feat(xtintin): 新增一个 diff 算法,可计算慕容线索

dzp 3 سال پیش
والد
کامیت
29ba906f11
2فایلهای تغییر یافته به همراه53 افزوده شده و 0 حذف شده
  1. 1 0
      plugins/lib/xtintin/__init__.tin
  2. 52 0
      plugins/lib/xtintin/diff.tin

+ 1 - 0
plugins/lib/xtintin/__init__.tin

@@ -14,3 +14,4 @@ load-file plugins/lib/xtintin/debug.tin;
 load-file plugins/lib/xtintin/fp.tin;
 load-file plugins/lib/xtintin/answer.tin;
 load-file plugins/lib/xtintin/default.tin;
+load-file plugins/lib/xtintin/diff.tin;

+ 52 - 0
plugins/lib/xtintin/diff.tin

@@ -0,0 +1,52 @@
+#nop 两个字符串参数,其中一个比另一个多包含了一个子串,本函数可返回该子串(即任务信息);
+#function {diff} {
+    #local str1 {%1};
+    #local str2 {%2};
+
+    #list str1 {tokenize} {$str1};
+    #list str2 {tokenize} {$str2};
+
+    #local size1 {&str1[]}; 
+    #local size2 {&str2[]}; 
+
+    #if { $size1 < $size2 } {
+        #local tmp      {$str1};
+        #local str1     {$str2};
+        #local str2     {$tmp};
+        #local tmp      {$size1};
+        #local size1    {$size2};
+        #local size2    {$tmp};
+    };
+
+    #local idx {};
+    #loop {1} {$size2} {idx} {
+        #local ch1 {$str1[$idx]};
+        #local ch2 {$str2[$idx]};
+        #if { "$ch1" != "$ch2" } {
+            #break;
+        };
+    };
+
+    #local begin    {$idx};
+    #local end      {};
+    #math  end      {$size1 - $size2 + $begin - 1};
+    #local diff     {};
+    #loop {$begin} {$end} {idx} {
+        #local ch {$str1[$idx]};
+        #cat diff {$ch};
+    };
+
+    #return {$diff};
+};
+
+/*
+#alias {diff.test} {
+    #local str1 {洞中无丝毫光亮,脚华山的练功房下平整,便似走在石板路上一般。};
+    #local str2 {洞中无丝毫光亮,脚下平整,便似走在石板路上一般。};
+    #echo {STR1: $str1};
+    #echo {STR2: $str2};
+    #local diff {@diff{{$str1};{$str2}}};
+    #nop 会得到「华山的练功房」
+    #echo {DIFF: $diff};
+};
+*/