Do multiple "false" make a single "true"?

5 messages
Open this post in threaded view
|

Do multiple "false" make a single "true"?

 Consider this code: AnyShape=[[[1.87047, 2.34549, 0], [-0.667563, 2.92478, 0], [-2.70291, 1.30165, 0], [-2.70291, -1.30165, 0], [-0.667563, -2.92478, 0], [1.87047, -2.34549, 0], [3, 0, 0]], [[1.87047, 2.34549, 0.6], [-0.667563, 2.92478, 0.6], [-2.70291, 1.30165, 0.6], [-2.70291, -1.30165, 0.6], [-0.667563, -2.92478, 0.6], [1.87047, -2.34549, 0.6], [3, 0, 0.6]], [[1.87047, 2.34549, 1.2], [-0.667563, 2.92478, 1.2], [-2.70291, 1.30165, 1.2], [-2.70291, -1.30165, 1.2], [-0.667563, -2.92478, 1.2], [1.87047, -2.34549, 1.2], [3, 0, 1.2]], [[1.87047, 2.34549, 1.8], [-0.667563, 2.92478, 1.8], [-2.70291, 1.30165, 1.8], [-2.70291, -1.30165, 1.8], [-0.667563, -2.92478, 1.8], [1.87047, -2.34549, 1.8], [3, 0, 1.8]], [[1.87047, 2.34549, 2.4], [-0.667563, 2.92478, 2.4], [-2.70291, 1.30165, 2.4], [-2.70291, -1.30165, 2.4], [-0.667563, -2.92478, 2.4], [1.87047, -2.34549, 2.4], [3, 0, 2.4]], [[1.87047, 2.34549, 3], [-0.667563, 2.92478, 3], [-2.70291, 1.30165, 3], [-2.70291, -1.30165, 3], [-0.667563, -2.92478, 3], [1.87047, -2.34549, 3], [3, 0, 3]]]; echo("AA",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] );   //ECHO: "AA", [false, false, false, false, false] echo("BB",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] ? "TRue" : "FaLse");    //ECHO: "BB", "TRue" Line 2 and 3 contain identical test instructions. Does anyone know how to change line 3 so that multiple "true"s return a True_Condition, and one or more "false"s return a False_Condition? Thanks wolf
Open this post in threaded view
|

Re: Do multiple "false" make a single "true"?

 I think this does what you want:function allTrue(list, i = 1) =     i >= len(list) ? true                    : list[0][0] != list[0][i] ? false                                              : allTrue(list, i + 1);echo(allTrue(AnyShape) ? "TRue" : "FaLse");On 14 July 2017 at 07:10, wolf wrote:Consider this code: AnyShape=[[[1.87047, 2.34549, 0], [-0.667563, 2.92478, 0], [-2.70291, 1.30165, 0], [-2.70291, -1.30165, 0], [-0.667563, -2.92478, 0], [1.87047, -2.34549, 0], [3, 0, 0]], [[1.87047, 2.34549, 0.6], [-0.667563, 2.92478, 0.6], [-2.70291, 1.30165, 0.6], [-2.70291, -1.30165, 0.6], [-0.667563, -2.92478, 0.6], [1.87047, -2.34549, 0.6], [3, 0, 0.6]], [[1.87047, 2.34549, 1.2], [-0.667563, 2.92478, 1.2], [-2.70291, 1.30165, 1.2], [-2.70291, -1.30165, 1.2], [-0.667563, -2.92478, 1.2], [1.87047, -2.34549, 1.2], [3, 0, 1.2]], [[1.87047, 2.34549, 1.8], [-0.667563, 2.92478, 1.8], [-2.70291, 1.30165, 1.8], [-2.70291, -1.30165, 1.8], [-0.667563, -2.92478, 1.8], [1.87047, -2.34549, 1.8], [3, 0, 1.8]], [[1.87047, 2.34549, 2.4], [-0.667563, 2.92478, 2.4], [-2.70291, 1.30165, 2.4], [-2.70291, -1.30165, 2.4], [-0.667563, -2.92478, 2.4], [1.87047, -2.34549, 2.4], [3, 0, 2.4]], [[1.87047, 2.34549, 3], [-0.667563, 2.92478, 3], [-2.70291, 1.30165, 3], [-2.70291, -1.30165, 3], [-0.667563, -2.92478, 3], [1.87047, -2.34549, 3], [3, 0, 3]]]; echo("AA",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] ); //ECHO: "AA", [false, false, false, false, false] echo("BB",[ for (i=[1:len(AnyShape)-1])  AnyShape[0][0]==AnyShape[0][i] ] ? "TRue" : "FaLse");    //ECHO: "BB", "TRue" Line 2 and 3 contain identical test instructions. Does anyone know how to change line 3 so that multiple "true"s return a True_Condition, and one or more "false"s return a False_Condition? Thanks wolf -- View this message in context: http://forum.openscad.org/Do-multiple-false-make-a-single-true-tp21822.html Sent from the OpenSCAD mailing list archive at Nabble.com. _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org _______________________________________________ OpenSCAD mailing list [hidden email] http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Open this post in threaded view
|

Re: Do multiple "false" make a single "true"?

 Thanks, that worked a treat. Packaging a Test_Condition as a function never crossed my mind. wolf