#recursion

写代码的时候,要有基本的语言常识,比如Python,你就不能忽视语言本身的特点随便乱写。
20万次递归的结果:

纯Python代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,
621,622,623,624,625,626,627,628,629,630,631,632,633,634,635,636,637,638,639,640,641,642,
643,644,645,646,647,648,649,650,651,652,653,654,655,656,657,658,659,660,661,662,663,664,
665,666,667,668,669,670,671,672,673,674,675,676,677,678,679,680,681,682,683,684,685,686,
687,688,689,690,691,692,693,694,695,696,697,698,699,700,701,702,703,704,705,706,707,708,
709,710,711,712,713,714,715,716,717,718,719,720,721,722,723,724,725,726,727,728,729,730,
731,732,733,734,735,736,737,738,739,740,741,742,743,744,745,746,747,748,749,750,751,752,
753,754,755,756,757,758,759,760,761,762,763,764,765,766,767,768,769,770,771,772,773,774,
775,776,777,778,779,780,781,782,783,784,785,786,787,788,789,790,791,792,793,794,795,796,
797,798,799,800,801,802,803,804,805,806,807,808,809,810,811,812,813,814,815,816,817,818,
819,820,821,822,823,824,825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,
841,842,843,844,845,846,847,848,849,850,851,852,853,854,855,856,857,858,859,860,861,862,
863,864,865,866,867,868,869,870,871,872,873,874,875,876,877,878,879,880,881,882,883,884,
885,886,887,888,889,890,891,892,893,894,895,896,897,898,899,900,901,902,903,904,905,906,
907,908,909,910,911,912,913,914,915,916,917,918,919,920,921,922,923,924,925,926,927,928,
929,930,931,932,933,934,935,936,937,938,939,940,941,942,943,944,945,946,947,948,949,950,
951,952,953,954,955,956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,
973,974,975,976,977,978,979,980,981,982,983,984,985,986,987,988,989,990,991,992,993,994,
995,Traceback (most recent call last):
File "./tt.py", line 3, in <module>
cur(0, 200000)
File "test.py", line 12, in t.cur
File "test.py", line 12, in t.cur
File "test.py", line 12, in t.cur
[Previous line repeated 993 more times]
File "test.py", line 6, in t.cur
RecursionError: maximum recursion depth exceeded while getting the str of an object

最大996 :)

Python动态库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
174133,174134,174135,174136,174137,174138,174139,174140,174141,174142,174143,174144,174145,
174146,174147,174148,174149,174150,174151,174152,174153,174154,174155,174156,174157,174158,
174159,174160,174161,174162,174163,174164,174165,174166,174167,174168,174169,174170,174171,
174172,174173,174174,174175,174176,174177,174178,174179,174180,174181,174182,174183,174184,
174185,174186,174187,174188,174189,174190,174191,174192,174193,174194,174195,174196,174197,
174198,174199,174200,174201,174202,174203,174204,174205,174206,174207,174208,174209,174210,
174211,174212,174213,174214,174215,174216,174217,174218,174219,174220,174221,174222,174223,
174224,174225,174226,174227,174228,174229,174230,174231,174232,174233,174234,174235,174236,
174237,174238,174239,174240,174241,174242,174243,174244,174245,174246,174247,174248,174249,
174250,174251,174252,174253,174254,174255,174256,174257,174258,174259,174260,174261,174262,
174263,174264,174265,174266,174267,174268,174269,174270,174271,174272,174273,174274,174275,
174276,174277,174278,174279,174280,174281,174282,174283,174284,174285,174286,174287,174288,
174289,174290,174291,174292,174293,174294,174295,174296,174297,174298,174299,174300,174301,
174302,174303,174304,174305,174306,174307,174308,174309,174310,174311,174312,174313,174314,
174315,174316,174317,174318,174319,174320,174321,174322,174323,174324,174325,174326,174327,
174328,174329,174330,174331,174332,174333,174334,174335,174336,174337,174338,174339,174340,
174341,174342,174343,174344,174345,174346,174347,174348,174349,174350,174351,174352,174353,
174354,174355,174356,174357,174358,174359,174360,174361,174362,174363,174364,174365,174366,
174367,174368,174369,174370,174371,174372,174373,174374,174375,174376,174377,174378,174379,
174380,174381,174382,174383,174384,174385,174386,174387,174388,174389,174390,174391,174392,
174393,174394,174395,174396,174397,174398,174399,174400,174401,174402,174403,174404,174405,
174406,174407,174408,174409,174410,174411,174412,174413,174414,174415,174416,174417,174418,
174419,174420,174421,174422,174423,174424,174425,174426,174427,174428,174429,174430,174431,
174432,174433,174434,174435,174436,174437,174438,174439,174440,174441,174442,174443,174444,
174445,1744fish: “python ./t.py” terminated by signal SIGSEGV (Address boundary error)

最大174447

Python的C模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
199593,199594,199595,199596,199597,199598,199599,199600,199601,199602,199603,199604,199605,
199606,199607,199608,199609,199610,199611,199612,199613,199614,199615,199616,199617,199618,
199619,199620,199621,199622,199623,199624,199625,199626,199627,199628,199629,199630,199631,
199632,199633,199634,199635,199636,199637,199638,199639,199640,199641,199642,199643,199644,
199645,199646,199647,199648,199649,199650,199651,199652,199653,199654,199655,199656,199657,
199658,199659,199660,199661,199662,199663,199664,199665,199666,199667,199668,199669,199670,
199671,199672,199673,199674,199675,199676,199677,199678,199679,199680,199681,199682,199683,
199684,199685,199686,199687,199688,199689,199690,199691,199692,199693,199694,199695,199696,
199697,199698,199699,199700,199701,199702,199703,199704,199705,199706,199707,199708,199709,
199710,199711,199712,199713,199714,199715,199716,199717,199718,199719,199720,199721,199722,
199723,199724,199725,199726,199727,199728,199729,199730,199731,199732,199733,199734,199735,
199736,199737,199738,199739,199740,199741,199742,199743,199744,199745,199746,199747,199748,
199749,199750,199751,199752,199753,199754,199755,199756,199757,199758,199759,199760,199761,
199762,199763,199764,199765,199766,199767,199768,199769,199770,199771,199772,199773,199774,
199775,199776,199777,199778,199779,199780,199781,199782,199783,199784,199785,199786,199787,
199788,199789,199790,199791,199792,199793,199794,199795,199796,199797,199798,199799,199800,
199801,199802,199803,199804,199805,199806,199807,199808,199809,199810,199811,199812,199813,
199814,199815,199816,199817,199818,199819,199820,199821,199822,199823,199824,199825,199826,
199827,199828,199829,199830,199831,199832,199833,199834,199835,199836,199837,199838,199839,
199840,199841,199842,199843,199844,199845,199846,199847,199848,199849,199850,199851,199852,
199853,199854,199855,199856,199857,199858,199859,199860,199861,199862,199863,199864,199865,
199866,199867,199868,199869,199870,199871,199872,199873,199874,199875,199876,199877,199878,
199879,199880,199881,199882,199883,199884,199885,199886,199887,199888,199889,199890,199891,
199892,199893,199894,199895,199896,199897,199898,199899,199900,199901,199902,199903,199904,
199905,199906,199907,199908,199909,199910,199911,199912,199913,199914,199915,199916,199917,
199918,199919,199920,199921,199922,199923,199924,199925,199926,199927,199928,199929,199930,
199931,199932,199933,199934,199935,199936,199937,199938,199939,199940,199941,199942,199943,
199944,199945,199946,199947,199948,199949,199950,199951,199952,199953,199954,199955,199956,
199957,199958,199959,199960,199961,199962,199963,199964,199965,199966,199967,199968,199969,
199970,199971,199972,199973,199974,199975,199976,199977,199978,199979,199980,199981,199982,
199983,199984,199985,199986,199987,199988,199989,199990,199991,199992,199993,199994,199995,
199996,199997,199998,199999,200000

完美的递归。

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×