Problem 1: CONCERNING A CHECK (536 Puzzles and Curious Problems, Henry Ernest, Dudeney)

May 28, 2014, 1:10 PM

# Problem 1: CONCERNING A CHECK (536 Puzzles and Curious Problems, Henry Ernest, Dudeney)

# Problem:
# A man went into a bank to cash a check. 
# In handing over the money the cashier, by mistake, gave him dollars for cents and cents for dollars. 
# He pocketed the money without examining it, and spent a nickel on his way home. 
# He then found that he possessed exactly twice the amount of the check. 
# He had no money in his pocket before going to the bank. 
# What was the exact amount of that check?

solution=FALSE
checkdollar=0
repeat {
  if(solution==TRUE) break
  checkdollar=checkdollar+1
  for (i in 0:99) {
    checkcent=i
    check=checkdollar+0.01*checkcent
    cashcent=checkdollar
    cashdollar=checkcent
    cashcent=cashcent-5
    cash=cashdollar+0.01*cashcent
    if(2*check==cash) {
      print(check)
      solution=TRUE
      break}
  }
}
[1] 31.63