# Problem

Build an octal calculator that can do the following operations:

• Subtract (-)
• Multiply (*)
• Divide (/)
• Check is prime

Counting in octal is like this with decimal

(Octal)  (Decimal)
0        0
1        1
2        2
3        3
4        4
5        5
6        6
7        7
10       8
11       9


and so on...

So given input a b c

• a being a number in octal
• b being an operator (+, -, *, /) not is prime
• c being a number in octal

Output the expression evaluated as abc = Output (Is prime)

Test cases:

a=3, b='+', c=3 -> 6 (false)

a=5, b='+', c=5 -> 12 (false)

a=1, b='*', c=5 -> 5 (true)

a=7, b='+', c=6 -> 15 (true)

a=31, b='-', c=11 -> 20 (false)

a=25, b='/', c=3 -> 7 (true)

# Rules:

• The output just needs to contain the answer and a truthy/falsey value of whether it is prime so [4,0] is fine.
• The inputs will always be a case that outputs an integer (integer division)
• This is code golf so shortest answer wins

When is an octal number a prime

## closed as unclear what you're asking by programmer5000, Cody Gray, TheLethalCoder, Titus, TotoJul 25 '17 at 9:07

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• Can we do something like [12, 0] or [4, 1] instead of 12 (false) and 4 (true)? – Stephen Jul 19 '17 at 13:10
• Yes, will ammend. – LiefdeWen Jul 19 '17 at 13:11
• ...as if being octal is a property of numbers... – Leaky Nun Jul 19 '17 at 13:12
• Also, does division refer to integer division? – Erik the Outgolfer Jul 19 '17 at 13:14
• @totallyhuman, you have to take 3 seperate strings though. – LiefdeWen Jul 19 '17 at 14:07

# Mathematica, 38 bytes

{a=#@@(#~FromDigits~8&)/@#2,PrimeQ@a}&


Anonymous function. Takes input in the form ... &[Plus, {"7", "12"}] (with both numbers as octal strings and the operator being Plus, Subtract, Times, or Divide) and returns output in the form {17, True} (with the number in decimal.) Did this based on my own, possibly incorrect, interpretation of the rules; please comment if I did something wrong.

# 05AB1E, 13 bytes

‚8ö³.VDps8B‚


Try it online!

Input format:

c
a
b


Output format:

[Is prime, 'Output']


Note that strings and numbers are equivalent datatypes in 05AB1E.

• Hmm...not sure if valid. – Erik the Outgolfer Jul 19 '17 at 13:25
• @MagicOctopusUrn I don't think it'd behave correctly (also there's ð for ' ), since the operator is designed to work on base-10 ints, while it would have incorrect results with base-8 ints. Also you aren't supposed to check if the base-8 version is prime, but the integer itself before converting to base-8 with 8B. – Erik the Outgolfer Jul 19 '17 at 14:21
• No it still makes the operator work on the base-8 versions of the integers (something it's not supposed to do). Basically it would treat them as base-10 integers. – Erik the Outgolfer Jul 19 '17 at 14:23
• Back to disliking the challenge, get it now though. – Magic Octopus Urn Jul 19 '17 at 14:25

# JavaScript, 82 bytes

(a,b,c,k=m=eval((v=0)+a+b+v+c))=>{while(k-->3)m%k||(v=1);return[m.toString(8),!v]}


# JSFiddle

Input is in octal base, output is also in octal base.

# Jelly, 12 bytes

Dḅ8jVµb8V,ÆP


Try it online!

Uses × for * and ÷ or : for / (approved by OP in chat).

Argument 1:

[a, c]


Argument 2:

b


Output:

[Output, Is prime]


# Python 2, 89 67 bytes

A whopping -22 bytes thanks to suggestions by Rod.

n=eval(''.join(input()))
print[oct(n),all(n%i for i in range(2,n))]


Try it online!

Takes input as:

['01', '*', '05']


Prints a list like:

['05', True]

• You can drop both lambdas switching to input()/print to save 2 bytes, also since you are using eval, you don't need to convert to int(,8), you can use octa literals in the string to save 10+ – Rod Jul 19 '17 at 13:53
• 1 is shown prime you need to add x>1and I guess. – officialaimm Jul 19 '17 at 14:21

# PHP, 104 bytes

for(eval("$i=$n=octdec($argv[1])$argv[2]octdec($argv[3])|0;");--$i>1&&$n%$i;);echo
decoct($n),_,$i==1;


Run with -nr or try it online.

Output format: Result_1 for primes; Result_ for non-primes.

Output for negative results is faulty; replace the echo part with echo$n<0?-decoct(-$n):decoct($n),_,$i==1;` (+17 bytes) to fix.