7 kyu
Simple Fun #149: Next Day Of Week
186 of 355myjinxin2015
Description:
Task
You have set an alarm for some of the weekdays.
Days of the week are encoded in binary representation like this:
0000001 - Sunday
0000010 - Monday
0000100 - Tuesday
0001000 - Wednesday
0010000 - Thursday
0100000 - Friday
1000000 - Saturday
For example, if your alarm is set only for Sunday and Friday, the representation will be 0100001
.
Given the current day of the week, your task is to find the day of the week when the alarm will ring next time.
Input/Output
[input]
integerCurrent Day
The weekdays range from 1 to 7, 1 is Sunday and 7 is Saturday.
[input]
integerAvailable Weekdays
An integer between 1 and 127, inclusive (which means the alarm will ring at least once per week). Days of the week are encoded in its binary representation.
[output]
an integer
The next day available. The weekday format is same as Current Day
.
Example
For Current Day = 4, Available Weekdays = 42
, the result should be 6
.
Current Day = 4 means current day is Wednesday
Available Weekdays = 42, convert to binary is "0101010"
So the next day the alarm will ring is Friday (6)
Puzzles
Similar Kata:
Stats:
Created | Feb 20, 2017 |
Published | Feb 20, 2017 |
Warriors Trained | 1041 |
Total Skips | 17 |
Total Code Submissions | 2418 |
Total Times Completed | 355 |
JavaScript Completions | 117 |
C# Completions | 61 |
Python Completions | 186 |
Ruby Completions | 26 |
Crystal Completions | 8 |
Total Stars | 10 |
% of votes with a positive feedback rating | 88% of 97 |
Total "Very Satisfied" Votes | 79 |
Total "Somewhat Satisfied" Votes | 12 |
Total "Not Satisfied" Votes | 6 |
Total Rank Assessments | 6 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |