Count Vowels in A list-Prolog

Page 1 of 1

4 Replies - 2790 Views - Last Post: 03 July 2013 - 09:02 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=323595&amp;s=99fe3fcf8c4269417f32ee50a6eab4c2&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 Ann1

• New D.I.C Head

Reputation: 0
• Posts: 10
• Joined: 13-November 12

Count Vowels in A list-Prolog

Posted 25 June 2013 - 05:07 AM

I'm new to prolog ,When I used the code below,I get the output as false
```cvowel([],0).
vowel([a],Counter):-Counter is 1.
vowel([e],Counter):-Counter is 1.
vowel([i],Counter):-Counter is 1.
vowel([o],Counter):-Counter is 1.
vowel([u],Counter):-Counter is 1.
vowel([_];[],Counter):-Counter is 0.
cvowel([H|T],Counter1):-cvowel(T,Count),vowel(H,Counter),Count is Count

+Counter,Counter1 is Counter1+Count.

```

Is This A Good Question/Topic? 0

Replies To: Count Vowels in A list-Prolog

#2 #define

• Duke of Err

Reputation: 1743
• Posts: 6,202
• Joined: 19-February 09

Re: Count Vowels in A list-Prolog

Posted 26 June 2013 - 01:14 PM

You are passing the head of the list to the vowel predicate, H is an element of a list.

```vowel(H,Counter)

```

So you don't need a list:

```vowel(a,Counter):-Counter is 1.

or

vowel(a, 1).

```

Was This Post Helpful? 1

#3 Ann1

• New D.I.C Head

Reputation: 0
• Posts: 10
• Joined: 13-November 12

Re: Count Vowels in A list-Prolog

Posted 02 July 2013 - 09:11 AM

then to hold a one value we don't need to put []
```	vowel(a,Counter):-Counter is 1.

```

Was This Post Helpful? 0

#4 #define

• Duke of Err

Reputation: 1743
• Posts: 6,202
• Joined: 19-February 09

Re: Count Vowels in A list-Prolog

Posted 02 July 2013 - 01:42 PM

Ann1, on 02 July 2013 - 05:11 PM, said:

then to hold a one value we don't need to put []

You are correct, the square brackets are used for lists and an empty list is [].
Was This Post Helpful? 0

#5 Ann1

• New D.I.C Head

Reputation: 0
• Posts: 10
• Joined: 13-November 12

Re: Count Vowels in A list-Prolog

Posted 03 July 2013 - 09:02 AM

Thank you.............
Was This Post Helpful? 0

Page 1 of 1

 .related ul{list-style-type:circle;font-size:12px;font-weight:bold;}.related li{margin-bottom:5px;background-position:left 7px!important;margin-left:-35px;}.related h2{font-size:18px;font-weight:bold;}.related a{color:blue;}