Slightlly OT - Bingo问题 [英] Slightlly OT - Bingo problem

查看:88
本文介绍了Slightlly OT - Bingo问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可能已经提到我在当地的一个b
学院开设了一个PHP入门课程(非常基础 - 我不是PHP专家)。好吧,我的一个学生是

表现得非常好,所以我给他做了一些扩展工作。任务是使用

PHP生成随机宾果卡。标准英国卡有九排

和三列。每行有五个数字。所有数字都是不同的,在90美元的游泳池中。


我让我的学生设计一张卡片。几天后他回来了

用一个产生六张牌的解决方案,使用90个号码中的每一个

一次。或者我认为。


虽然我已经设置了问题但我没有自己编写解决方案,所以我设置了它的
。我尝试了各种方法,但无法获得一个每次都可靠地工作的脚本

。通常情况下,我无法获得适合的数字。我最终通过蛮力解决了这个问题,即

我放弃了所有不起作用的尝试。见
http://www.ckdog.co .uk / php / test / bingo.php 我的解决方案

代码在这里:
http://www.ckdog.co.uk/php/test/bingo_code.phps


我还是很聪明,因为我觉得我的学生提出了比我更好的解决方案,所以我再看看他的。他有同样的问题,偶尔,最后一行不完整。这有点像卡片游戏的耐心,有时候它没有用。如果你是读这个克雷格的b $ b,请不要看我的解决方案:-)


我的问题是这个。是否有可能编写一个算法,

将以随机的方式将所有90个数字放在矩阵中,因为尝试失败,
不必循环?


请帮助这位可怜的讲师比他的学生领先一步。 :-)

-

Geoff Berrow(把猫放到电子邮件中)

它只是Usenet,没有人死。

我的意见,而不是我的委员会。

简单的RFD http://www.ckdog.co.uk/rfdmaker/

I may have mentioned that I run an Introduction to PHP course at a local
college (very basic - I''m no PHP expert). Well, one of my students was
doing really well so I set him some extension work. The task was to use
PHP to generate a random bingo card. The standard UK card has nine rows
and three columns. Each row has five numbers. All numbers are
different, out of a pool of 90.

I asked my student to design one card. He came back a few days later
with a solution that generated six cards, using each of the90 numbers
just once. Or so I thought.

Although I''d set the problem I had not coded the solution myself so I
set to it. I tried various methods but could not get a script which
would work reliably every time. More often than not I could not get all
the numbers to fit. I eventually solved the problem by brute force, ie
I discard all attempts that don''t work. See
http://www.ckdog.co.uk/php/test/bingo.php for my solution
Code is here:
http://www.ckdog.co.uk/php/test/bingo_code.phps

I was still smarting because I thought my student had come up with a
better solution than me so I took another look at his. He had the same
problem, occasionally, the last line was not complete. It''s a bit like
the card game patience, sometimes it doesn''t work out. If you are
reading this Craig, don''t look at my solution :-)

The question I have is this. Is it possible to write an algorithm that
will place all 90 numbers in the matrix in a random fashion that will
not have to loop because of failed attempts?

Please help this poor lecturer stay one step ahead of his students. :-)
--
Geoff Berrow (put thecat out to email)
It''s only Usenet, no one dies.
My opinions, not the committee''s, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/

推荐答案

Geoff Berrow写道:
Geoff Berrow wrote:
我可能已经提到我在当地的一所学院开设了PHP课程入门(非常基础 - 我不是PHP专家)。好吧,我的一个学生做得很好,所以我为他做了一些推广工作。任务是使用PHP生成随机宾果卡。标准英国卡有九排
和三列。每行有五个数字。 90.


我猜你的意思是三行九列(所以每个5个数字) $ b行每张卡最多15个数字。)

我让我的学生设计一张卡片。几天后他带着一个生成六张牌的解决方案回来了,只使用了90个号码中的每一个。或者我认为。


< snip>

我的问题是这个。是否有可能编写一种算法,将所有90个数字以随机方式放置在矩阵中,由于尝试失败而无需循环?


这个解决方案对我来说似乎微不足道,所以它一定是错的:


1.生成90个数字的随机排列。 />
(Google知道如何操作。)


2.将排列分成15个数字的6个区块。


3.对每个区块进行排序。


4.将每个区块分配给一张卡。


我错过了什么吗?
<请帮助这位可怜的讲师比他的学生领先一步。 :-)
I may have mentioned that I run an Introduction to PHP course at a local
college (very basic - I''m no PHP expert). Well, one of my students was
doing really well so I set him some extension work. The task was to use
PHP to generate a random bingo card. The standard UK card has nine rows
and three columns. Each row has five numbers. All numbers are
different, out of a pool of 90.
I guess you mean three rows and nine columns (so that 5 numbers in each
row sum up to 15 numbers per card).

I asked my student to design one card. He came back a few days later
with a solution that generated six cards, using each of the90 numbers
just once. Or so I thought.

<snip>

The question I have is this. Is it possible to write an algorithm that
will place all 90 numbers in the matrix in a random fashion that will
not have to loop because of failed attempts?
This solution seems trivial to me, so it must be wrong:

1. Generate a random permutation of the 90 numbers.
(Google knows how to do it.)

2. Split the permutation in 6 blocks of 15 numbers.

3. Sort each block.

4. Assign each block to a card.

Am I missing something?

Please help this poor lecturer stay one step ahead of his students. :-)



.oO(Geoff Berrow)
.oO(Geoff Berrow)
我的问题是这个。是否有可能编写一种算法,将所有90个数字以随机方式放置在矩阵中,由于尝试失败而无需循环?
The question I have is this. Is it possible to write an algorithm that
will place all 90 numbers in the matrix in a random fashion that will
not have to loop because of failed attempts?



有一种数学方法可以做到这一点(不记得确切,

必须查找它),但PHP已经能够做到这一点。


一个快速的肮脏黑客:


<?php

//懒得编写HTML表格。 ..; -D

header(''Content-type:text / plain'');


//创建包含90个数字的数组,随机排序



There''s a mathematical approach for doing that (can''t remember exactly,
would have to look it up), but PHP is already capable of doing it.

A quick ''n dirty hack:

<?php
// too lazy to write HTML tables ... ;-D
header(''Content-type: text/plain'');

// create array with 90 numbers, ordered randomly


numbers = range(1,90);

shuffle(
numbers = range(1, 90);
shuffle(


这篇关于Slightlly OT - Bingo问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆