Skip to content

Commit 002658e

Browse files
committed
Add graduate.rb
1 parent fcd3f0f commit 002658e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

bitset/graduate.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
FRUIT = { 1 => 'Orange', 2 => 'Banana', 4 => 'Cherry', 8 => 'Apple' } # => {1=>"Orange", 2=>"Banana", 4=>"Cherry", 8=>"Apple"}
4+
5+
def mask_fruit(a, b)
6+
a | b # => 9
7+
end # => :mask_fruit
8+
9+
def unmask_fruit(masked)
10+
FRUIT.select { |k, _| (masked | k) == masked } # => {1=>"Orange", 8=>"Apple"}
11+
end # => :unmask_fruit
12+
13+
mask = mask_fruit 1, 8 # => 9
14+
unmask_fruit mask # => {1=>"Orange", 8=>"Apple"}
15+
16+
17+
def graduate(semester, taken)
18+
19+
end # => :graduate
20+
21+
"4 4 4 4".split.map(&:to_i) # => [4, 4, 4, 4]
22+
23+

0 commit comments

Comments
 (0)