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)
@SeanBean Trailing spaces allowed? – Luis Mendo – 2016-08-17T12:38:49.667
@LuisMendo Yes. – Shaun Wild – 2016-08-17T12:40:56.520
3I find that LaTeX harder to understand that a simple formula string.. but whatever the majority wants I guess.. – Shaun Wild – 2016-08-17T13:07:35.207
1Will
v
ora
ever be negative? – Leaky Nun – 2016-08-17T13:16:05.7633You should almost add [[tag:underhanded]] for the question being underhanded. – Adám – 2016-08-17T13:28:26.860
Given the current formula, unanswered questions will always have a difficulty score of 10 (assuming the convention that dividing a positive number by zero gives positive infinity). This feels unfair to me. – Joe Z. – 2016-08-17T14:05:23.287
5This is a Code Golf question. Not an actual system being implemented into the site. Who cares if it's unfair? – Shaun Wild – 2016-08-17T14:11:33.763
Also I don't know if all the answers below actually work with 0 questions. – Joe Z. – 2016-08-17T14:13:35.497
13its kinda early so I may be missing something here, but why
/700 * 10
instead of/70
? – Kevin L – 2016-08-17T14:21:36.1074@KevinL Ssshhhh ;) – Shaun Wild – 2016-08-17T14:34:46.823
1@Adám Tag wiki for [tag:underhanded]:
This tag exists for historical reasons. New questions of the type previously posted under this tag are not welcome.
– haykam – 2016-08-17T19:24:34.783What should occur when
views
and/oranswers
==0? (granted, views==0 implies answers==0, but hey). – Delioth – 2016-08-17T19:52:23.570It doesn't matter really. – Shaun Wild – 2016-08-17T20:49:38.223
3@Peanut I know, but here the OP isn't calling for underhanded answers, it is the OP's challenge which is underhanded: SeanBean incredibly manages to fool most (all?) the experienced golfers into writing unnecessarily long code! – Adám – 2016-08-18T05:22:01.467
1You should add a test case where v/a is evenly divisible by 70, e.g., 70, 1, 1. – Dennis – 2016-08-18T08:01:27.063
I was really hoping that this would be a competition for writing code that tries to predict some measure of difficulty based on the text of the question. – Mark S. – 2016-08-18T12:41:08.920
@MarkS. I'll try and think of a question based around that idea if you like? Or you can do it yourself :P – Shaun Wild – 2016-08-18T13:52:22.757
How do you build a code to test how hard this question is?... – None – 2016-08-18T15:55:21.710
@DonielF I just edit the question everynow and again, running it through my version of the program. – Shaun Wild – 2016-08-18T15:59:47.007
@Sean That was a failed joke. Apparently you missed the humor in it. Oh well. – None – 2016-08-18T16:23:54.537
@DonielF Care to explain? – Shaun Wild – 2016-08-18T20:16:19.697
Will v or a ever be zero? What should the outputs be in those cases? – FryAmTheEggman – 2016-08-20T22:15:46.440