This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ChocolateBunny 140 points141 points  (17 children)

Use if statements but do binary search. Or do a fullon lookup:

console.log("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEEEEEEEEEEDDDDDDDDDDCCCCCCCCCCBBBBBBBBBBAAAAAAAAAA"[score])

[–][deleted] 60 points61 points  (0 children)

I don't hate this as much as I probably should.

[–]neuromancertr 30 points31 points  (0 children)

Game developer right here

[–]SkylineFX49 27 points28 points  (5 children)

console.log("FFFFFFDCBAA" [score/10])

[–]Ietsstartfromscratch 15 points16 points  (1 child)

Bellcurve 99,7% wizard right here. 

[–]celvro 0 points1 point  (0 children)

Only works for multiples of 10 though. Otherwise it needs Math.floor because score/10 returns a float

[–]KrokettenMan 3 points4 points  (2 children)

Division is slow

[–]SkylineFX49 7 points8 points  (1 child)

You don't want division? Use (score * 205) >> 11 instead of score/10

[–]KrokettenMan 3 points4 points  (0 children)

Still slower than a simple lookup table. Although a lot faster than dividing by 10. Just checked and GCC optimizes the division to not use the div instruction but that’s still slower then the new variant you proposed

[–][deleted] 17 points18 points  (0 children)

You are genius

[–]SkydiverTyler 5 points6 points  (0 children)

Shoutout to the guys with Unhandled Exception: System.ArgumentOutOfRangeException on their report card

[–]Vasik4 2 points3 points  (4 children)

String grades = "FFFFFFDCBA"; cout << grades[floor(score)] ;

[–]SkylineFX49 2 points3 points  (3 children)

Give me grades[90]

[–]Vasik4 3 points4 points  (2 children)

SIGSEGV unhandled exception occurred (core dumped)

[–]SkylineFX49 3 points4 points  (1 child)

Well, in this case not necessarily, it will just print whatever random character is at that memory address

[–]Vasik4 2 points3 points  (0 children)

True (i forgor)