Playing cards: Difference between revisions

Content added Content deleted
(→‎{{header|Python}}: Add another example that uses Poker hand analyser#Python,)
(Updated to work for Go Fish)
Line 1,035: Line 1,035:
=={{header|Erlang}}==
=={{header|Erlang}}==
The -spec() is a type declaration. It is optional, but helps humans to understand complex data types and the Erlang type verifier (dialyzer) to check the code.
The -spec() is a type declaration. It is optional, but helps humans to understand complex data types and the Erlang type verifier (dialyzer) to check the code.

This module is used by [[Go_Fish]].
<lang Erlang>
<lang Erlang>
-module( playing_cards ).
-module( playing_cards ).


-export( [deal/2, deal/3, deck/0, print/1, shuffle/1, task/0] ).
-export( [deal/2, deal/3, deck/0, print/1, shuffle/1, sort_pips/1, sort_suites/1, task/0] ).


-record( card, {pip, suite} ).
-record( card, {pip, suite} ).
Line 1,052: Line 1,054:


shuffle( Deck ) -> knuth_shuffle:list( Deck ).
shuffle( Deck ) -> knuth_shuffle:list( Deck ).

sort_pips( Cards ) -> lists:keysort( #card.pip, Cards ).

sort_suites( Cards ) -> lists:keysort( #card.suite, Cards ).


task() ->
task() ->