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

/prog/ Challenge -- Hydrocarbons [Heroic]

Name: Anonymous 2010-08-08 17:50

The challenge: Develop a program that takes in the notation of a hydrocarbon in standard form, and outputs a correct ball-and-stick graphical representation of that hydrocarbon.

The Deadline: 2010-08-30 20:00

Your implementation will be judged based on the following guidelines:


1. Accuracy
2. Consistency
3. Run time
4. Clarity of output
5. Code readability
6. Overall functionality


Good Luck!

Name: Anonymous 2010-08-08 17:59

HOMEWORK. GOOD LUCK FINDING SATORI.

Name: Anonymous 2010-08-08 18:05

>>1
2010-08-30
But there are only 12 months!!

Name: Anonymous 2010-08-08 18:07

But I'm already done with heroics.

Name: Anonymous 2010-08-08 18:38

>>3
US date notation.
PIG DISGUSTING.

Name: Anonymous 2010-08-08 19:55

>>5
DATE MY ANUS

Name: Anonymous 2010-08-08 20:15

>>6
About 6-7 years.

Name: Anonymous 2010-08-08 21:14

>>6
Still young and tender.

Name: Anonymous 2010-08-08 23:00

Is this a joke. TOO HARD!

Name: Anonymous 2010-08-08 23:39

>>9
Not so much.
1) First you have to see if the electrons balance out, which also indicates how the covalent or ionic bonds work.  Try starting with larger atoms and connect the atoms with the smallest number of available electrons first, and keep going from there.
2) Then you use the number of atoms and their masses and radii to determine bonding angles and relative distances.
3) The modeling is as easy as your language permits from that point onward.

There is probably more detail that can be gone into but that is the kind of thing a person who understands chemistry will implement.
I never passed a molecular chemistry course with anywhere near good marks.

Name: Anonymous 2010-08-09 0:09

Fuck your ball-and-stick model.

#!/bin/bash

if [ -z $(type -t seq) ]; then
    seq()
    {
        local i
        i=1

        while [ $i -lt $1 ]; do
            echo $i
            let i++
        done

        echo $1
    }
fi

flat_model()
{
    local i

    echo -n " "
    for i in `seq $1`; do echo -n "  H"; done
    echo -en "\n "
    for i in `seq $1`; do echo -n "  |"; done
    echo -en "\nH"
    for i in `seq $1`; do echo -n "--C"; done
    echo -en "--H\n "
    for i in `seq $1`; do echo -n "  |"; done
    echo -en "\n "
    for i in `seq $1`; do echo -n "  H"; done
    echo
}

display_flat()
{
    REGEX="^C([0-9]+)H([0-9]+)$"

    if [[ $1 =~ $REGEX ]]; then
        CARBON=${BASH_REMATCH[1]}
        HYDROGEN=${BASH_REMATCH[2]}
        let EXPECTED_HYDROGEN=$CARBON*2+2

        if [[ $EXPECTED_HYDROGEN != $HYDROGEN ]]; then
            echo -e "Unexpected number of hydrogen atoms: \033[1m$1\033[0m" &2>1
            return
        fi

        flat_model $CARBON

    else
        echo -e "Input is not a hydrocarbon: \033[1m$1\033[0m" &2>1
        return
    fi
}


if [ $# -lt 1 ]; then
    echo "Usage: $0 C2H6" &2>1
    exit 1
fi

while [ 1 ]; do
    display_flat $1
    shift
    [ -z $1 ] && exit
done

Name: Anonymous 2010-08-09 0:20

>>11
Excuse me Sir, but your program seems to be intolerant; it is discriminating against my benzene.

Name: Anonymous 2010-08-09 0:31

Oh, right. I keep forgetting there are more hydrocarbons than just the alkanes.

Name: Anonymous 2010-08-09 2:49

There isn't enough information in the ``standard form'' (I'm assuming you mean the straightforward chemical formula; define what you mean if that isn't it) to compose the ball-and-stick representation. Unless you want something that will show you all possible structural isomers, in which case fuck you.

Name: Anonymous 2010-08-09 5:38

>>14
You assume correct.

Name: Anonymous 2010-08-09 5:48

Alkanes are easy. Alkenes might be quite easy I cant remember. Its been 11 years since I took chemistry classes.

Name: Anonymous 2010-08-09 14:03

Alkanes are incredibly easy. Its the other crap that sucks.

Name: Anonymous 2010-08-09 14:06

>>14
You know, some hydrocarbons have thousands of isomers. Why would you even assume that's what OP ment. Did you really think he would be willing to take the time to check THAT many molecular representations?

Name: Anonymous 2010-08-09 14:38

What about Alkynes, Arenes and Buckminsterfullerene?

Name: Anonymous 2010-08-09 14:40

>>19
What about Icanthinkupnamestoo?

Name: Anonymous 2010-08-09 14:50

Name: Anonymous 2010-08-09 14:54

Fullerenes aren't hydrocarbons. They don't contain any hydrogen.

Name: Anonymous 2010-08-09 15:34

Oh no! How dare you make a challenge that involves chemistry! Do I look like a chemist to you

Name: Anonymous 2010-08-09 18:40

uuu

Name: Anonymous 2010-08-09 19:30

What about we replace "hydrocarbon" with "DNA?"  would that make the project remotely feasible?

>>24
Be quiet, Maria.

Name: Anonymous 2010-08-09 19:59

>>25
#!/bin/bash

DNA[0]="\-|"
DNA[1]=" \ "
DNA[2]="|-\\"

REGEX="^[CGAT]+$"

if [[ $1 =~ $REGEX ]]; then
    i=0

    for gene in `echo $1 | sed 's/[CGAT]/&\n/g'`; do
        let j=$i%3
        echo " ${DNA[$j]} $gene"
        let i++
    done

else
    echo -e "Usage: \033[1m$0 CCGATTCA\033[0m" &2>1
fi

Name: Anonymous 2010-08-09 22:10

This code solves the problem of finding connected multigraphs without self-edges with C vertices of degree 4 and H vertices of degree 1. No pruning or further checking is done.

Returned are the edges of the C vertices. Adding the H edges and visualising the graph is left as an exercise for the reader.

#lang racket

(require racklog)

(define (main)
  (let/ec break
    (displayln "Amount of carbon atoms?")
    (define C (string->number (read-line)))
    (displayln "Amount of hydrogen atoms?")
    (define H (string->number (read-line)))
    (when (or (not (integer? C))
              (not (positive? C))
              (not (integer? H))
              (not (positive? H))
              (odd? H))
      (displayln "Invalid input")
      (break))
   
    (define C-bonds (/ (- (* C 4) H) 2))
   
    (define %bind
      (%rel (i j n a b)
        ((i j n a b)
         (%=:= n 0) !
         (%= b empty))
        ((i j n a b)
         (%>= i C) !
         %fail)
        ((i j n a b)
         (%or (%is 4 (hash-ref a i 0)) (%>= j C)) !
         (%let (i* j*)
           (%and
            (%is i* (+ i 1))
            (%is j* (+ i* 1))
            (%bind i* j* n a b))))
        ((i j n a b)
         (%is #t (< (hash-ref a j 0) 4))
         (%let (n* a-i a-ij b*)
           (%and
            (%is n* (- n 1))
            (%is a-i (hash-update a i add1 0))
            (%is a-ij (hash-update a-i j add1 0))
            (%bind i j n* a-ij b*)
            (%= b (cons (list i j) b*)))))
        ((i j n a b)
         (%let (j*)
           (%and
            (%is j* (+ j 1))
            (%bind i j* n a b))))))
   
    (define %connect
      (%rel (i j a b)
        ((i j a b)
         (%>= i C) !
         (%bind 0 1 (- C-bonds (- C 1)) a b))
        ((i j a b)
         (%>= j i) !
         %fail)
        ((i j a b)
         (%let (j*)
           (%and
            (%is j* (+ j 1))
            (%connect i j* a b))))
        ((i j a b)
         (%is #t (< (hash-ref a j 0) 4))
         (%let (i* a-i a-ij b*)
           (%and
            (%is a-i (hash-update a i add1 0))
            (%is a-ij (hash-update a j add1 0))
            (%is i* (+ i 1))
            (%connect i* 0 a-ij b*)
            (%= b (cons (list j i) b*)))))))
   
    (displayln (cdar (%which (b) (%connect 1 0 (make-immutable-hash empty) b))))
    (let loop ()
      (displayln "Press enter for another result")
      (let ((ln (read-line)))
        (when (not (eof-object? ln))
          (displayln (cdar (%more)))
          (loop))))))

(main)

Name: Anonymous 2010-08-09 22:21

>>27
So actually doing what was asked in >>1 is left as an exercise.

Name: Anonymous 2010-08-10 1:50

>>11
I barfed out my ass, but was intrigued

Name: Anonymous 2010-08-10 2:14

>>11,26
Xarn, or just someone inspired by Xarn's latest Github project?

Name: Anonymous 2010-08-10 4:53

>>30
I'm pretty sure OP is Xarn.

Name: Anonymous 2010-08-10 5:25

I never did any chemistry, but if you describe the input -> output transformation for such a "standard form" in layman's terms I will put an entry in.

Name: Anonymous 2010-08-10 5:35

>>32
rephrase that sentence using faggot quotes

Name: Anonymous 2010-08-10 5:41

>>31
Xarn would have used a proper em dash.
>>32
You're an idiot if you dismiss this project because you don't know chemistry. Not to mention that alkanes, alkenes, alkynes, and cycloalkanes are high school chemistry.

Name: Anonymous 2010-08-10 6:26

>>34
You're an idiot if you dismiss people for not knowing chemistry. It's not compulsory in the country I was educated in, so I didn't take it.

If the chemistry is as simple as claimed, I'm sure it's not too much to ask that you reproduce the production rules here for brevity. If it is not, I have little interest in reading a book or researching something which is of little practical use to me to participate in what should be a programming challenge. Perhaps this thread should be relocated to /sci/?

Name: Anonymous 2010-08-10 6:55

>>35
It's all there on the Wikipedia page, dolt.

Name: Anonymous 2010-08-10 8:03

>>36
Great! Then I look forward to your reproduction of the relevant text right here on this board.

Name: Anonymous 2010-08-10 10:21

>>34
what about beta lactones?

Name: Anonymous 2010-08-10 11:47

>>35
Americans always get so defensive when their ignorance is laid bare. Your secondary education is an international laughing stock, and your own laziness seems to be typical of your countrymen. Maybe the two problems are related.

Name: Anonymous 2010-08-10 11:58

>>38
Not a hydrocarbon.

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