…  
…  
1169  
1169  
1170  
1170  
1171  
1171  
1172  # Experiments 
1172  # Experiments 
1173  
1173  
1174  # It is important that these subroutines using sort are evaluated before 


1175  # the problem template is evaluated. 


1176  # Once the problem template has a "my $a;" susequent sort routines will not work. 


1177  # 


1178  # PGsort can be used as a slightly slower but safer sort within problems. 


1179  


1180  


1181  


1182  =head2 PGsort 


1183  


1184  Because of the way sort is optimized in Perl, the symbols $a and $b 


1185  have special significance. 


1186  


1187  C<sort {$a<=>$b} @list> 


1188  C<sort {$a cmp $b} @list> 


1189  


1190  sorts the list numerically and lexically respectively. 


1191  


1192  If C<my $a;> is used in a problem, before the sort routine is defined in a macro, then 


1193  things get badly confused. To correct this, the following macros are defined in 


1194  dangerougMacros.pl which is evaluated before the problem template is read. 


1195  


1196  PGsort sub { $_[0] <=> $_[1] }, @list; 


1197  PGsort sub { $_[0] cmp $_[1] }, @list; 


1198  


1199  provide slightly slower, but safer, routines for the PG language. (The subroutines 


1200  for ordering are B<required>. Note the commas!) 


1201  


1202  =cut 


1203  


1204  


1205  


1206  # sub PGsort { 


1207  # my $sort_order = shift; 


1208  # die "Must supply an ordering function with PGsort: PGsort sub {\$a cmp \$b }, \@list\n" unless ref($sort_order) eq 'CODE'; 


1209  # sort {&$sort_order($a,$b)} @_; 


1210  # } 


1211  # Moved to translate.pl 


1212  # For some reason it still caused 


1213  # trouble here when there was 


1214  # more than one ans_eval in ANS() 


1215  # Noone knows why? 


1216  


1217  # This allows the use of i for imaginary numbers 
1174  # This allows the use of i for imaginary numbers 
1218  # one can write 3 +2i rather than 3+2i() 
1175  # one can write 3 +2i rather than 3+2i() 
1219  # 
1176  # 
1220  
1177  
1221  
1178  