question.rb
solution.rb
playground.rb
1 require_relative "../physics" 2 3 question :forty_minutes_out_speed do 4 kind :numerical 5 describes "A man walks on a straight road from his home to a market %{distance} away with a speed of " \ 6 "%{speed_there}. Finding the market closed, he instantly turns and walks back home with a speed of " \ 7 "%{speed_back}. %{average_speed} over the interval of time 0 to %{interval}, in km/h?" 8 given distance: "2.5 km" , speed_there: "5 km/h" , speed_back: "7.5 km/h" , interval: "40 min" 9 asks average_speed: "What is the average speed of the man" 10 end
1 require_relative "../questions/forty_minutes_out_speed" 2 require_relative "../science/motion_in_a_straight_line/velocity" 3 4 solve :forty_minutes_out_speed , using: Velocity do 5 objects :man 6 instants :start , :market , :later 7 man . goes ( :to_market , during: start .. market ) 8 man . goes ( :turning_back , during: market .. later ) 9 man . goes ( :walking , during: start .. later ) 10 take distance: man . position ( at: market ), speed_there: to_market . average_speed , 11 speed_back: turning_back . average_speed , interval: walking . time_taken 12 deduce_from "from his home" , man . position ( at: start ) => "0 km" 13 deduce_from "on a straight road" , to_market . average_velocity => to_market . average_speed 14 deduce_from "walks back home" , turning_back . average_velocity => - turning_back . average_speed 15 average_speed = walking . average_speed 16 answer average_speed :, in: "km/h" , figures: 4 17 conclusion "Average speed counts the whole path, out to the market and part of the way back, so it is " \ 18 "more than the size of the average velocity over the same time." 19 end
1 require_relative "../solutions/forty_minutes_out_speed" 2 3 play_with :forty_minutes_out_speed do 4 title "Forty Minutes Out: Speed" 5 end