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.
 
  • Post
  • Reply
Maxxim
Mar 10, 2007

You're overcome by an indescribably odd sensation...!

dis astranagant posted:

I'm still having trouble wrapping my head around how that's even supposed to work. The words all parse but I just can't make the logic happen.

code:
( $ arg == 'B' ) ? 'bus' : ( $arg == 'A' ) => false

false ? 'airplane' : ( $arg == 'T' ) => true

true ? 'train' : ( $arg == 'C' ) => 'train'

'train' ? 'car' : ( $arg == 'H' ) => 'car'

'car' ? 'horse' : 'feet' => 'horse'

Adbot
ADBOT LOVES YOU

Maxxim
Mar 10, 2007

You're overcome by an indescribably odd sensation...!
Using AI to write code is backwards since the AI is constantly evolving. The code will always be better tomorrow - you should stay up to date instead.

code:
from openai import OpenAI

def is_even(value):    
    client = OpenAI()
    completion = client.chat.completions.create(
      model="gpt-3.5-turbo",
      # optimization hack - ask it to return the values True or False so we can skip the cast
      messages=[
        {"role": "system", "content": "i need to know if a number is even. reply with only a single word with the same capitalization: True or False. reply True if the number is even, False otherwise."},
        {"role": "user", "content": "is the following number even? " + str(value)}
      ]
    )

    return completion.choices[0].message.content

if __name__ == '__main__':
    print(is_even(5))
    print(is_even(-4412)) # test a negative number
    print(is_even(100001)) # test a really big number
    print(is_even(0))
code:
> python is_even.py
False
True
False
True

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply