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] integer Current Day

The weekdays range from 1 to 7, 1 is Sunday and 7 is Saturday.

  • [input] integer Available 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

Stats:

CreatedFeb 20, 2017
PublishedFeb 20, 2017
Warriors Trained1041
Total Skips17
Total Code Submissions2418
Total Times Completed355
JavaScript Completions117
C# Completions61
Python Completions186
Ruby Completions26
Crystal Completions8
Total Stars10
% of votes with a positive feedback rating88% of 97
Total "Very Satisfied" Votes79
Total "Somewhat Satisfied" Votes12
Total "Not Satisfied" Votes6
Total Rank Assessments6
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • GiacomoSorbi Avatar
  • smile67 Avatar
  • hobovsky Avatar
  • Just4FunCoder Avatar
  • saudiGuy Avatar
Ad