所有可能的集合(3 位)的排列,包括零

我正在创建一个小型游戏程序,其中有两种类型的游戏。 和。对于每个游戏,都有一个固定的图表集。SingleDouble


单张图表


        '128',   '129',  '120',  '130',  '140',   '123',  '124',  '125',  '126',  '127',

        '137',   '138',  '139',  '149',  '159',   '150',  '160',  '134',  '135',  '136',

        '146',   '147',  '148',  '158',  '168',   '169',  '179',  '170',  '180',  '145',

        '236',   '156',  '157',  '167',  '230',   '178',  '250',  '189',  '234',  '190',

        '245',   '237',  '238',  '239',  '249',   '240',  '269',  '260',  '270',  '235',

        '290',   '246',  '247',  '248',  '258',   '259',  '278',  '279',  '289',  '280',

        '380',   '345',  '256',  '257',  '267',   '268',  '340',  '350',  '360',  '370',

        '470',   '390',  '346',  '347',  '348',   '358',  '359',  '369',  '379',  '389',

        '489',   '480',  '490',  '356',  '357',   '349',  '368',  '378',  '450',  '460',

        '579',   '570',  '580',  '590',  '456',   '367',  '458',  '459',  '469',  '479',

        '560',   '589',  '670',  '680',  '690',   '457',  '467',  '468',  '478',  '569',

        '678',   '679',  '689',  '789',  '780',   '790',  '890',  '567',  '568',  '578',


当我选择一个并输入数字0123456789时,它返回与 相关的整个集合。对于这种情况,它返回集合。Single(any sequence(sorted & unsorted), min 4 digits & max 10 digits from 0-9, repeated)Single Chart120


如果我选择并输入相同的数字0123456789它将返回与 ONLY 相关的所有集合。doubleDouble Chart


目前,我正在为游戏使用一种解决方案,这里给出了排列 - 所有可能的数字集,但在一些集合中,它被返回,就像但它必须是Single001100


我也找不到游戏的解决方案。我尝试什么 :Double


至尊宝的传说
浏览 83回答 2
2回答

交互式爱情

您可以通过创建正则表达式对数字进行preg_match,例如:/^[235046]+$/这意味着我们试图匹配一个从开始(插入符号)到结束(美元符号)的数字(含义,或等)的字符串。如果我们找到匹配项,我们会将它们收集到另一个数组中。235046235^$片段:<?php$digits = '235046';$single_chart_filtered = [];foreach($single_chart as $chart_value){&nbsp; &nbsp; if(preg_match("/^[$digits]+$/",$chart_value) === 1){&nbsp; &nbsp; &nbsp; &nbsp; $single_chart_filtered[] = $chart_value;&nbsp; &nbsp; }}print_r($single_chart_filtered);$double_chart_filtered = [];foreach($double_chart as $chart_value){&nbsp; &nbsp; if(preg_match("/^[$digits]+$/",$chart_value) === 1){&nbsp; &nbsp; &nbsp; &nbsp; $double_chart_filtered[] = $chart_value;&nbsp; &nbsp; }}演示:https://3v4l.org/jChvm

噜噜哒

001 是0123456789的有效组合。您需要过滤数组以查找可能的集合:// simple artificial setup$single = [111,222,333,444,555];function generatePossibleSet($input) { return [000,001,010,100,011,101,110,111]; }$possibleSet = generatePossibleSet("01");$set = $single;// just interscet the picked set with the possible set$set = array_intersect($set, $possibleSet);此示例将给出 [111] - 集合列表中 0 和 1 的唯一有效组合。
打开App,查看更多内容
随时随地看视频慕课网APP