48
\$\begingroup\$

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: ***

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 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.

\$\endgroup\$
22
  • 3
    \$\begingroup\$ I find that LaTeX harder to understand that a simple formula string.. but whatever the majority wants I guess.. \$\endgroup\$
    – Shaun Wild
    Commented Aug 17, 2016 at 13:07
  • 3
    \$\begingroup\$ You should almost add [underhanded] for the question being underhanded. \$\endgroup\$
    – Adám
    Commented Aug 17, 2016 at 13:28
  • 6
    \$\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
    Commented Aug 17, 2016 at 14:11
  • 19
    \$\begingroup\$ its kinda early so I may be missing something here, but why /700 * 10 instead of /70? \$\endgroup\$
    – Kevin L
    Commented Aug 17, 2016 at 14:21
  • 5
    \$\begingroup\$ @KevinL Ssshhhh ;) \$\endgroup\$
    – Shaun Wild
    Commented Aug 17, 2016 at 14:34

42 Answers 42

50
\$\begingroup\$

JavaScript (ES6), 40 39 bytes

v=>a=>"**********".substring(10-v/a/70)

Because substring provides the required clamping and "ceil"ing behaviour. Edit: Normally I'm too lazy to bother, but because it got 4 upvotes, I've followed @MarsUltor's advice to save 1 byte by currying.

\$\endgroup\$
11
  • \$\begingroup\$ Oh, that is a nice use of substring :-) \$\endgroup\$ Commented Aug 17, 2016 at 12:32
  • 7
    \$\begingroup\$ Use currying: v=>a=> \$\endgroup\$
    – ASCII-only
    Commented Aug 17, 2016 at 12:53
  • 3
    \$\begingroup\$ Can you use substr instead? I know the second parameter makes a difference, but not sure about the first... \$\endgroup\$ Commented Aug 17, 2016 at 18:25
  • 1
    \$\begingroup\$ @DomHastings: Yes, though slice would be even shorter. \$\endgroup\$
    – Yay295
    Commented Aug 17, 2016 at 18:57
  • 5
    \$\begingroup\$ @DomHastings No, both substr and slice interpret a negative argument as counting back from the end of the string. \$\endgroup\$
    – Neil
    Commented Aug 17, 2016 at 19:07
38
\$\begingroup\$

I've been wanting to do this for a while...

HTML + CSS 491 487 485 bytes

-4 bytes thanks to Conor O'Brien
-2 bytes thanks to Releasing Helium Nuclei

Input is taken as the width and height of the page window; width being the number of Views, and height being the number of Answers.

<style>p{overflow:hidden;width:1ch}@media(max-aspect-ratio:70/2){p{width:1ch}}@media(max-aspect-ratio:70/3){p{width:2ch}}@media(max-aspect-ratio:70/4){p{width:3ch}}@media(max-aspect-ratio:70/5){p{width:4ch}}@media(max-aspect-ratio:70/6){p{width:5ch}}@media(max-aspect-ratio:70/7){p{width:6ch}}@media(max-aspect-ratio:70/8){p{width:7ch}}@media(max-aspect-ratio:70/9){p{width:8ch}}@media(max-aspect-ratio:7/1){p{width:9ch}}@media(max-aspect-ratio:70/11){p{width:10ch</style><p>**********

You can try it in your browser by entering

data:text/html,<style>p{overflow:hidden;width:1ch}@media(max-aspect-ratio:70/2){p{width:1ch}}@media(max-aspect-ratio:70/3){p{width:2ch}}@media(max-aspect-ratio:70/4){p{width:3ch}}@media(max-aspect-ratio:70/5){p{width:4ch}}@media(max-aspect-ratio:70/6){p{width:5ch}}@media(max-aspect-ratio:70/7){p{width:6ch}}@media(max-aspect-ratio:70/8){p{width:7ch}}@media(max-aspect-ratio:70/9){p{width:8ch}}@media(max-aspect-ratio:7/1){p{width:9ch}}@media(max-aspect-ratio:70/11){p{width:10ch</style><p>**********

as a url in a new tab.

\$\endgroup\$
5
  • 12
    \$\begingroup\$ +1 for thinking out of the box – ehm, thinking of the box... \$\endgroup\$
    – Adám
    Commented Aug 18, 2016 at 5:24
  • 2
    \$\begingroup\$ Do you need the closing p tag? \$\endgroup\$ Commented Aug 18, 2016 at 6:21
  • \$\begingroup\$ I love how it updates as I change the window's size. \$\endgroup\$
    – YSC
    Commented Aug 18, 2016 at 11:36
  • \$\begingroup\$ @ConorO'Brien: Good point! \$\endgroup\$
    – Yay295
    Commented Aug 18, 2016 at 13:27
  • 1
    \$\begingroup\$ You don't need the last two }s too. \$\endgroup\$
    – betseg
    Commented Aug 18, 2016 at 23:24
12
\$\begingroup\$

05AB1E, 11 bytes

/70/î'*T×s£

Explanation

/            # divide v by a
 70/         # divide by 70
    î        # round up, call this n
     '*T×    # push 10 asterisks
         s£  # take n up to 10 asterisk
             # implicitly print

Try it online

\$\endgroup\$
0
12
\$\begingroup\$

Javascript (ES6), 37 36 bytes

v=>a=>"*".repeat((v/=a*70)<9?v+1:10)

Saved 1 byte by currying, thanks to TheLethalCoder

let F=
v=>a=>"*".repeat((v/=a*70)<9?v+1:10)

console.log("Test #1:", F(163)(2))    // **
console.log("Test #2:", F(548)(22))   // *
console.log("Test #3:", F(1452)(24))  // *
console.log("Test #4:", F(1713)(37))  // *
console.log("Test #5:", F(4162)(32))  // **
console.log("Test #6:", F(3067)(15))  // ***
console.log("Test #7:", F(22421)(19)) // **********

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Can you use v=>a=> instead of (v,a)=>? \$\endgroup\$ Commented Aug 17, 2016 at 14:56
  • \$\begingroup\$ @TheLethalCoder - Updated. Thanks! \$\endgroup\$
    – Arnauld
    Commented Aug 17, 2016 at 15:02
  • 2
    \$\begingroup\$ Doesn't work for v=70, a=1 does it? \$\endgroup\$
    – Neil
    Commented Aug 17, 2016 at 19:09
  • 1
    \$\begingroup\$ @Neil - That's right. It is off by 1 point if the number of answers is an exact divisor of the number of views. Or put in other words, it's anticipating the next view. ;-) \$\endgroup\$
    – Arnauld
    Commented Aug 18, 2016 at 10:55
11
\$\begingroup\$

Mathematica, 38 35 bytes

StringRepeat["*",10,⌈#/#2/70⌉]&

Thanks to @MartinEnder for 3 bytes

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Hello, and welcome to PPCG! This is a great answer! \$\endgroup\$ Commented Aug 17, 2016 at 15:06
  • \$\begingroup\$ @NoOneIsHere Thanks! Originally I was thinking of Clip, which has pretty much the same syntax as OP's Clamp, but then I saw that StringRepeat has the optional third argument for truncation. \$\endgroup\$
    – user58632
    Commented Aug 18, 2016 at 6:47
  • 3
    \$\begingroup\$ There are Unicode characters for the left and right ceiling bracket which together make up only 6 bytes instead of the 9 you need for Ceiling[]. \$\endgroup\$ Commented Aug 18, 2016 at 7:31
9
\$\begingroup\$

CJam, 18 15 14 bytes

Saved 1 byte thanks to Peter Taylor and 3 bytes thanks to Adnan

'*A*q~d/70/m]<

Try it online

'*A*            e# Push "**********"
    q~d/        e# Get the input and divide the two numbers
        70/     e# Divide by 70
           m]   e# Ceil, yielding x
             <  e# Slice the string, taking the first x elements
\$\endgroup\$
0
8
\$\begingroup\$

C#, 68 49 48 bytes

v=>a=>"**********".Substring((int)(10-v/a/70d));

This is the C# version of this excellent answer by Neil.

Saved another 19 bytes thanks to Neil

\$\endgroup\$
9
  • \$\begingroup\$ Try (int)System.Math.Floor(10-v/a/70) or just (int)(10-v/a/70). \$\endgroup\$
    – Neil
    Commented Aug 17, 2016 at 13:16
  • \$\begingroup\$ @Neil Looks like I had to leave the 70d alone but works better thanks \$\endgroup\$ Commented Aug 17, 2016 at 13:44
  • 1
    \$\begingroup\$ Sorry, didn't see the d there. \$\endgroup\$
    – Neil
    Commented Aug 17, 2016 at 15:07
  • \$\begingroup\$ Another answer that could save one byte with currying, I think: v=>a=> \$\endgroup\$ Commented Aug 18, 2016 at 3:10
  • \$\begingroup\$ @BrianMcCutchon Didn't even realise how I could do it in C# thanks \$\endgroup\$ Commented Aug 18, 2016 at 8:11
8
\$\begingroup\$

Java 8, 57 bytes

Uses a lambda to save bytes, performs the calculation and substrings to return the answer.

(v,a)->"**********".substring(Math.max(0,(700*a-v)/70/a))

Here is my class for testing it.

public class DifficultyCalculator{
    static interface h{ String f(int v, int a);}
    static void g(h H){
        System.out.print(H.f(163,2));System.out.println("\t**");
        System.out.print(H.f(548,22));System.out.println("\t*");
        System.out.print(H.f(1452,24));System.out.println("\t*");
        System.out.print(H.f(1713,37));System.out.println("\t*");
        System.out.print(H.f(4162,32));System.out.println("\t**");
        System.out.print(H.f(3067,15));System.out.println("\t***");
        System.out.print(H.f(22421,19));System.out.println("\t**********");
    }
    public static void main(String[] args) {
        g( // 70
            (v,a)->"**********".substring(java.lang.Math.max(0,(int)(10-v/70d/a)))
        );
    }
}

Update

  • -3 [16-08-19] Utilized integer division
  • -10 [16-08-18] Removed unnecessary import, thanks to @OlivierGrégoire!
  • -18 [16-08-17] Return string instead of print
\$\endgroup\$
4
  • 2
    \$\begingroup\$ Nice, a Java answer that isn't a train! \$\endgroup\$ Commented Aug 17, 2016 at 20:40
  • 4
    \$\begingroup\$ No need for java.lang. since it's the default included package. \$\endgroup\$ Commented Aug 18, 2016 at 7:25
  • \$\begingroup\$ You are rounding not ceiling! \$\endgroup\$
    – user54187
    Commented Aug 18, 2016 at 11:34
  • 1
    \$\begingroup\$ @Advancid I tested it and System.out.println((int)2.99); prints 2 and since I take the pre-floored value from 10 and then floor it, it is the same as taking the ceiling away from 10. \$\endgroup\$ Commented Aug 18, 2016 at 12:53
7
\$\begingroup\$

MATL, 12 bytes

/70/0:9>42*c

Try it online!

Explanation

The rounding up and clamping are done simultaneously as follows: the number x = v/a/70 is compared against each element of the array [0 1 ... 9]. The numbers of that array that are exceeded by x will become asterisks, and the rest will be spaces.

/      % Take the two numbers implicitly. Divide. (Example: for inputs 3067, 15
       % we get 204.47)
70/    % Divide by 70 (we get 2.92)
0:9    % Push array [0 1  ... 9]
>      % See which of those are exceeded by the previous number (2.92 exceeds
       % 0, 1 and 2, so we get [1 1 1 0 ... 0]). This does the rounding up
       % and the clamping
42*    % Multiply by 42, which is the ASCII code of '*' (we get [42 42 42 0 ... 0])
       % Char 0 will be displayed as space
c      % Convert to char. Implicitly display
\$\endgroup\$
7
\$\begingroup\$

Python2, 32 bytes

saved 3 + 2 bytes and corrected off by one error thanks to Leaky Nun

lambda v,a:('*'*10)[:~-v/a/70+1]

similar to Neils answer. Uses the fact that Python2 does integer division.

\$\endgroup\$
10
  • \$\begingroup\$ fails when v=70 and a=1 \$\endgroup\$
    – Leaky Nun
    Commented Aug 17, 2016 at 13:26
  • \$\begingroup\$ The f= can be removed \$\endgroup\$
    – Leaky Nun
    Commented Aug 17, 2016 at 13:27
  • \$\begingroup\$ v, a can become v,a \$\endgroup\$
    – Leaky Nun
    Commented Aug 17, 2016 at 13:27
  • \$\begingroup\$ thanks! should work now. May be wrong for v=0, a=1 now, but this case cannot exist, can it? \$\endgroup\$
    – mathause
    Commented Aug 17, 2016 at 13:50
  • \$\begingroup\$ That would not be wrong for v=0, a=1. \$\endgroup\$
    – Leaky Nun
    Commented Aug 17, 2016 at 13:51
7
\$\begingroup\$

EXCEL, 29 bytes

If you count Excel as a representation of VBA Excel, then you can use

=REPT("*",MIN(1+v/(70*a),10))

where v and a are the name of reference cells.

\$\endgroup\$
2
  • 3
    \$\begingroup\$ Hi, and welcome to PPCG! This is a nice first post! And valid also. \$\endgroup\$
    – Riker
    Commented Aug 20, 2016 at 22:08
  • \$\begingroup\$ Hi too @EasterlyIrk. Thanks for the warm welcome :) \$\endgroup\$ Commented Aug 20, 2016 at 22:12
6
\$\begingroup\$

Haskell, 35 bytes

v#a=[1..min(ceiling$v/a/70)10]>>"*"

[1..min(ceiling$v/a/70)10] creates a range from 1 to the computed difficulty (an empty list for difficulty 0). a>>b repeats the list b length a often.

\$\endgroup\$
5
\$\begingroup\$

Pyth, 17 13 bytes

4 bytes in credit to Luis Mendo for his algorithm.

*\*htS[0T.EccFQ70
*\*s>LccFQ70T

Test suite.

\$\endgroup\$
1
4
\$\begingroup\$

Pyke, 13 9 bytes

/70/\**T<

Try it here!

Explanation:

/         -    num_1 / num_2
 70/      -   ^ / 70
    \**   -  "*" * ^
       T< - ^[:10]
\$\endgroup\$
4
\$\begingroup\$

C#, 97 89 87 77 42 41 bytes

v=>a=>new string('*',(v/=a*70)<9?v+1:10);

Saved 10 bytes thanks to Adám

Saved a few bytes thanks to Arnauld

\$\endgroup\$
1
  • \$\begingroup\$ You can save a whole lot by replacing (int)System.Math.Ceiling(v/a/70d) by (v+69)/(70*a)... Note that moreover v/a can not be negative, so c can be simplified a lot because you don't need to check for that. \$\endgroup\$ Commented Aug 17, 2016 at 14:20
4
\$\begingroup\$

Perl, 35 32 bytes

say"*"x(10-($-=10-pop()/70/pop))

Use -E to activate say and give the arguments in the reverse order:

perl -E 'say"*"x(10-($-=10-pop()/70/pop))' 2 163

If arguments on STDIN are allowed the following is 29 bytes:

(echo 163; echo 2) | perl -pe '$_="*"x(10-($-=10-$_/70/<>))'
\$\endgroup\$
3
  • \$\begingroup\$ I can't remember if it'd exactly the same, but can you have 0| instead of $-=? (Thinking operator precedence might not be right...) \$\endgroup\$ Commented Aug 17, 2016 at 18:44
  • \$\begingroup\$ @DomHastings 0| makes a negative number into a huge number (leading to zero *s), $-= clips to 0 (leading to ten *s), which is what I need here \$\endgroup\$
    – Ton Hospel
    Commented Aug 17, 2016 at 18:59
  • \$\begingroup\$ Ah, of course, it's only ever a positive integer! Thanks for reminding. I'm sure I'll forget that when I need it though... 😀 \$\endgroup\$ Commented Aug 17, 2016 at 19:30
4
\$\begingroup\$

R, 68, 50 52 bytes

f=function(v,a)cat(rep("*",1+min(v/a/70,10)),sep="")

rep implicitly places a min on number of 0.

Thanks to @plannapus and @Anastasiya-Romanova秀 for spotting my error.

\$\endgroup\$
2
  • \$\begingroup\$ You can remove f= \$\endgroup\$
    – Cyoce
    Commented Aug 18, 2016 at 18:11
  • 1
    \$\begingroup\$ Outputs of your code are not equal to the Test Data. You should add 2 more bytes 1+ after min( in order to get the same outputs \$\endgroup\$ Commented Aug 22, 2016 at 7:02
3
\$\begingroup\$

Javascript ES6, 48 bytes

a=>b=>"*".repeat(Math.ceil(Math.min(a/b/70,10)))
\$\endgroup\$
0
3
\$\begingroup\$

m4, 136 135 bytes

define(r,`ifelse($1,0,,eval($1>9),1,*`r(9)',*`r(decr($1))')')define(f,`r(ifelse(eval($1%($2*70)),0,eval($1/$2/70),eval($1/$2/70+1)))')

Defines a macro f which takes v and a, and expands to the correct output. Most of the program is an implementation of ceiling.

\$\endgroup\$
3
\$\begingroup\$

C, 54, 51, 50, 49 bytes

Assuming that v is positive or zero and a positive, the x < min clamping case is never met, since there is no way the result of the ceiling operation can be negative. Additionally, integer maths on non-negative values always yields the floor of the result, so we add 1 to get the ceiling.

This solution requires a write function, works on Linux at least.

F(v,a){write(1,"**********",(v/=a*70)>9?10:v+1);}

Test main:

int main() {
  F(163, 2);
  putchar('\n');
  F(548, 22);
  putchar('\n');
  F(1452, 24);
  putchar('\n');
  F(1713, 37);
  putchar('\n');
  F(4162, 32);
  putchar('\n');
  F(3067, 15);
  putchar('\n');
  F(22421, 19);
  putchar('\n');
}
\$\endgroup\$
2
  • 1
    \$\begingroup\$ Replacing (v=v/a/70) with (v/=a*70) saves 1 byte. \$\endgroup\$
    – ceilingcat
    Commented Aug 19, 2016 at 6:32
  • \$\begingroup\$ Nice catch @ceilingcat! \$\endgroup\$ Commented Aug 19, 2016 at 9:35
2
\$\begingroup\$

javascript: 82 73 bytes

 (v,a)=>console.log("*".repeat(Math.min(Math.max(0,Math.ceil(v/a/70),10)))
  • saved some bytes after Adám pointed out I overlooked the /700*10=/70, and the removal of parens
\$\endgroup\$
4
  • \$\begingroup\$ @Adám what's with the edit? \$\endgroup\$ Commented Aug 17, 2016 at 12:49
  • \$\begingroup\$ @Adám If people read any of the answers they'll have the spoiler already. Rolling back, because currently that sentence is fairly useless and just makes people click on the revision history. \$\endgroup\$ Commented Aug 17, 2016 at 13:01
  • \$\begingroup\$ @Adám That's what I usually use myself but I don't see any harm in the current version. \$\endgroup\$ Commented Aug 17, 2016 at 13:56
  • \$\begingroup\$ No need to console.log it, returning is fine. You can also save a byte with v=>a=> instead of (v,a)=> \$\endgroup\$
    – Cyoce
    Commented Aug 18, 2016 at 18:20
2
\$\begingroup\$

Dyalog APL, 15 bytes

'*'⍴⍨10⌊⌈⎕÷70×⎕

'*'⍴⍨ the character repeated this many times:
10⌊ min(10,...
⎕÷ input divided by
70× seventy times
input

TryAPL online!

\$\endgroup\$
2
  • \$\begingroup\$ Would it be golfier to use Mendo's algorithm? \$\endgroup\$
    – Leaky Nun
    Commented Aug 17, 2016 at 13:11
  • \$\begingroup\$ @LeakyNun I don't think so: '*'/⍨(⎕÷70×⎕)>⍳10 \$\endgroup\$
    – Adám
    Commented Aug 17, 2016 at 13:19
2
\$\begingroup\$

Jellyfish, 18 bytes

P
#'*
mM/%i
10 %70

Takes input in the format [a v]. Try it online!

Explanation

  • % is reciprocal, so %70 is 1/70.
  • i is input, as a two-element array.
  • /% with inputs i and %70 reduces the array i by flipped division with initial value %70. In other words, it computes v/(a/(1/70)), which is equal to v / (70*a).
  • M takes the ceiling of this value, and m takes the maximum of that and 10.
  • #'* repeats the literal * character that many times.
  • P prints the result without quotes.
\$\endgroup\$
2
\$\begingroup\$

MATLAB, 34 33 bytes

Because I like this challange so much, here is one for MATLAB (outputs trailing whitespaces):

@(v,a)[(ceil(v/a/70)>0:9)*42,'']

Inspired by @Luis Mendo's answer. Thanks to @pajonk for saving one byte.

\$\endgroup\$
2
  • \$\begingroup\$ Nice approach! I had a 40-byte one to post... BTW, you can save one byte using [... ''] instead of char(...). And do you really need the ceil when at the end you are comparing with integers? \$\endgroup\$
    – pajonk
    Commented Aug 17, 2016 at 15:44
  • 2
    \$\begingroup\$ thanks @pajonk - one can really learn some things on this site to make my code even less readable ;) \$\endgroup\$
    – mathause
    Commented Aug 17, 2016 at 15:56
2
\$\begingroup\$

dc, 110 108 104 98 bytes

This was a doozy since slicing isn't a thing. Also, dc doesn't manipulate strings. I just really was waiting for a string one that would be < 5 hours of coding. On the plus side, I finally started writing down common constructs, like for loops. Also had to formulate rounding/ceiling, so thanks for that.

[42P]sd[dsi[li0!=dli1-dsi0!=L]dsLx]sl[Isi[li0!=dli1-dsi0!=L]dsLx]sg[1+]saIk/70*0k1~0!=adI>ldI!>gIP

Invoked in bash:

echo 'v a (above)'|dc
# Wholly:
>> echo '163 2 [42P]sd[dsi[li0!=dli1-dsi0!=L]dsLx]sl[Isi[li0!=dli1-dsi0!=L]dsLx]sg[1+]saIk/70*0k1~0!=adI>ldI!>gIP'|dc
# outputs:
**
>> 

Replacing (above) with the code, and v and a with their respective counterparts above. The single quotes are important (otherwise you get bash's history stuff).


Explained:

[42P]sd   # Here we store a macro in register d to print 1 * without a newline

[dsi[li0!=dli1-dsi0!=L]dsLx]sl # Store the "less than" case, a for loop which
                        # uses the top-of the stack as it's number of iterations.
[Isi[li0!=dli1-dsi0!=L]dsLx]sg # Store the "greater than" case. It's the above,
                        # but it puts 10 on the stack to use instead.

[1+]sa # Store a macro to add 1 to whatever is the top-of-stack.


Ik # Set precision at non-zero to allow decimal division

/70* # Divide the top two of the stack, v/a; multiply by 70 (`/700*10` == `/70`)
             # dc is postfix and stack-based, so operators come after operands.

0k1~0!=a     # This is a ceiling function.
|> 0k  # set precision to 0 to perform integer division
|> 1~  # push the quotient of integer division by 1, and then the remainder. (r is top)
|> 0!=a # If the top-of-stack (decimal part) is not 0, add 1 to the quotient

dI>ldI!>g # Conditional statement
|> dI>l  # (d)uplicate the top, push 10 on. If 10 > the old top, execute the `l`ess-than
          # case, which loops top-of-stack times.
|> dI!>g # Complement of the above, using the `g`reater-than to loop 10 times.

IP # print a newline

This is probably more golf-able, but I was trying to get it finished to avoid premature optimization.

  • 2 bytes saved by duplicating-saving instead of saving-loading
  • 4 bytes saved dividing by 70
  • 6 bytes from daniero's suggestions (non-strings, ASCII nums instead; 10 => I)
\$\endgroup\$
1
  • \$\begingroup\$ [*]n => 42P. Every instance of 10 can be replaced by I. []p => IP \$\endgroup\$
    – daniero
    Commented Aug 17, 2016 at 20:50
2
\$\begingroup\$

Haskell, 35 bytes

This solution is as completely different from Laikonis answer as it gets for something this trivial. Yet the score (for now) is exactly the same.

v%a=take(ceiling$v/a/70)[0..9]>>"*" 

This produces ten stars, then shaves off some. Easy to extend to arbitrary difficulty with an infinite list.

I did manage to shave off one more byte. But while all test cases work, this shouldn't be correct in general.

v%a=take(1+div v(a*70))[0..9]>>"*"
\$\endgroup\$
2
\$\begingroup\$

TI-Basic, 39 bytes

Prompt V,A
sub("**********",1,max(0,min(10,int(V/A/70)+1
\$\endgroup\$
2
\$\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.

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

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
\$\endgroup\$
2
\$\begingroup\$

Vyxal, 9 bytes

/70/ṙ›\**

Try it Online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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