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

Pages: 1-

Simple math question

Name: Anonymous 2009-12-15 13:56

Hey /bros/, excuse me while I try to come up with the words to explain this basic math concept. I'm trying to "round" values into steps, like so:

1 2 3 4 5 6 7 8 9

might become

1 1 1 4 4 4 7 7 7

or

1 1 1 1 1 6 6 6 6

I know there's a mathematical operation that can do this. If you were to graph the values, let's say as compared to y = x,  it would look like stairs instead of a straight line. (I'm pretty sure that with the right mathematical function the "step size" could be arbitrary.) I know this must be elementary school-level math and yet nothing is coming to me. Any ideas?

Name: Anonymous 2009-12-15 14:11

Define the intervals for splitting and how to round a value down to its interval(for example the start of end value of the interval), rest should be trivial.

Name: Anonymous 2009-12-15 14:13

I don't think there is a name for this operation, if it's for a program just write a function like
(define (my-round num step)
  (* (round (/ num
               step))
     step))

Name: Anonymous 2009-12-15 14:18

[expert]
import math

def xround(val, step):
    num_raters = 1
    def LEAHround(star_sum):
        # 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))
        return stars
    return int(math.floor(LEAHround(val))//step)+1

print "example:"
for vv in xrange(12):
    print xround(vv, 3)
[/expert]

Name: Leah Culver !1LEahRIBg. 2009-12-15 14:21

>>4
That's not funny, bro

Name: Anonymous 2009-12-15 14:30

((n-1)/3)*3+1
((n-1)/6)*6+1


Where / denotes integer (truncated) division.

Also ducking trivial, this is fucking Leah Culver level.

Name: Anonymous 2009-12-15 14:39

Prelude> let myRound n = map (\x -> (truncate (x/n))*n)
Prelude> myRound 3 [0..14]

<interactive>:1:0:
    Ambiguous type variable `t' in the constraints:
      `Integral t'
        arising from a use of `myRound' at <interactive>:1:0-16
      `RealFrac t'
        arising from a use of `myRound' at <interactive>:1:0-16
    Probable fix: add a type signature that fixes these type variable(s)

?
How do I add typesigs in ghci? And what's exactly wrong?

Name: Anonymous 2009-12-15 14:54

>>6
I've fuck Leah Culver, if you know what I mean.

Name: Leah Culver !1LEahRIBg. 2009-12-15 14:57

>>8
I don't think I do, please elaborate.

Name: Anonymous 2009-12-15 16:05

OP here.
With your help I worked it out to floor(num/step) * step + step.

Many thanks!

Name: Anonymous 2009-12-15 16:10

>>10

You can't possibly be this retarded. Did you even test it?

Not saging for public humiliation.

Name: Anonymous 2009-12-15 16:36

>>11
You can't possibly be this retarded.
It is surprisingly common for people to be this retarded.

Name: Anonymous 2009-12-15 17:36

> (define step-size 4)
(map (λ(x) (* step-size (quotient x step-size))) (build-list 20 values))
(0 0 0 0 4 4 4 4 8 8 8 8 12 12 12 12 16 16 16 16)
(map (λ(x) (- x (modulo x step-size))) (build-list 20 values))
(0 0 0 0 4 4 4 4 8 8 8 8 12 12 12 12 16 16 16 16)
dicks

reference to an identifier before its definition: dicks
>

Name: Anonymous 2009-12-15 19:22

GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> dicks

*** Exception: stack overflow

Name: Anonymous 2009-12-15 19:50

:? for help
meme fail

Name: Anonymous 2009-12-15 21:46

>>15
fuck you, I invented this meme and someone else tried to hijack it.

Name: Anonymous 2009-12-15 22:50

>>10,11
Not sure what you're getting at, since the formula I posted worked exactly as I needed it to. What am I missing?

Name: Anonymous 2009-12-15 23:25

>>17
Not sure what you're getting at, since the formula in >>10 certainly won't match the examples in >>1 regardless of the step value.

Name: ajcates 2009-12-15 23:42

if your lazy and rich get a mac.

Name: Anonymous 2009-12-15 23:57

>>> [(n - ((n - 1) % 3)) for n in range(1, 10)]
[1, 1, 1, 4, 4, 4, 7, 7, 7]

Name: Anonymous 2009-12-16 3:37

Are you working in discrete values or continuous functions? Some algorithms have been proposed so far, but none works for the general case, and they all assume sampled values.

Getting the average of an arbitrary function over an area isn't "elementary school level". What you want is to integrate the function between two bounds a and b, then divide the result by (b-a), which will give you the average. I'll assume that you want your function sampled between the intervals 0-1,2-3,4-5... for simplicity, but your new function can be expressed rather simply as:

f'(x) = integral from (floor x) to (ceil x) of f(x)

In the case of a sampled function, you can use the definition of an integral as a sum of differences and get the equivalent expression. Integral becomes a sum, you'll have to divide by your deltax, and update bounds accordingly.

Your solution in >>10 will work only for the special case of y = x.

Name: Anonymous 2009-12-16 8:41

steps incr = concatMap (replicate incr) [1, 1 + incr..]

Name: >>22 2009-12-16 9:03

Nevermind my previous post, I had just skimmed through the OP and, consequently, got it wrong.

Name: Anonymous 2009-12-16 9:59

>>21
Hello Xarn. Now that you have posted that, I'm actually a little ashamed of myself for not remembering this. :(

Name: Anonymous 2009-12-16 13:06

>>21
Getting the average of an arbitrary function over an area
OP asks about a step function
sweet sage

Name: HMA 2009-12-16 13:21

>>24
Actually, I am not Xarn. He's too busy decoding ISBNs and bitching about Cisco to post here.
>>25
Sage my anus.

Name: HMA MEME FAN 2009-12-16 13:37

>>26
LOL

Name: Anonymous 2010-12-17 1:24

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Anonymous 2010-12-26 23:16

Name: Anonymous 2013-09-02 13:00


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