Обсуждение:Scratch/Данные

Материал из Letopisi.Ru — «Время вернуться домой»
Перейти к: навигация, поиск

Compiling the Differences

Two variables may typically have differences in characters. For example, of variable 1 has a value of "potato" and variable 2 has a value of "tomato" the differences would be "pm" because those are the characters not shared by both variables. Only variable 1 contains a "p" and oinly variable 2 contains an "m". The following custom block analyzes the two strings specified by the block definition's parameters and compiled a variable of characters unshared between the two variables.

definecomparedifferencesofstr1tostr2deleteallofcharssetito1setdifferenciestorepeatlengthofstr1addletteriofstr1tocharschangeiby1setito1repeatlengthofstr2ifnotcharscontainsletteriofstr2 ?thensetjto1setmatchto0repeatlengthofdifferenciesifletterjofdifferencies=letteriofstr2thensetmatchto1changejby1ifmatch=0thensetdifferenciestojoindifferenciesletteriofstr2changeiby1deleteallofcharssetito1repeatlengthofstr2addletteriofstr2tocharschangeiby1setito1repeatlengthofstr1ifnotcharscontainsletteriofstr1 ?thensetjto1setmatchto0repeatlengthofdifferenciesifletterjofdifferencies=letteriofstr1thensetmatchto1changejby1ifmatch=0thensetdifferenciestojoindifferenciesletteriofstr1changeiby1

Compiling the Similarities

A script that reports the similarities in two strings is following:

definecomparesimilaritiesofstr1tostr2deleteallofcharssetito1setsimilaritiestosetmatchto0repeatlengthofstr1addletteriofstr1tocharschangeiby1setito1repeatlengthofstr2ifcharscontainsletteriofstr2 ?thensetjto1repeatlengthofsimilaritiesifletterjofsimilarities=letteriofstr2thensetmatchto1changejby1ifmatch=0thensetsimilaritiestojoinsimilaritiesletteriofstr2changeiby1
Персональные инструменты
Инструменты