Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

‭☭ Crimson skies ☭‬

Name: Anonymous 2010-02-01 21:38

I'm wondering why the red countries produce such skilled hackers.
Maybe the difference be their strict and result-oriented schooling system. Or their lawlessness and disregard for copyrights. Maybe it's because they are bred with older and more hackable computer systems instead of the Fisher Price iPhones fat Americans get to play with.

Could these Russian, Czech and Chinese hackers be driven by the spirit of communism itself. Did our comrade Trotskij miss out on a glorious computing career?

Name: Anonymous 2010-02-07 5:35

>>39
Like a baawwwssss.

Name: Leah Culver 2010-02-07 7:33

I've been awfully busy programming lately. My Django-based side project is coming along well and I hope to have it ready for use in a few weeks. Please don't ask more about it, that's really all I can say for now. Anyways, I came across an interesting little math problem today and was hoping some skilled programmers out there could come up with a more elegant solution than mine.

Problem: Star Ratings

People can rate cheeseburgers on my website with a star rating of 0-5 stars (whole stars only), 5 being mighty tasty and 0 being disgusting. I would like to show the average of everyone's ratings of a particular cheeseburger to the nearest half star. I have already calculated the average rating as a float (star_sum) and the total number of people that rated the particular cheeseburger (num_raters). The result should be stored as a float in a variable named "stars."
My Solution (in Python):

# round to one decimal place and
# separate into whole and fractional parts
parts = str(round(star_sum/num_raters, 1)).split('.')
whole = int(parts[0])
frac = int(parts[1])
if frac < 3:
___frac = 0
elif frac > 7:
___frac = 0
___whole += 1
else:
___frac = 5
# recombine for a star rating rounded to the half
stars = float(str(whole)+'.'+str(frac))


Mmmm… In-N-Out Burgers… Please reply if you've got a better solution.

Name: Anonymous 2010-02-07 11:38

That seems to use a lot of unnecessary variables and work just to round a number.

THIS IS NOW A post your own rounding algorithm THREAD

Here's mine, written in Sessless (also known as C):

double round (double number)
{
    float test = (int)number;
    if      (number < (test + .3))
        return test;
    else if (number > (test + .7))
        return test + 1.0;
    else
        return test + 0.5;
}


A program to test it:

#include <stdio.h>

int main ()
{
    double derp[] = {1.2, 1.4, 1.6, 1.8};
    int x;
   
    for (x = 0; x < 4; x++)
    {
        printf ("%1.1f rounds to %1.1f\n", derp[x], round (derp[x]));
    }
   
    return 0;
}

Name: Anonymous 2010-02-07 13:12

>>43

$ ./a.out
1.2 rounds to 1.0
1.4 rounds to 1.5
1.6 rounds to 1.5
1.8 rounds to 2.0

DELICIOUS MATH

Name: Anonymous 2010-02-07 13:40

>>42
Dem cheeseburgers fill up dem hips.

Name: Anonymous 2010-02-07 13:43


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int expert_round(double d) {
  char *p,s[1024];  // TODO dynamic buffer of sufficient length
  int r;
  sprintf(s,"%.5f",d);
  if((p=strchr(s,'.')))
    *p = 0;
  r = strtol(s,0,10);
  if(*(++p)>='5')
    r++;
  return r;
}

int main(int argc, char **argv) {
  double d;
  argv[1] ? d = strtod(argv[1],0) : exit(1);
  printf("%d\n",expert_round(d));
  return 0;
}

Name: Anonymous 2010-02-07 14:13

>>45
shut up fatie!

Name: Anonymous 2010-02-07 14:22

EXPERT FIOC

import math

def round(num):
    foo = lambda (x,y): y if x < 0.3 else 1.0+y if x > 0.7 else 0.5+y
    return foo(math.modf(num))

nums = [1.2,1.4,1.6,1.8]
print map(round,nums)

Name: Anonymous 2010-02-07 15:42

inline float round (float num) { return 0.5 * (int) (num * 2.0); }

derp

Name: Anonymous 2010-02-07 16:33

>>49
$ ./a.out
1.2 rounds to 1.0
1.4 rounds to 1.0
1.6 rounds to 1.5
1.8 rounds to 1.5


IHBT

Name: Anonymous 2010-02-07 16:50


int round( float num )
{
   return (int)( num + ( num > 0.0f ? 0.5f : -0.5f ) );
}

Name: Anonymous 2010-02-07 16:57

>>49,50
inline float round (float num) { return 0.5 * (int) (0.5 + (num * 2.0)); }

>>49 is a faggot

Name: Anonymous 2010-02-07 16:59

>>51
IHBTA

Name: Anonymous 2010-02-07 17:05

>>52
WINAR

Name: Anonymous 2010-02-07 17:11

>>52
Nope.  num = 1.25 returns 1.5

Name: Anonymous 2010-02-07 17:21

>>53

>>51 works.

Name: Anonymous 2010-02-07 17:28

>>56
How can it?  The return value is int?

Unless IHBTe

Name: Anonymous 2010-02-07 17:43

>>55
It rounds in binary, so that's to be expected.

Name: Anonymous 2010-02-07 18:01

>>58
I see.  So >>51 is just a general rounding algorithm.  Not one to solve the Culver's stars problem.

Name: Anonymous 2010-02-07 18:05

>>55
It's meant to. Did you never take basic mathematics? Using 0.3 and 0.7 for rounding limits as previous posts did is idiotic - for instance, 1.29 is clearly closer to 1.5 than it is to 1.0.

Name: Anonymous 2010-02-07 20:07

>>60
well 1.75 is closer to 2 but 7/4 is 1 in most programming languages so whats your point fucker!

Name: Anonymous 2010-02-07 22:36

>>61
PYTHON 3 IS STANDARD.  GET OVER IT LISP WEENIE

Name: Anonymous 2010-02-07 22:55

>>61
Oh, stop being such a brainus.

Name: Anonymous 2010-02-07 23:19

>>63
hax my brainus

Name: Anonymous 2010-02-07 23:39

float round( float n ) { return ( (int)( ( n + 0.25f ) * 2.0f ) ) / 2.0f ) }

With correct rounding points, too.

Name: Anonymous 2010-02-08 0:31

>>60

Fuck, fine.

double round (double number)
{
    float test = (int)number;
    if      (number < (test + .25))
        return test;
    else if (number >= (test + .75))
        return test + 1.0;
    else
        return test + 0.5;
}

Name: Anonymous 2010-02-08 1:01

>>65,66
These are broken for negative numbers. Please make use of the standard library rounding functions, they're there for a reason.

Name: Anonymous 2010-02-08 1:29

>>67
You can't have negative cheeseburgers.

Name: Anonymous 2010-02-08 1:41

>>68
Fuck you bitch I can have negative cheeseburgers if I want to

Name: Anonymous 2010-02-08 3:09

>>69
IL_OP_U_MAD?

Name: Anonymous 2010-02-08 6:37

>>70
U_MAD?
Back to the imageboards, please.

Name: Anonymous 2010-02-08 8:27

Name: Anonymous 2010-02-08 9:15

>>72
``U MAD'' is still imageboard garbage.

Name: Anonymous 2010-02-08 13:19

>>73
``U_MAD'' is not.

Name: Anonymous 2010-11-15 5:56

Name: Anonymous 2010-12-26 2:45

Name: Anonymous 2011-01-31 21:04

<-- check em dubz

Name: Anonymous 2011-02-03 2:22


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List