# Briefing

The difficulty of a Code Golf question can be calculated as such:

$$\text{clamp} \left( \left\lceil \left( \frac v a \div 700 \right) \times 10 \right\rceil, 0, 10 \right)$$

Where $$\v\$$ is the number of views a question has

and $$\a\$$ is the number of answers a question has

and $$\⌈x⌉\$$ is the ceiling operator.

Also:

$$\text{clamp}(x, min, max) = \begin{cases} min & x < min \\ x & min \le x \le max \\ max & max < x \end{cases}$$

This question's current difficulty: ***

Write a program that will take two integers (v and a) and output the difficulty in asterisks (*).

The input can be in the form of an array, a separated string or as separate function arguments

# Test Data

Views   Answers Difficulty  Program Output
163     2       2           **
548     22      1           *
1452    24      1           *
1713    37      1           *
4162    32      2           **
3067    15      3           ***
22421   19      10          **********


### Example with pseudocode

v: 1713
a: 37
out = clamp(ceil(((v/a)/700)*10), 0, 10); // evaluates to 1
//program will output '*'


The shortest code in bytes wins! Trailing/ leading spaces are allowed.

• I find that LaTeX harder to understand that a simple formula string.. but whatever the majority wants I guess.. Commented Aug 17, 2016 at 13:07
• You should almost add [underhanded] for the question being underhanded.
Commented Aug 17, 2016 at 13:28
• This is a Code Golf question. Not an actual system being implemented into the site. Who cares if it's unfair? Commented Aug 17, 2016 at 14:11
• its kinda early so I may be missing something here, but why /700 * 10 instead of /70? Commented Aug 17, 2016 at 14:21
• @KevinL Ssshhhh ;) Commented Aug 17, 2016 at 14:34

## Actually, 14 bytes

:70a\\u9ukm'**


Try it online!

Takes advantage of the fact that 0 views and 0 answers is impossible, and thus ceil(v/a) > 0.

Explanation:

:70a\\u9ukm'**
:70             push 70 ([70 a v])
a            invert stack ([v a 70])
\\          integer division twice ([v//a//70])
u         add 1 ([v//a//70 + 1])
9uk      push 10, make stack into list ([[v//a//70+1, 10]])
m     minimum of list
'**  push "*", repeat


# Fourier, 46 bytes

All division in Fourier is integer division, so I just add one after division.

I*10/I/700^~X<0{1}{0~X}X>10{1}{10~X}X(42ai^~i)


Try it online!

# PHP 5.6, 66 bytes

function a($v,$a){echo str_repeat('*',max(0,min(10,1+$v/$a/70)));}


First we simplify the equation to v/a/70. From there we add 1 since PHP will use this number as an integer for the str_repeat, essentially doing abs($number+1). Then we use the hand-rolled clamp function of max($min_number, min($max_number,$the_number)) to keep it between 1 and 10.

The substr version is a few bytes shorter (due to not having to have to build in the clamp functionality), but this one was more fun to make.

# Ruby, 27 bytes

->v,a{(?**10)[1..(v/a/70)]}


## Ruby, 47 35 bytes

f=->(v,a){'*'*((v/=a*70)<9?v+1:10)}


Called with f.call(v,a)

Saved 12 bytes thanks to user3334690, now the function implicitly returns the result.

• you can probably save a bit by doing string * number like: "q=->(v,a){'*'*((v/=a*70)<9?v+1:10)}" Commented Aug 19, 2016 at 18:18
• You can safely remove f= Commented Aug 26, 2016 at 13:15

# Perl 6: 32 bytes

As a lambda that takes two arguments:

{"*"x min 10,ceiling $^x/$^y/70}


L^,/70/i9b<"*"\$yp


Try it online!

Not often I get to use the ^ flag in

## How it works

L^,		; Create a lambda that returns the stack joined
; Example arguments:	[3067 15]
/	; Divide;		[204.46]
70/	; Divide by 70;		[2.921]
i	; Floor;		[2]
9b>	; Minimum with 9;	[2]
"*"	; Push '*';		[2 '*']
y	; Repeat with an extra;	['*' '*' '*']


# Jelly, 10 bytes

÷÷70Ċ«⁵”*x


Try it online!

## How it works

÷÷70Ċ«⁵”*x - Main link. Takes v on the left and a on the right
÷          - v ÷ a
÷70       - v ÷ a ÷ 70
Ċ      - ⌈v ÷ a ÷ 70⌉
«⁵    - min(⌈v ÷ a ÷ 70⌉, 10)
”*x - Repeat "*" min(⌈v ÷ a ÷ 70⌉, 10) times


## Batch, 81 bytes

@set/an=(700*%2-%1)/%2/70,n*=!(n^>^>31)
@set s=**********
@call echo %%s:~%n%%%


Port of my JavaScript answer, except that Batch uses integer arithmetic, so I wrote the formula as (700*a-v)/a/70 which will truncate towards zero, and then the n*=!(n^>^>31) clears n if it is negative.

• Batch makes my eyes bleed, but nice answer! Commented Aug 18, 2016 at 14:57
• I could probably save a byte by using " instead of two ^s but I can't be bothered to check.
– Neil
Commented 14 hours ago

# Thunno 2, 10 bytes

/70/ṃ'*T×ɱ


Try it online!

#### Explanation

/70/ṃ'*T×ɱ  '# Implicit input
/            # Divide v by a
70/         # Divide this by 70
ṃ        # Take the ceiling
'*T×   '# Push 10 asterisks
ɱ   # Take that many characters
# (with a maximum of 10)
# from the string
# Implicit output