Post Reply 
New Casio fx-9860 GIII model
10-05-2020, 04:13 PM
Post: #47
RE: New Casio fx-9860 GIII model
(10-05-2020 12:25 PM)toml_12953 Wrote:  Would you post the exact program you used to test? For a valid benchmark, the same program should be used on all the tested calculators (or as close as possible). Here's the nqueens program I used:

Sure. FWIW I think yours stops at the first solution found. Mine starts by asking what size board you want to work with and then finds all the solutions (92 in the case of an 8×8 board)

Code:
n=0
while n<1 or n>10:
    n = int(input("n= (1 to 10) "))

sol = [ 0 ] * n

nodes=0
solutions=0
row=0
col=0

# Keep on doing this until we try and go "back" beyond the first row
while row >= 0:
    
    # Keep on while we're in the range 0..n-1 for the column
    while col < n:
    
        # increment the count of nodes examined
        nodes += 1

        # Find out if this space is safe.
        safe=True
        if row > 0:
            for testrow in range(row):
                # If there's something in the same column or on the same diagonal then we're not safe
                if sol[testrow]==col or abs(sol[testrow]-col)==(row-testrow):
                    safe=False
                    break
        
        if safe:
            # Mark the space as taken
            sol[row] = col
            # Are we on the final row?
            if row==(n-1):
                # Yes, then we have a solution
                solutions += 1;
                # print(sol)
            else:
                # If not then try solving as of col 0 in the next row
                col=0;
                row += 1
                continue
                
        # move to the next column
        col += 1
        
        # end while col < n

    # Nothing more in this column so we need to go back to the previous row
    row -= 1;
    # ...and try on the next column
    if row >= 0:
        col=sol[row]+1
    
    #end while row >= 0

print()
print(n,"×",n," board")
print(solutions, "solutions")
print(nodes, "nodes tested")

There are only 10 types of people in this world. Those who understand binary and those who don't.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
New Casio fx-9860 GIII model - Coco - 01-09-2020, 04:34 PM
RE: New Casio fx-9860 GIII model - Hlib - 01-09-2020, 08:02 PM
RE: New Casio fx-9860 GIII model - Coco - 02-02-2020, 04:15 PM
RE: New Casio fx-9860 GIII model - lrdheat - 03-06-2020, 03:22 PM
RE: New Casio fx-9860 GIII model - Dands - 03-08-2020, 04:07 AM
RE: New Casio fx-9860 GIII model - klesl - 03-08-2020, 12:25 PM
RE: New Casio fx-9860 GIII model - lrdheat - 03-10-2020, 05:51 PM
RE: New Casio fx-9860 GIII model - klesl - 05-14-2020, 04:30 PM
RE: New Casio fx-9860 GIII model - grsbanks - 10-05-2020 04:13 PM
RE: New Casio fx-9860 GIII model - lrdheat - 10-04-2020, 11:34 PM
RE: New Casio fx-9860 GIII model - pier4r - 10-06-2020, 08:26 PM
RE: New Casio fx-9860 GIII model - vaklaff - 10-11-2020, 06:29 PM
RE: New Casio fx-9860 GIII model - lrdheat - 10-15-2020, 03:43 PM
RE: New Casio fx-9860 GIII model - lrdheat - 10-18-2020, 11:26 PM
RE: New Casio fx-9860 GIII model - Druzyek - 10-21-2020, 12:47 AM
RE: New Casio fx-9860 GIII model - DiTBho - 01-01-2021, 01:25 PM
RE: New Casio fx-9860 GIII model - critor - 01-01-2021, 08:37 PM
RE: New Casio fx-9860 GIII model - robve - 01-16-2022, 03:30 PM
RE: New Casio fx-9860 GIII model - critor - 01-19-2022, 08:36 PM
RE: New Casio fx-9860 GIII model - robve - 01-21-2022, 03:28 PM



User(s) browsing this thread: 1 Guest(s)