LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2012, 10:08 AM   #16
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948

Quote:
Originally Posted by battler View Post
It's almost perfect, I get a "division by zero attempted" attempt on row 38 in the script.
I think you used the original version; I overlooked the "asterisk may be at the start of the next line instead of the end of the answer line" -issue. That I fixed in edit 1. In edit 2, I added logic that marks the final answer correct if none of the others were correct. (Oh, I'd better add a warning to standard output if that happens; that'll be marked edit 3.)
 
Old 04-15-2012, 11:17 AM   #17
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,999

Rep: Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190Reputation: 3190
Well mine isn't quite as in depth as NAs, but it seems to work on the data provided:
Code:
#!/usr/bin/awk -f

/^[1-9]/{
    print "::",gensub(/^[^[:alpha:]]+| \[.*/,"","g")
    print "::",gensub(/^[^[:alpha:]]+/,"","1")
    print "{"
}

/^[a-z]/{
    answer[++cnt] = substr($0,4)

    if(/\*/){
        correct[cnt]++
        answer[cnt] = substr(answer[cnt],1,length(answer[cnt])-1)
    }
    next
}

cnt && (/\*/ || /^$/){
    percentage = 0

    if(/\*/)
        correct[cnt]++

    for(x = 1; x <= cnt; x++){
        if(percentage)
            if(correct[x])
                printf "~%%%.2f%% %s\n",percentage,answer[x]
            else
                printf "~%%100%% %s\n",answer[x]
        else
            if(correct[x])
                print "=",answer[x]
            else
                print "~",answer[x]
    }

    print "}"

    cnt = 0
    delete correct
    delete answer
}
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex Find and Replace using sed or other tool marco114 Linux - Newbie 1 10-24-2011 05:42 PM
[SOLVED] differences between shell regex and php regex and perl regex and javascript and mysql golden_boy615 Linux - General 2 04-19-2011 01:10 AM
Perl to find regex and print following 5 lines after regex casperdaghost Linux - Newbie 3 08-29-2010 08:08 PM
regex with sed to process file, need help on regex dwynter Linux - Newbie 5 08-31-2007 05:10 AM
How to replace all occurances of a complex string using sed 6millionbucks Programming 6 08-12-2007 11:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration