Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Shaggar
Apr 26, 2006
the last time we had a fizzbuzz thread and everyone was writing their fizzbuzzes i started writing one up that used spring aop and then realized it wasnt funny

Adbot
ADBOT LOVES YOU

Bloody
Mar 3, 2013

answer fizz buzzes in machine code

and don't tell them which machine

Bloody
Mar 3, 2013

USSMICHELLEBACHMAN posted:

i'm also so loving bad at doing programming questions on the spot jesus

it's like all my critical thinking skills go out the window

i recently got the 'do a tic tac toe solver' questions which i've seen a bunch but i've just ignored because it's so easy but when i was actually sitting there programming i took forever

i once hosed up a for loop for array reversal on a whiteboard because i couldn't remember if it should be i < length or i <= length :downs:

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
half the beauty in fizzbuzz is it also filters out smartarses who refuse to play the game

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
speaking of, torpedo'd myself with a recruiter yesterday by showing less-than-absolute enthusiasm for the position. lesson learnt.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY

USSMICHELLEBACHMAN posted:

i'm also so loving bad at doing programming questions on the spot jesus

it's like all my critical thinking skills go out the window

i recently got the 'do a tic tac toe solver' questions which i've seen a bunch but i've just ignored because it's so easy but when i was actually sitting there programming i took forever

one of the textbooks im working through at the moment is How to Solve It: Modern Heuristics which is great with this kind of stuff. bit time intensive but if you feel it's a weakness of yours s worth a read

weird
Jun 4, 2012

by zen death robot
woah

Valeyard
Mar 30, 2012


Grimey Drawer
did someone do a LOLCODE fizzbuzz solution?

Luigi Thirty
Apr 30, 2006

Emergency confection port.

coffeetable posted:

speaking of, torpedo'd myself with a recruiter yesterday by showing less-than-absolute enthusiasm for the position. lesson learnt.

same but accidentally picking up a recruiter cold call and hanging up on him when he asked me how much i made in my position as a CJ at [chain store] then laying in bed for an hour hyperventilating

uhhh maybe i should go to a therapist instead of sh/sc

stoutfish
Oct 8, 2012

by zen death robot

Luigi Thirty posted:

same but accidentally picking up a recruiter cold call and hanging up on him when he asked me how much i made in my position as a CJ at [chain store]

that's p funny

MeruFM
Jul 27, 2010
in college, I applied for a poo poo tier CJ job
got a call a few weeks later at around 8-9am asking if i wanted to go in for an interview. Responded with "I think i'm busy on all days".
Took me an entire week before realizing what I did.

gonadic io
Feb 16, 2011

>>=
perhaps it's just because it's late but i'm having trouble with some physics behaviour in my latest sisyphean attempt at a game. it's in haskell but this particular question is language independent.

so the idea is that you have a sword in somebody's hand which i've, to start with, modelled as
code:
data SwordHand = SwordHand
    { handY        :: Float -- 0 is middle of the screen
    , wristAngle   :: Float -- 0 is horizontal
    , wristAngleV  :: Float -- differential of wristAngle
    } deriving (Eq, Show)
and then every timestep i do wristAngle += dt*wristAngleV (see below)

i.e. their hand can go up and (no horizontal movement) and can angle their wrist. the sword starts horizontal but can be flicked up and down which is what i can't get working.

actually applying the impulse to angle the sword away from the centreline is fine, i just add a constant to wristAngleV but then I want the sword to slow down and stop at a 45 degree (ish) angle before returning back to its resting position.

so far I have (in some kind of OO-like pseudocode)
code:
eps = 0.1

step swordhand dt = {
    arrestVelocity;
    wristAngle += dt*wristAngleV;
    wristAngleV := signum wristAngleV * straighten (abs wristAngleV)
        -- i.e. make straighten symmetrical for x < 0
    }
    where
    -- stop the sword from penduluming if close to the middle and moving towards it
    arrestVelocity = 
        if (abs wristAngle < eps && (signum wristAngle /= signum wristAngleV)) 
            {swordhand.wristAngle := 0; swordhand.wristAngleV := 0;}

    -- straighten the wrist slowly, assumes angleV > 0
    straighten angleV = angleV - wristAngle * dt * STRAIGHTEN_CONSTANT
but this isn't working at all, the sword just kind of stays still once i stop pushing up or down. sometimes the sword drifts a little but it certainly isn't the 'push away from horizontal then return back to the ready position' that i want

yes I know Euler integration is poo poo, no I don't care

DONT THREAD ON ME
Oct 1, 2002

by Nyc_Tattoo
Floss Finder
well i dont know what ur problem is there atomD but it reminds me that i really want to start doing more stuff with haskell.

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
sooo in this bit

code:
 straighten angleV = angleV - wristAngle * dt * STRAIGHTEN_CONSTANT
you're decelerating it proportional to the angle from horizontal. so at a large angle, once you let go of the keys the velocity drops very quickly to zero, and it should then go negative and ever more negative and take you back toward the horizontal

except this bit

code:
straighten(abs wristAngleV)
means you only ever pass it a positive value, which means the smallest value returned by straighten might be negative, but its gonna be very very close to zero (assumin yr constants are small). which means yr sword stays still.

suffix
Jul 27, 2013

Wheeee!
yeah the flipping thing won't work because you're not flipping the wristAngle

and i don't think you need it since the formula should always push your wrist towards 0 degrees :gay:

distortion park
Apr 25, 2011


USSMICHELLEBACHMAN posted:

i'm also so loving bad at doing programming questions on the spot jesus

it's like all my critical thinking skills go out the window

i recently got the 'do a tic tac toe solver' questions which i've seen a bunch but i've just ignored because it's so easy but when i was actually sitting there programming i took forever

i had an interview the other day and when i started describing a search implementation he jsut told me to use a library method instead. really want to work there

gonadic io
Feb 16, 2011

>>=


I rewrote it using the simple pendulum equation[1] and added a drag term (i.e. a force proportional to negative angular velocity) and it works, feels nice and fluid without waving back and forth for 10 minutes. Now to get mouse movement to control it then my JO simulator will be nearly complete!

[1]: http://en.wikipedia.org/wiki/Pendulum_(mathematics)

Nomnom Cookie
Aug 30, 2009



AlsoD posted:

perhaps it's just because it's late but i'm having trouble with some physics behaviour in my latest sisyphean attempt at a game. it's in haskell but this particular question is language independent.

so the idea is that you have a sword in somebody's hand which i've, to start with, modelled as
code:
data SwordHand = SwordHand
    { handY        :: Float -- 0 is middle of the screen
    , wristAngle   :: Float -- 0 is horizontal
    , wristAngleV  :: Float -- differential of wristAngle
    } deriving (Eq, Show)
and then every timestep i do wristAngle += dt*wristAngleV (see below)

i.e. their hand can go up and (no horizontal movement) and can angle their wrist. the sword starts horizontal but can be flicked up and down which is what i can't get working.

actually applying the impulse to angle the sword away from the centreline is fine, i just add a constant to wristAngleV but then I want the sword to slow down and stop at a 45 degree (ish) angle before returning back to its resting position.

so far I have (in some kind of OO-like pseudocode)
code:
eps = 0.1

step swordhand dt = {
    arrestVelocity;
    wristAngle += dt*wristAngleV;
    wristAngleV := signum wristAngleV * straighten (abs wristAngleV)
        -- i.e. make straighten symmetrical for x < 0
    }
    where
    -- stop the sword from penduluming if close to the middle and moving towards it
    arrestVelocity = 
        if (abs wristAngle < eps && (signum wristAngle /= signum wristAngleV)) 
            {swordhand.wristAngle := 0; swordhand.wristAngleV := 0;}

    -- straighten the wrist slowly, assumes angleV > 0
    straighten angleV = angleV - wristAngle * dt * STRAIGHTEN_CONSTANT
but this isn't working at all, the sword just kind of stays still once i stop pushing up or down. sometimes the sword drifts a little but it certainly isn't the 'push away from horizontal then return back to the ready position' that i want

yes I know Euler integration is poo poo, no I don't care

just let the engine do it sheesh

AWWNAW
Dec 30, 2008

coffeetable posted:

speaking of, torpedo'd myself with a recruiter yesterday by showing less-than-absolute enthusiasm for the position. lesson learnt.

i been working with a recruiter lately looking to relocate and they sent me an "opportunity" to work for a conservative lobbying group






















i start on monday

AWWNAW
Dec 30, 2008

lol jk

BONGHITZ
Jan 1, 1970

i would love to work for some republicans

i bet they are the best

stoutfish
Oct 8, 2012

by zen death robot

AWWNAW posted:

i been working with a recruiter lately looking to relocate and they sent me an "opportunity" to work for a conservative lobbying group





i start on monday

being a republican lobbyist is hilarious because you are actively working against your interests. there was a article about cutting lobbyists something it was a good article.

Valeyard
Mar 30, 2012


Grimey Drawer
why isnt sctp used as a replacement for tcp?

is it just the barriers of trying to adopt new protocols on the internet

MrMoo
Sep 14, 2000

Because the Internets routers will drop it. Thus Google made SPDY which is pretty much SCTP in user space.

Forums Terrorist
Dec 8, 2011

Valeyard posted:

why isnt sctp used as a replacement for tcp?

is it just the barriers of trying to adopt new protocols on the internet

that and :nsa:

suffix
Jul 27, 2013

Wheeee!

MrMoo posted:

Because the Internets routers will drop it. Thus Google made SPDY which is pretty much SCTP in user space.

it's not the routers, it's the nats and firewalls.

which makes it even harder to fix because that's end user owned equipment. the transport layer is pretty much locked to tcp/udp

MeruFM
Jul 27, 2010
can't newer routers just slowly seed in alternative transport layers with fallback to tcp/udp

pseudorandom name
May 6, 2007

that would require effort which is money and that is antithetical to consumer hardware design

a cyberpunk goose
May 21, 2007

https://www.youtube.com/watch?v=JEpsKnWZrJ8&t=80s

MononcQc
May 29, 2007

MeruFM posted:

can't newer routers just slowly seed in alternative transport layers with fallback to tcp/udp

maybe once IPv6 is there

power botton
Nov 2, 2011

why does google hate linode. is it jelly of their ipv6 rollout?

Brain Candy
May 18, 2006

MononcQc posted:

maybe once IPv6 is there

lol if you think NAT is ever going away, network janitors believe its for security now

no packets can be trusted without forms in triplicate

coffeetable
Feb 5, 2006

TELL ME AGAIN HOW GREAT BRITAIN WOULD BE IF IT WAS RULED BY THE MERCILESS JACKBOOT OF PRINCE CHARLES

YES I DO TALK TO PLANTS ACTUALLY
gonna do some dickin about in haskell this weekend as a break from c++. alsod/xml/famdav/i forget the other yospos haskelitists are: what're some particularly good examples of haskell libraries in terms of coding style n architecture?

gonadic io
Feb 16, 2011

>>=

coffeetable posted:

gonna do some dickin about in haskell this weekend as a break from c++. alsod/xml/famdav/i forget the other yospos haskelitists are: what're some particularly good examples of haskell libraries in terms of coding style n architecture?

lens :newlol:

the containers library shows common architecture patterns in nontrivial projects (consideration of strictness, cpp macros, repeated use of "go patterns" instead of naive recursion, even some fusion via RULE pragmas iirc)

anything by released Brian O'Sullivan is probably good
blog: http://www.serpentine.com/blog/
github: https://github.com/bos?tab=repositories
hackage: http://hackage.haskell.org/user/BryanOSullivan

the vector package is a prime example of heavy pointer/ffi use if you want to learn about that specifically

seriously though ekmett does take care to have nice code iirc so you might want to check that out afterwards (even if it does sometimes go off the deep end in terms of abstraction)

gonadic io fucked around with this message at 12:30 on May 1, 2014

gonadic io
Feb 16, 2011

>>=
the quintessential "go pattern" is

code:
map :: (a -> b) -> [a] -> [b]
map f = go
    where
    go [] = []
    go (x:xs) = f x : go xs
i.e. stop passing around things that you can just keep in scope. it also lets you set up some stuff that you don't want in your recursive call like:

code:
reverse :: [a] -> [a]
reverse = go []
    where
    go acc []     = acc
    go acc (x:xs) = go (x:acc) xs
e: i mean in both of these cases it could be expressed better using a fold but that's not always the case obv and go patterns let you have much better control over strictness using bang patterns
code:
map f = foldr (\x xs -> f x : xs) []
reverse = foldl (flip (:)) []

gonadic io fucked around with this message at 12:37 on May 1, 2014

FamDav
Mar 29, 2008
never heard it called a go pattern

cool

distortion park
Apr 25, 2011


AlsoD posted:

lens :newlol:

the containers library shows common architecture patterns in nontrivial projects (consideration of strictness, cpp macros, repeated use of "go patterns" instead of naive recursion, even some fusion via RULE pragmas iirc)



code:
balanceL :: a -> Set a -> Set a -> Set a
balanceL x l r = case r of
  Tip -> case l of
           Tip -> Bin 1 x Tip Tip
           (Bin _ _ Tip Tip) -> Bin 2 x l Tip
           (Bin _ lx Tip (Bin _ lrx _ _)) -> Bin 3 lrx (Bin 1 lx Tip Tip) (Bin 1 x Tip Tip)
           (Bin _ lx ll@(Bin _ _ _ _) Tip) -> Bin 3 lx ll (Bin 1 x Tip Tip)
           (Bin ls lx ll@(Bin lls _ _ _) lr@(Bin lrs lrx lrl lrr))
             | lrs < ratio*lls -> Bin (1+ls) lx ll (Bin (1+lrs) x lr Tip)
             | otherwise -> Bin (1+ls) lrx (Bin (1+lls+size lrl) lx ll lrl) (Bin (1+size lrr) x lrr Tip)

  (Bin rs _ _ _) -> case l of
           Tip -> Bin (1+rs) x Tip r

           (Bin ls lx ll lr)
              | ls > delta*rs  -> case (ll, lr) of
                   (Bin lls _ _ _, Bin lrs lrx lrl lrr)
                     | lrs < ratio*lls -> Bin (1+ls+rs) lx ll (Bin (1+rs+lrs) x lr r)
                     | otherwise -> Bin (1+ls+rs) lrx (Bin (1+lls+size lrl) lx ll lrl) (Bin (1+rs+size lrr) x lrr r)
                   (_, _) -> error "Failure in Data.Map.balanceL"
              | otherwise -> Bin (1+ls+rs) x l r
cool

distortion park
Apr 25, 2011


i find reading haskell so hard at the moment with all the pattern matching and lack of function brackets


maybe one day it'll be easier

distortion park
Apr 25, 2011


i'm fairly certain if i wasn't a dumb idiot i'd be confident enough to call haskell unreadable but i am so i just have to think it

Adbot
ADBOT LOVES YOU

gonadic io
Feb 16, 2011

>>=
you did pick the example in which two nested binary trees are probed, i don't think there's any language where needing to account for 12 or so different cases would be anything other than a whole load of code.

pointsofdata posted:

i find reading haskell so hard at the moment with all the pattern matching and lack of function brackets

maybe one day it'll be easier

everybody says the same thing and it will come in time, it helps that you can never have pattern matching in the same place as function application and vice versa - pattern matching always is in a function definition (between its name and "=") or in a lambda (between "\" and "->")

  • Locked thread