Try searching for tickets on new.trainsplit.com
That site will offer you options in the £40 to £45 range involving a single from Ashford to London Victoria travelling via Brighton, and then an Advance (i.e. booked train only) ticket from London Kings X to Leuchars. Of course you can get faster journeys by taking a quicker (but more expensive) route to London. On the 30th, this will involve leaving London Kings X on the 1600 or 1700. There are three through trains per day from Kings X to Leuchars (at 10am, 2pm and 4pm although the 4pm doesn't run at weekends and weekend times can change due to engineering works): otherwise change at Edinburgh. If relevant, there are buses from Leuchars to St Andrews until after midnight on Mondays to Saturdays (about 11 minutes and about £3).