44
\$\begingroup\$

Briefing

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

formula

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:

clamp

This question's current difficulty: ***

Task

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 seperated string or as seperate 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.

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

37 Answers 37

1
2
1
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

Ruby, 27 bytes

->v,a{(?**10)[1..(v/a/70)]}
| improve this answer | |
\$\endgroup\$
1
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ you can probably save a bit by doing string * number like: "q=->(v,a){'*'*((v/=a*70)<9?v+1:10)}" \$\endgroup\$ – user3334690 Aug 19 '16 at 18:18
  • \$\begingroup\$ You can safely remove f= \$\endgroup\$ – Luis Masuelli Aug 26 '16 at 13:15
1
\$\begingroup\$

Perl 6: 32 bytes

As a lambda that takes two arguments:

{"*"x min 10,ceiling $^x/$^y/70}
| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

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.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Batch makes my eyes bleed, but nice answer! \$\endgroup\$ – Mark K Cowan Aug 18 '16 at 14:57
0
\$\begingroup\$

Add++, 26 bytes

L^,/700/10*1+i10m1_Vc"*"Gy

Try it online! or see the test suite

It's not often I get to use the ^ function flag in a code golf.

How it works

L^,		; Create a lambda that returns the stack joined
		; Example arguments:	[3067 15]
	/	; Divide;		[204.46]
	700/	; Divide by 700;	[0.2921]
	10*	; Times by 10;		[2.91]
	1+i	; Ceiling;		[3]
	10m	; Minimum with 10;	[3 10 3]
	1_	; Decrement;		[3 10 2]
	Vc	; Keep the top value;	[2]
	"*"G	; Push '*' below;	['*' 2]
	y	; Repeat;		['*' '*' '*']
| improve this answer | |
\$\endgroup\$
1
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.