Friends Pairing Problem | Returns count of ways n people can remain single or paired up . ; Driver code
< ? php function countFriendsPairings ( $ n ) { $ a = 1 ; $ b = 2 ; $ c = 0 ; if ( $ n <= 2 ) { return $ n ; } for ( $ i = 3 ; $ i <= $ n ; $ i ++ ) { $ c = $ b + ( $ i - 1 ) * $ a ; $ a = $ b ; $ b = $ c ; } return $ c ; } $ n = 4 ; print ( countFriendsPairings ( $ n ) ) ; ? >