Code Monkey home page Code Monkey logo

algorithm-php's People

Contributors

arvin2000dev avatar awesee avatar chenishr avatar lazyou avatar lookphp avatar m9rco avatar pfinal-nc avatar pushaowei avatar qishibo avatar sartoshi-foot-dao avatar wxxiong6 avatar wybcp avatar xaboy avatar xianyunyh avatar zhangxuanru avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

algorithm-php's Issues

关于查找算法的测试数组

一些查找算法的前提是 被查找的序列是顺序的 比如fibonacci查找, 测试的时候 那个数组不是顺序的

求蓄水池抽样算法

给定一个数据流,数据流长度N很大,且N直到处理完所有数据之前都不可知,请问如何在只遍历一遍数据(O(N))的情况下,能够随机选取出m个不重复的数据。

commit-msg

vim .git/hooks/commit-msg

放入以下代码

#!/bin/bash


msg=$(head -n 1 $1)

if echo $msg | grep -iqE "^Merge "; then
  exit 0
fi;

if echo $msg | grep -iqE "^Revert "; then
  exit 0
fi;

gitmoji=(
:art:
:zap:
:fire:
:bug:
:ambulance:
:sparkles:
:memo:
:rocket:
:lipstick:
:tada:
:white_check_mark:
:lock:
:apple:
:penguin:
:checkered_flag:
:robot:
:green_apple:
:bookmark:
:rotating_light:
:construction:
:green_heart:
:arrow_down:
:arrow_up:
:construction_worker:
:chart_with_upwards_trend:
:hammer:
:heavy_minus_sign:
:whale:
:heavy_plus_sign:
:wrench:
:globe_with_meridians:
:pencil2:
:hankey:
:rewind:
:twisted_rightwards_arrows:
:package:
:alien:
:truck:
:page_facing_up:
:boom:
:bento:
:ok_hand:
:wheelchair:
:bulb:
:beers:
:speech_balloon:
:card_file_box:
:loud_sound:
:mute:
)

i=$(awk 'BEGIN{srand();fr=int(48*rand());print fr;}')
basepath=$(dirname `pwd`"/"$1"/COMMIT_EDITMSG" ;)
echo $msg ${gitmoji[$i]} > $basepath;

if echo $msg | grep -iqE "^(feat|fix|docs|style|refactor|perf|test|chore)(\([^()]{1,}\)){0,1}: .{1,}"; then
  exit 0
fi;

echo
echo -e "\033[41mINVALID COMMIT MSG:\033[0m Does not match \"<type>(<scope>): <subject>\" !"
echo
cat <<EOF
Available types and what it mean are list here

  feat:     A new feature
  fix:      A bug fix
  docs:     Documentation only changes
  style:    Changes that do not affect the meaning of the code
            (white-space, formatting, missing semi-colons, etc)
  refactor: A code change that neither fixes a bug or adds a feature
  perf:     A code change that improves performance
  test:     Adding missing tests
  chore:    Changes to the build process or auxiliary tools
            and libraries such as documentation generation
EOF
echo -e "Please read http://www.ruanyifeng.com/blog/2016/01/commit_message_change_log.html"
echo

exit 1

Translate to English

Unfortunately, I do not speak, nor can I read Chinese.

However, this project seems interesting and from what I managed to translate using google seems like a really interesting read.

Hopefully, someone who is fluent in both English and Chinese can translate this.

If we plan on translating to more than one language it would be worthwhile creating an 'English' branch and other languages could follow suit.
If we plan on translating only to English then an English translation under the Chinese comments would be ideal.

建议示例跟代码剥离

建议示例跟代码剥离,写到专门的test里边去,然后建一个composer包来发布,这样别人使用和测试都比较方便

关于BubbleSortV2函数

您好,新人最近在学习您的这个算法合集,发现一个问题,希望能和您探讨一下!如果说错了还望海涵!

关于BubbleSortV2函数, 我觉得代码应该是这样

function BubbleSortV2(array $container)
{
    $count = count($container);
    for ($i = 0; $i < **_$count - 1_**; $i++) {
        for ($j = $i + 1; $j < $count; $j++) {
            if ($container[$i] > $container[$j]) {
                list($container[$i], $container[$j]) = array($container[$j], $container[$i]);
            }
        }
    }
    return $container;
}

原代码在比较的时候多进行了无意义的一轮。
假设$count = 4 ,即 $i = 3 的时候,还会进行一轮比较,这个时候 $j 都等于 4 了 里面的循环根本就不成立,还不如在之前就去掉,这样稍微严谨一点吧!

原代码如下

function BubbleSortV2(array $container)
{
    $len = count($container);
    // 也可以用foreach
    for ($i = 0; $i < $len; $i++) {
        for ($j = $i + 1; $j < $len; $j++) {
            if ($container[$i] > $container[$j]) {
                list($container[$i], $container[$j]) = array($container[$j], $container[$i]);
            }
        }
    }

    return $container;
}

print_r(BubbleSort([4, 21, 41, 2, 53, 1, 213, 31, 21, 423]));

如有错误,还望指正!!! 谢谢!!

快速排序算法中,和看到的c的实现不一样

在一本算法结构的书中,介绍的快速排序,每一趟排序都会去交换。
但这里的好像只是找到了比基准值大的和小的两个数组,然后最后再去合并。
书上的c的实现:
`int Quick(List R, int low, int high)
{
x=R[low];

while(low<high)
{
	while((low<high) && R[high].key >= x.key) 
	{
		high --;
	}
	R[low] = R[high];

	while(low<high && R[low].key <= x.key)
	{
		low++;
	}
	R[high] = R[low];
}

R[low] = x;
return low;

}

void QuickSort(List R, int low, int high)
{
if (low < high)
{
temp = Quick(R, low, high);
QuickSort(R, low, temp - 1);
QuickSort(R, temp + 1, high);
}
}`

Trying to get in touch regarding a security issue

Hi there,

I couldn't find a SECURITY.md in your repository and am not sure how to best contact you privately to disclose a security issue.

Can you add a SECURITY.md file with an e-mail to your repository, so that our system can send you the vulnerability details? GitHub suggests that a security policy is the best way to make sure security issues are responsibly disclosed.

Once you've done that, you should receive an e-mail within the next hour with more info.

Thanks! (cc @huntr-helper)

TODO

🔥 列几个小清单

  • 每周一推一道算法
  • 每周三推一道算法
  • 每周五推一道算法
  • 理解所学算法**

🚀 当然还有一些小事

  • 主动多拉几个志同道合的盆友进来优化并提供更多学习资料
  • 重写REDAME
  • 写个wiki
  • 记得有个前端代码预览的玩意儿写的比较好,什么时候拿过来用用,简直太棒

求帮助~ 给出一个处理方案

由于安全方面限制,要求我们不能保存用户的信用卡信息,包括信用卡过期时间.
但是可以通过一个 api, 单次调用获得 一个用户的 信用卡过期时间 .
现在要求 在用户信息用卡过期的前三天,给用户发送邮件通知 .

请问如何避免每天大量全库用户调用 API 来实现这个功能 .

(信用卡过期时间 为 年月 eg: 07/21 2021年07月过期 , 一般认为 当月的最后一天为过期时间)

二分叉递归查找有个问题

php 里面 0== 'default' 是 true 导致了执行到$top=0的时候重新赋值$top=10 死循环了

改成下面的方式

    if (!is_numeric($top) && $top == 'default')
    {
        $top = count($container);
    }

快排正确写法

public function QulickSort(array $container){
        $count = count($container);
        if ($count <=1 ) {
            return $container;
        }
        $left = $right = [];
        for ( $i = 1; $i<$count; $i++ ){
            if ( $container[$i] <= $container[0] ){
                $left[] = $container[$i];
            } else {
                $right[]= $container[$i];
            }
        }

        $left = $this->QulickSort($left);
        $right = $this->QulickSort($right);

        return array_merge($left,[$container[0]],$right);
    }

更好的理解建议

/**

  • BubbleSort
  • 冒泡排序,依次比较相邻的两个元素的大小,如果前面的大于后面的,那么交换两者位置
  • @param array $container
  • @return array
    */
    function BubbleSort(array $container)
    {
    $count = count($container);
    for ($j = 1; $j < $count; $j++) {
    for ($i = 0; $i < $count - $j; $i++) {
    if ($container[$i] > $container[$i + 1]) {
    $temp = $container[$i];
    $container[$i] = $container[$i + 1];
    $container[$i + 1] = $temp;
    }
    }
    $str = "第" . $j . "步排序结果";
    $res = $str . implode(',', $container);
    printf("%s\n",$res);
    }
    return $container;
    }

BubbleSort([4, 21, 41, 2, 53, 1, 213, 31, 21, 423]);

/*
第1步排序结果4,21,2,41,1,53,31,21,213,423
第2步排序结果4,2,21,1,41,31,21,53,213,423
第3步排序结果2,4,1,21,31,21,41,53,213,423
第4步排序结果2,1,4,21,21,31,41,53,213,423
第5步排序结果1,2,4,21,21,31,41,53,213,423
第6步排序结果1,2,4,21,21,31,41,53,213,423
第7步排序结果1,2,4,21,21,31,41,53,213,423
第8步排序结果1,2,4,21,21,31,41,53,213,423
第9步排序结果1,2,4,21,21,31,41,53,213,423
*/

BubbleSortV2应该不是冒泡排序了吧

function BubbleSortV2(array $container)
{
$len = count($container);
// 也可以用foreach
for ($i = 0; $i < $len; $i++) {
for ($j = $i + 1; $j < $len; $j++) {
if ($container[$i] > $container[$j]) {
list($container[$i], $container[$j]) = array($container[$j], $container[$i]);
}
}
}

return $container;

}

这样不是稳定排序了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.