ivelin1012
-
Posts
5 -
Joined
-
Last visited
Never
Posts posted by ivelin1012
-
-
Have you tried simpler recursive functions? I think you need more practice with recursion before tackling this, because the basics are not there.
You can try factorial, reverse (make an array with the elements in the opposite order), "sum of array values" and "count of array values".
i have to present it till monday.I am trying to develop myself in the web design & programing . Never had any interest in encryption and software development. But i have to present this implementation till monday. It can be done with trees but those are dark waters for me
-
i'm very bad with recursion,with this function i tried to do this
if we have array ("B"=>5,"A"=>2,"C"=>1,"D"=>1)
B=>5
A=>2
C=>1
D=>1 on the first divide has to become :
up-array :B=>5;
down-array:
A=>2
C=>1
D=>1
and in the other array to write :
codeArray
B=>0
A=>1
C=>1
D=>1
down array divides again to :
up1:
A=>2;
down1:
C=>1
D=>1
and codeArray Becomes:
B=>0
A=>10
C=>11
D=>11
then down1 array divides into:
up2:
C=>1
down2:
D=>1
and codeArray Becomes:
B=>0
A=>10
C=>110
D=>111
recursion stops and prints codeArray
-
Allowed memory size of 134217728 bytes exhausted (tried to allocate 261904 bytes) in
from this sort
-
hello everyone i'm new to PHP and i need your help. I'm developing a code which implements shannon-fano encryption algorithm with php. But i have problems with my function.
Basicly i try to do this:
1.Specofy a string to be coded.
2.Count the number of occurences of a character and write it in assoc array like this : "A"=>4,"B"=>2 etc. then i copy this array
3.After i have the array i sort it descending.
4.Divide the given array into two arrays where the sum of the values is almost equal.In the Copied array i set the value of the elements which fit into the fisrt divided array with 0 the rest with 1.
5.Each of the divided arrays i divide with recursion again until every symbol is into different array.and add to the value in the copied array 0 or 1;
6.I try to print the copied array.
here is my function which doesnt work and gives a lot of errors
function divide_array($array)
{
$sum=0;
$mid=array_sum($array)/2;
foreach($array as $k=>$v)
{
if($sum<$mid){
$sum=$sum+$array[$k];
$up[$k]=$array[$k];
$codeArr[$k]=0;
}
else
{
$down=array_slice($array,$k+1);
$codeArr[$k]=1;
}
}
divide_array($up);
divide_array($down);
echo "<pre>";
print_r($codeArr);
echo "</pre>";
}
i appreciate any help
PS:I know this can be done easier with trees but i don't understand them.
Append symbol to assoc array value
in PHP Coding Help
Posted
hello i can't figure out how to modify a value from assoc array so with each recursion to add additional string to his:
for example i have
attribute="";
then call recursive function
and i try to modify its value by concatenating "0"; or "1";
on the next loop to add again "0" or "1";