Sam54

5 Reputation

3 Badges

13 years, 327 days

MaplePrimes Activity


These are questions asked by Sam54

Hi I'm trying to write a proc to takes a character and a string as inputs and as output tells you how many times the character shows up in the string.
I don't know what is wrong with the code


 s:=proc(Z)

local counts,C,i,L:

for C from "a" to "z" do
counts[C]:= 0:
end do:
L:=length(Z):
for i from 1 to L do
C:=Z[i];
if C >= "a" and C <= "z" then
counts[C] := counts[C] + 1
end if;
print(C,counts):

Code
 

L:={NULL}:
for q from 11 to 100
check:=0:
for p from 1 to 200
n:=length(p):
for i from 1 to n
a[i]:=p[i]:
s:=sum(a[i],i=2..n)
if p-a[1]-10*s*modq=0 then
check:=check+1:
if check=200 then
L:=L{op(L),q}:
print(L);

and the pseudocode:
1. L is the empty set
2. for q from 11 to 100
3. check=0
4. for p from 1 to 200
5. find n, the number of digits of p
6. for i from 1 to n
7. find a[i], the ith digit of p

Here is my code , could you please tell me where i'm going wrong... isn't plotting anything

Fern :=proc(n);
local pick,n;
n := NULL;
for n from 1 to n do 
pick := rand();
if pick < 0.01 then
x[n+1] := 0;
y[n+1] := 0.16*y[n];

else if pick < 0.01 + 0.85 then
x[n+1] := 0.85*x[n] + 0.04*y[n] + 0;
y[n+1] := -0.04*x[n] + 0.85*y[n] + 1.6;
else if pick < 0.01 + 0.85 + 0.07 then
x[n+1] := 0.2*x[n] - 0.26*y[n] + 0;
y[n+1] := 0.23*x[n] + 0.22*y[n] + 1.6;

Question: (how to do this)

Write a procedure that takes as input a lowercase text string and returns a list 26 integers.
the fist entry is a count of the number of letter 'a's,the second the number of lette 'b's ,.... , the 26th the numberof letter 'z'.


Thank you 

Page 1 of 1