fork download
  1. library(magrittr)
  2.  
  3. mult <- function(a, b) {
  4. result <- 0
  5. shift <- 0
  6. while(b) {
  7. if(b %% 2) {
  8. result %<>% bitwXor(bitwShiftL(a, shift))
  9. }
  10. b %<>% bitwShiftR(1)
  11. shift <- shift + 1
  12. }
  13. return(result)
  14. }
  15.  
  16. runIt <- function(inputString) {
  17. inputs <- read.table(textConnection(inputString))
  18. result <- apply(inputs, 1, function(x) paste0(x[1], '@', x[2], '=', mult(x[1], x[2])))
  19. writeLines(result)
  20. }
  21.  
  22.  
  23.  
  24. inputString <- "1 2
  25. 9 0
  26. 6 1
  27. 3 3
  28. 2 5
  29. 7 9
  30. 13 11
  31. 5 17
  32. 14 13
  33. 19 1
  34. 63 63"
  35.  
  36. invisible(runIt(inputString))
Success #stdin #stdout 0.17s 176448KB
stdin
Standard input is empty
stdout
1@2=2
9@0=0
6@1=6
3@3=5
2@5=10
7@9=63
13@11=127
5@17=85
14@13=70
19@1=19
63@63=1365