26
5
Challenge
Given a three digit octal permissions number, output the permissions that it grants.
chmod
On UNIX OSes file permissions are changed using the chmod
command. There are few different ways of using chmod, but the one we will focus on today is using octal permissions.
The three digits in the permissions number represent a different person:
- The first digit represents the permissions for the user
- The second digit represents the permissions for the group
- The last digit represents the permissions for others
Next, each digit represents a permission as shown below in:
Key: number | permission
7 | Read Write and Execute
6 | Read and Write
5 | Read and Execute
4 | Read only
3 | Write and Execute
2 | Write only
1 | Execute only
0 | None
Input
The input will be the three digit number as a string, e.g.:
133
or
007
This will be passed either via STDIN or via function arguments.
Output
Your output should be the different permissions for each of the user, the group and the others. You must display this information like so:
User: ddd
Group: ddd
Others: ddd
Where there are three spaces after User
, two spaces after Group
and one space after Others
. You replace ddd
with the permissions information.
Your output may be to STDOUT or as a returned string.
Examples
Input: 666
Output:
User: Read and Write
Group: Read and Write
Others: Read and Write
Input: 042
Output:
User: None
Group: Read only
Others: Write only
Input: 644
Output:
User: Read and Write
Group: Read only
Others: Read only
Winning
The shortest code in bytes wins.
What are the specifications of the input? – Jonathan Allan – 2016-09-13T11:23:01.843
@JonathanAllan Just the three digit number – Beta Decay – 2016-09-13T11:29:40.590
You mean as a decimal integer only, so 042 would be received as 42? – Jonathan Allan – 2016-09-13T11:31:50.403
2@Jonathan No, it's a string input so it'd be 042 – Beta Decay – 2016-09-13T11:50:19.720
Are we allowed to have an int-array or three ints as input? Or we need to use the String and then parse to digits? – Kevin Cruijssen – 2016-09-13T14:58:33.193
@KevinCruijssen You need to have a string and parse the digits – Beta Decay – 2016-09-13T14:59:21.457
Is using a tab instead of [3|2|1] spaces allowed? – aross – 2016-09-14T09:48:01.683
@aross No, you must use spaces since all of the answers have used spaces – Beta Decay – 2016-09-14T09:50:12.537
@BetaDecay Except the PHP one :) – aross – 2016-09-14T10:02:34.040
@aross Oh right haha – Beta Decay – 2016-09-14T10:11:14.350
The top JavaScript entry currently also uses a tab at time of writing. – Neil – 2016-09-14T10:50:17.127
1The output looks right with a tab character, so why not use it? Just to penal languages that need more bytes to pad a string? – Titus – 2016-09-14T11:32:51.113
@Titus No, because I specified to use spaces, which almost every other submission does – Beta Decay – 2016-09-16T06:09:24.473