fork download
  1. formulaIsRight <- function( x ){
  2. left <- x[1]*(10*x[2]+x[3])+100*x[4]+10*x[5]+x[6]
  3. right <- 1000*x[7]+100*x[8]+10*x[9]+x[10]
  4. return( left == right )
  5. }
  6.  
  7. # count <<- 0, permutation( 0:9, NULL ) で呼び出す
  8. permutation <- function( s, a ){
  9. if( length( s ) <= 0 ){
  10. if( formulaIsRight( a ) ){
  11. count <<- count + 1
  12. }
  13. }else{
  14. for( i in s ){
  15. Recall( s[ s != i ], c( a, i ) )
  16. }
  17. }
  18. }
  19.  
  20. count <<- 0
  21. permutation( 0:9, NULL )
  22. print( count ) # 350
Runtime error #stdin #stdout #stderr 5s 22968KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
/spoj/r_run: line 18:  3934 CPU time limit exceeded $R_HOME/bin/exec/R --vanilla --quiet --slave --encoding=UTF-8 --file=prog.r