Hi, I'm new to python, and I'm not sure if this is the place to post
this kind of question; so feel free to tell me if I should take this
elsewhere.
So, to start me off on python, I decided to put together a little
script to test the probabilities of rolling certain combinations of
dice. Below is my code for checking for a full house (when rolling
with 5 dice). A roll is a list, eg [1, 3, 5, 1, 4] (this example is
not a full house)
def removeAll(eleme nt, num2Rem, list):
l = list[:]
for num in range(0, num2Rem):
l.remove(elemen t)
return l
def isfullHouse(rol l):
for die in range(1,7):
if roll.count(die) ==3:
l = removeAll(die, 3, roll)
if l[0]==l[1]:
return 1
return 0
My questions is this: is there a better way to do this? A way that's
more natural to python, or just more efficient perhaps?
ps. A roll of [1, 2, 1, 1, 2] is a full house (three of one kind and
two of another)
Jul 19 '05
10 8752
Wow... This is amazing, I didn't know there were so many way's of
doing this! Thank you every one for all your suggestions. I
particularly like the sorting counting ones.
And no, Roy, this isn't a home work assignment, at the moment all of
those contain php and java RMI. :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: lennart |
last post by:
Hi,
For a website i'm looking for a script which can check the
availabililty of several users for an $event.
There are several apps that does the job the other way: checking the
availability of an object (eg a house, car) and bind it to a person.
That's not what i looking for.
In my case, you've to make an event (meeting) and add some users the
|
by: Patient Guy |
last post by:
Does anyone have any coding rules they follow when doing argument checking?
When arguments fail during check, do you return from the call with an
ambiguous return value, or do you throw exceptions?
|
by: brian.j.parker |
last post by:
I inherited an application (or two) that run on SQL Server 6.5, which I
haven't used in years, and am having a problem. I get the error:
------------------------------------------------------------------------
Can't allocate space for object 'Syslogs' in database 'master' because
the 'logsegment' segment is full. If you ran out of space in Syslogs,
dump the transaction log. Otherwise, use ALTER DATABASE or
sp_extendsegment to increase...
|
by: lawrence k |
last post by:
I've made it habit to check all returns in my code, and usually, on
most projects, I'll have an error function that reports error messages
to some central location. I recently worked on a project where someone
suggested to me I was spending too much time writing error messages,
and that I was therefore missing the benefit of using a scripting
language. The idea, apparently, is that the PHP interpreter writes all
the error messages that are...
|
by: jacob navia |
last post by:
We hear very often in this discussion group that
bounds checking, or safety tests are too expensive
to be used in C.
Several researchers of UCSD have published an interesting
paper about this problem.
http://www.jilp.org/vol9/v9paper10.pdf
Specifically, they measured the overhead of a bounds
| |
by: Gemmalouise1988 |
last post by:
Hi everyone,
My most important college assignment to date seems pretty basic on the outside
but I'm sure this will interest a few of you.
If you see this document:
http://stair.stcoll.ac.uk/jowen/btecsd/pconc/docs/IVA1.pdf and take a brief look
to see what it's all about, (a fixtures and points system for a school) take a
look on page 3, to see the list of students with their names, house and class.
Then look on page 2 to see the...
|
by: John |
last post by:
Hi
How can I check for existence of a certain table by name in and access
database and if the table exists find the number of records in it?
I guess I can access this information by setting up a dataset for the
database but I am wondering if there is a quick way to find this.
Thanks
|
by: Stef Mientki |
last post by:
hello,
In the code below, I can build a large street like this:
large_street = house * 25
but not a small street. like this:
small_street = 5 * house
Why is this different ?
And more interesting, how do I get the right results ?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |