Size: 5526
Comment:
|
← Revision 10 as of 2020-06-02 22:07:41 ⇥
Size: 5629
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 15: | Line 15: |
{{{ | {{{#!sagecell |
Line 30: | Line 30: |
print "<html><h1 align=center>Zeros</h1></html>" print "<html><h2 align=center><font color='blue'>How many zeros?</font></h2></html>" |
pretty_print(html("<h1 align=center>Zeros</h1>")) pretty_print(html("<h2 align=center><font color='blue'>How many zeros?</font></h2>")) |
Line 34: | Line 34: |
def zeros(a=("",selector(buttons=True, nrows=1, values=['Reset'] + [1..B], default=1))): | def zeros(a=selector(buttons=True, nrows=1, values=['Reset'] + [1..B], default=1)): |
Line 37: | Line 37: |
print "<html><center>" | |
Line 39: | Line 38: |
H = "<center>" | |
Line 41: | Line 41: |
print "<font size=+3 color='red'>RIGHT</font>" | H += "<font size=+3 color='red'>RIGHT</font>" |
Line 54: | Line 54: |
print "<font size=+2 color='blue'>Wrong. Try again...</font>" print "</center>" print "<font size=+%s color='#333'>"%random.randrange(-2,5) print ' '*random.randrange(20) + '0'*n print "</font>" |
H += "<font size=+2 color='blue'>Wrong. Try again...</font>" H += "</center>" pretty_print(html(H)) H2 = "<font size=+%s color='#333'>%s</font>"%(random.randrange(-2,5),' '*random.randrange(20) + '0'*n) pretty_print(html(H2)) html("</font>") |
Line 60: | Line 61: |
print "<br><br><center>Score: %s rounds, Average time: %.1f seconds</center>"%( round, float(tm)/round) print "</html>" |
pretty_print(html("<br><br><center>Score: %s rounds, Average time: %.1f seconds</center>"%( round, float(tm)/round))) |
Line 68: | Line 68: |
{{{ | {{{#!sagecell |
Line 81: | Line 81: |
queens.remove(queen) | if queen in queens: queens.remove(queen) |
Line 97: | Line 98: |
print 'Queen at (%d,%d) is threatened by another queen'%(x,y) | print('Queen at (%d,%d) is threatened by another queen' % (x, y)) |
Line 101: | Line 102: |
show(matrix_plot(board, cmap='Oranges' )) |
show(matrix_plot(board, cmap='Oranges' )) |
Line 109: | Line 109: |
{{{ | {{{#!sagecell |
Line 134: | Line 134: |
}}} {{{ |
|
Line 143: | Line 142: |
print 'You have lost' | print('You have lost') |
Line 146: | Line 145: |
print 'Try to take the last item' | print('Try to take the last item') |
Line 148: | Line 147: |
print 'Previous situation:' print game_repr(nim) |
print('Previous situation:') print(game_repr(nim)) |
Line 152: | Line 151: |
print 'Your move:' print game_repr(nim) |
print('Your move:') print(game_repr(nim)) |
Line 155: | Line 154: |
print 'You win' | print('You win') |
Line 158: | Line 157: |
print 'My move:' | print('My move:') |
Line 160: | Line 159: |
myheap,myamount=move_nim(nim) | myheap, myamount = move_nim(nim) |
Line 163: | Line 162: |
myheap=min(heap_number for heap_number, heap_size in enumerate(nim) if heap_size>0) | myheap=min(heap_number for heap_number, heap_size in enumerate(nim) if heap_size > 0) |
Line 166: | Line 165: |
print game_repr(nim) | print(game_repr(nim)) |
Line 168: | Line 167: |
print 'I win' | print('I win') |
Line 170: | Line 169: |
print 'Please move again' | print('Please move again') |
Line 172: | Line 171: |
print 'Choose a heap and the amount to substract from that heap' print game_repr(nim) |
print('Choose a heap and the amount to substract from that heap') print(game_repr(nim)) |
Sage Interactions - Games and Diversions
goto interact main page
Zeros
Have you ever wished you could count the number of zero digits in a long number like Rainman?
by William Stein and Sequoia Lefthand
Queens on board
An interaction to play with the problem of placing eight queens on a board so that they do not threaten each other. This interaction exemplifies the use of persistent data, and the auto_update=False option coded by mhansen and included in sage 3.3. by Pablo Angulo
Nim
Play nim against a perfect opponent. This interaction exemplifies the use of persistent data, and the auto_update=False option coded by mhansen and included in sage 3.3. by Pablo Angulo