Clear(); Print ("Beginning demo program: test_1_3.txt\n\n"); Print ("This demonstrates the use of the following procedures:\n"); Print (" IntegerToList( intIn, length, base )\n"); Print (" ListToInteger( vector, length, base )\n"); Print (" ListToMultiset( list )\n"); Print (" MultisetToList( multiset, listlength )\n\n"); Sleep(5); # Let's try to represent some integers as lists int1 := IntegerToList( 21, 2, 10 ); int2 := IntegerToList( 103, 5, 10 ); int3 := IntegerToList( 1451, 2, 10 ); Print ("Let's try to represent some integers as lists in base 10.\n\n"); Print (" int1 := IntegerToList( 21, 2, 10 )\n", int1, "\n\n"); Print (" int2 := IntegerToList( 103, 5, 10 )\n", int2, "\n\n"); Print (" int3 := IntegerToList( 1451, 2, 10 )\n", int3, "\n\n"); Print ("\n"); Sleep(8); # Okay, now how about with different bases? int1 := IntegerToList( 21, 5, 3 ); int2 := IntegerToList( 103, 10, 2 ); int3 := IntegerToList( 1451, 4, 16 ); Print ("Okay, same trick with different bases.\n\n"); Print (" int1 := IntegerToList( 21, 5, 3 )\n", int1, "\n\n"); Print (" int2 := IntegerToList( 103, 10, 2 )\n", int2, "\n\n"); Print (" int3 := IntegerToList( 1451, 4, 16 )\n", int3, "\n\n"); Print ("\n"); Sleep(8); # Let's go backward... list1 := [ 0, 0, 0, 1, 1, 0, 0, 1, 1, 1 ]; list2 := [ 0, 5, 10, 12 ]; Print ("Let's go backward...\nStarting with:\n\nlist1 := "); PrintArray (list1); Print ("list2 := "); PrintArray (list2); Print ("\n"); int1 := ListToInteger( list1, 2 ); int2 := ListToInteger( list2, 16 ); int3 := ListToInteger( list1, 3 ); Print (" int1 := ListToInteger( list1, 2 );\n", int1, "\n\n"); Print (" int2 := ListToInteger( list2, 16 );\n", int2, "\n\n"); Print (" int3 := ListToInteger( list1, 3 );\n", int3, "\n\n"); Print ("\n"); Sleep(10); # So basically, we can do really trivial things in # really creative ways: int1 := ListToInteger( IntegerToList( 1000, 10, 3 ), 3); Print ("Now we change 1000 to a list and immediately change back:\n"); Print (" int1 := ListToInteger( IntegerToList( 1000, 10, 3 ), 3);\n"); Print (int1, "\n\n"); Sleep(3); # Or interesting truncations: int1 := ListToInteger( IntegerToList( 1000, 4, 3 ), 3); Print ("We can do the same thing but truncate the list before we\n"); Print ("reconstruct the integer.\n"); Print (" int1 := ListToInteger( IntegerToList( 1000, 4, 3 ), 3);\n"); Print (int1, "\n\n"); Sleep(5); # Now we can test our multiset functions. list := [1, 2, 1, 0, 0, 3]; mult := ListToMultiset( list ); Print ("Start with a list:\n list := ", list, "\n"); Print (" mult := ListToMultiSet( list );\n", mult, "\n\n"); Sleep(3); # and back... newlist := MultisetToList( mult, Size(list) ); Print ("And back to a list:\n"); Print (" newlist := MultisetToList( mult, (Size(list) );\n"); Print ( newlist, "\n\n" );