<![CDATA[check if there are consecutive numbers in list]]>
https://help.geogebra.org/topic/check-if-there-are-consecutive-numbers-in-list
Wed, 20 Jul 2016 21:46:47 +0000Wed, 20 Jul 2016 15:24:55 +0000Zend_Feed<![CDATA[Hi, try : nmbOfSeq=Sum[Join[Sequence[Sequence[nmbList(k) ≟ nmbList(l) + 1, k, 1, Length[nmbList]], l, 1, Length[nmbList]]]] ]]>
https://help.geogebra.org/topic/check-if-there-are-consecutive-numbers-in-list#comment-200258
Wed, 20 Jul 2016 16:46:10 +0000<![CDATA[Works fantastic! Thank you very much - now I have to study the GeoGebra syntax and commands you've used in the solution... I see the command Join[] that I've previously used only in the basic usage... Once again, I appreciate your help and quick response!]]>
https://help.geogebra.org/topic/check-if-there-are-consecutive-numbers-in-list#comment-200266
Wed, 20 Jul 2016 17:00:04 +0000<![CDATA[This is directly transferred JS code in GGB code! Fantastic! I knew for a two-dimensional array, but I did not really know how to get the number as an output value, and not a sequence ... I have never used the combination of commands Sum[Join[]] with the sequence - this solution is really very elegant one, and I learned a lot for the future applets! Thank you very much once again!]]>
https://help.geogebra.org/topic/check-if-there-are-consecutive-numbers-in-list#comment-200268
Wed, 20 Jul 2016 17:14:14 +0000<![CDATA[I've only changed a little bit code because it also counts appearance of equal numbers as a part of consecutive sequence - for example, if there are numbers 8. 8 and 9 in array the output value is 2 as well as if there are 7, 8 and 9 in array... So, I've used Unique[] command in the code: I've first created new array with Unique[] command and than used that new array in the code... Once again I'm so happy - I'm working on Three in a row game on the coordinate plane and want to avoid JS as much as I can for later workshops with my students...]]>
https://help.geogebra.org/topic/check-if-there-are-consecutive-numbers-in-list#comment-200270
Wed, 20 Jul 2016 17:51:15 +0000<![CDATA[Also CountIf and Zip are useful when dealing with lists Sum[Zip[CountIf[x==k+1,numList],k,numList]] Assuming unique numbers this might work: Length[Intersection[numList,numList+1]]]]>
https://help.geogebra.org/topic/check-if-there-are-consecutive-numbers-in-list#comment-200272
Wed, 20 Jul 2016 18:53:59 +0000<![CDATA[I came upon another problem based on the error that I had in my original JS code... The var nmbOfSeq is increased by 1 each time the pair of consecutive numbers occur which means that if there are, for example, numbers 1,5,6,9,10,15 in array the output will also be 2 (the value of the nmbOfSeq) as well as if there are numbers 1,5,6,7,10,15 in the array! As I'm creating the Three in a row game I need to find the exact sequence of three consecutive numbers, so I've came upon this solution based on the original Michel Iroir's solution: Sum[Sequence[numListUnique(k + 1) ≟ numListUnique(k) + 1 ∧ numListUnique(k + 2) ≟ numListUnique(k) + 2, k, 1, Length[numListUnique]]] and it works perfect! The output value is 1 in this case (if there are three consecutive numbers) or, in general, the output value is 2 less than the number of consecutive numbers in array... Now I'm going to try Zbynek's solution! Once again thanks both of you - you're really helped me a lot!]]>
https://help.geogebra.org/topic/check-if-there-are-consecutive-numbers-in-list#comment-200274
Wed, 20 Jul 2016 19:04:01 +0000<![CDATA[I just can't believe the simplicity of this solution!!! This is genius yet so simple and nice... Thanks!]]>
https://help.geogebra.org/topic/check-if-there-are-consecutive-numbers-in-list#comment-200280
Wed, 20 Jul 2016 21:37:33 +0000<![CDATA[Zbynek, your solution really rocks except when having two pairs of consecutive numbers which don't form a sequence of consecutive numbers... This is due to my original error in JS code on which you based your solution... Meaning, if there is numList = {2, 3, 6, 7, 12} the output will be 2 which is fine, but perhaps I didn't give enough detailed explanation at the beginning that I need to count only the sequences of 3 and more consecutive numbers... but never the pairs... Because I want to detect if three (in the game I'm developing now) points are collinear vertically, horizontally or diagonally and if their corresponding coordinates are consecutive (if so, I have three in a row...) I need more complex procedure and I can not just use the AreCollinear[] command because I don't know in advance the indexes of the points, whose coordinates are stored in a list, which are potentially collinear nor their coordinates... Anyway, once again - great and neat solution and a good idea which I will sooner or later use in some other code!]]>
https://help.geogebra.org/topic/check-if-there-are-consecutive-numbers-in-list#comment-200282
Wed, 20 Jul 2016 22:03:14 +0000