81. building a deck of cards
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces)
82. building a deck of cards
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces)
=> [[“S”, 2], [“S”, 3], …, [“S”, “A”],
[“C”, 1], …, [“C”, “A”], …]
83. building a deck of cards
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces)
=> [“S2”, “S3”, …, “SA”, “C1”, …, “C2”,
…]
84. join(sep=$,) -> str
Returns a string created by converting each element
of the array to a string, seperated by sep.
[ “a”, “b”, “c”].join
=> “abc”
[ “a”, “b”, “c”].join(“-”)
=> “a-b-c”
85. building a deck of cards
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces)
deck = deck.map do |pair|
pair.join
end
86. building a deck of cards
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces)
deck.map! do |pair|
pair.join
end
88. building a deck of cards
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces)
deck.map! do |pair|
pair.join
end
89. building a deck of cards
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces)
deck.map! { |pair| pair.join }
90. building a deck of cards
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces).map(&:join)
91. generating poker hands
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces).map(&:join)
92. sample(n) -> new_ary
Choose n random elements from the array.
The elements are chosen by using random
and unique indices in order to ensure that an
element doesn’t repeat itself unless the array
already contained duplicate elements.
93. generating poker hands
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces).map(&:join)
deck.sample(5)
94. generating poker hands
suits = %w(S C H D)
faces = (2..10).to_a + %w(J Q K A)
deck = suits.product(faces).map(&:join)
deck.sample(5)
=> [“C2”, “D5”, “S7”, “D8”, “C8”]
97. Count of URL Access Frequency
The map function processes logs of web page
requests and outputs <URL, 1>. The reduce
function adds together all values for the same
URL and emits a <URL, total count> pair.
from Introduction to Parallel Programming and MapReduce (Google)
100. Count of URL Access Frequency
The map function processes logs of web page
requests and outputs <URL, 1>. The reduce
function adds together all values for the same
URL and emits a <URL, total count> pair.
from Introduction to Parallel Programming and MapReduce (Google)
102. Count of URL Access Frequency
The map function processes logs of web page
requests and outputs <URL, 1>. The reduce
function adds together all values for the same URL
and emits a <URL, total count> pair.
from Introduction to Parallel Programming and MapReduce (Google)
110. Count of URL Access Frequency
The map function processes logs of web page
requests and outputs <URL, 1>. The reduce
function adds together all values for the same URL
and emits a <URL, total count> pair.
from Introduction to Parallel Programming and MapReduce (Google)