On 12 Sep 2006 at 12:00, [EMAIL PROTECTED] wrote:

> To cut to the chase: raw_input() provides an extremely useful
> I/O function for simple exercise type problems which are so essential
> in building a beginners repertoire of programming techniques and
> for 'John Zeller' type problems ( simple quick  dirty and effective
> solutions that get those housekeeping jobs done).

Again, inputs to functions (or procedures), and the prompt, can
replace raw_input, as in my first example (simple guessing games).

I define the following procedures:

to palindrome? :n
if 2 > count :n [output "true]
if (first :n) = (last :n) [output palindrome? butfirst butlast :n]
output "false
end

to make.pal :n
print :n
if palindrome? :n [stop]
make.pal :n + reverse :n
end



Then, at the prompt:

show palindrome? 121
true

I can press the "Trace" button, and I get:

show palindrome? 121
( palindrome? 121 )
 ( palindrome? 2 )
 palindrome? outputs "true
palindrome? outputs "true

true

show palindrome? 123211
( palindrome? 123211 )
 ( palindrome? 2321 )
 palindrome? outputs "false
palindrome? outputs "false

false


Anyway:

make.pal 423
423
747

make.pal random 1000
739
1676
8437
15785
74536
138083
518914
938729
1866568
10523249
104755750
162313151
313626412
528252725
1055505550
1610561051
3112211212
5233333325

make.pal random 1000
507
1212
3333

make.pal random 1000
600
606

make.pal 879
879
1857
9438
17787
96558
182127
903408
1707717
8884788
17759676
85455447
159910905
668930856
1326970722
3597766953
7194444906
13288889823
46187778054
91275556218
172541113437
906852258708
1714704517317
8851858591488
17693817173076
84730989012747
159452087916495
754071868171446
1.3982437363419e+15
+ doesn't like 51+e9143637342893.1 as input  in make.pal


I can modify my make.pal procedure, to use lsum instead
of "+".

to make.pal :n
print :n
if palindrome? :n [stop]
make.pal lsum :n reverse :n
end



make.pal 879
879
1857
9438
17787
96558
182127
903408
1707717
8884788
17759676
85455447
159910905
668930856
1326970722
3597766953
7194444906
13288889823
46187778054
91275556218
172541113437
906852258708
1714704517317
8851858591488
17693817173076
84730989012747
159452087916495
754071868171446
1398243736341903
4489680109770834
8870459120640678
17630919340181466
84049023732085137
157207047464179185
739178512204881936
1378366914420753873
5161937158617392604
9224874327134784219
18349748644369568448
102836344989054362829
1031099795978498001030
1332108744774477902331
2664206489548955914662
5328402088008801939324
9567793176017603987559
19125686243124317965218
100382657585258586617409
1005099343437844342900410
1145191777925187782805411
2290274655740485554720822
4570549211580961119441744
9041998323271812248892498
17984986745453535487883907
88923865198988990256832878
176747730408977979413665866
845314045388757783451413537
1580628199776515666991827085
7387910196441672446910087936
13785710392884433893820285773
51543913232717882723122044504
92087935365446754446353979019
183185870729892518902707957048
1023945577939707817829786538429
10272302457226894897227542031630
13885327029506744759502962358831
27770653950102489520095034717662
54442397009105087940200970325434
97894704909310065990391049649879
195789398928620021991781990399758
1053782498115819142018611884387349
10491617379283921561203730827260850
16297890183014138074142028198880251
31506779365038285157283066308759512
53102559731076560315566122706520025
105105120453243111622133136502040160
166145326084574337733475490523541661
332290651179148675466950971147083322
555671392358208340043792942303175555
1111242695607505680087595795596352110
1223779651583463480952652861558773221
2447558203266026071796296713128546442
4894016416442953043502503336157103884
9777033932776005096906095782303208868
18465056965651911193811102554696516647
93126626611172023032923018211661573128
175264143222453055955955045323324235267
937796566545993615515505399545665697838
1776593133091987121031021799091331395577
9532524465001958322332239690994645352348
17965059929992927644664478282000289604707
88705758130021215091309151211993284661678
176322406369932430281628202423996470412466
840536481069256633107810236663960074636137
1572172951138623265126511573316920259271185
7383902471434757016282727196585231851983936
13777794052760613933555553304159573594077773
51554843590355754269111087235766298643855504
92110678279622507547122283481521608178701019
183121465460235025985344458052044305466302148
1024325129963675276839788047572576370030423529
10277565430700428034248667434298340069245657730
14053219726704817277725351677380740772702234931
27996440454409525655340704454652581535493469972
55992879907928051300781408810305171980897939944
100986859716845201602661827510620254951895769899
1099954457876297227618389993716722803569854458900
1198499047529379503792389831883950730357399058801
2287008985059750097673779664857010469614809007712
4464018069229390205258449438624911049120707015534
8819125139448791399526798887149931988350315120178
17529340269987682798944687863409863966799630339366
83922643969754619689381566508399592645795834731937
157836387829509249288762133026798284291592769354875
736290355124701732186382464294681227197521552993626
1362689610250493454372874928578362464304943106086263
4989495623744528097011633223361097008245463275948894
9977991347389956104913266446722204916499936541898788
18856972803789902298935542893345398933099773973896587
97426810741588936288289882717899388154098504801862468
183853621582177981476689754446797676418087019503724947
933280927492958796153487398904784350607858304630083328
1756660963896817502206974808798568702305717599359165667
9422280503853992534285633786883364724362904583049832238
17744669907708085168560267673756730548715898166100654487
96190270073897936953064033411432937134873978937097299258
181489549147885874796237956822865983170837958774104508427
906294950625745612867627525051525715868316547516050492608
1712589001241491226736145050202051442636533095042109985217
8838488013647394583098586552222556859012755036463119837388
17675877127293700155208173104445113717916609973926228685776
85434559390231690817179904258885250898171710713198406543447
159869119879363392534369709517770491895343520326407802086905
669549328583986417877967903595486399858778813690386714055856
1328099746267082736755826897280081709628557528379772538001822
3609108099046820994314095969080909695914133901187399017910053
7109305208984632087628291938171719391818268891473808925929116
13228600507068374076256473877343437783746536693838706950968133
46415506467852213739821212650777815621211803741224777451650364
92721121945594428470632425302655521242424697472450653912201828
175531343881199855950274849515211141594848304954900208824314557
930944772683209315354123344656323657543320364513891397167450128
1751999534476407630817146690412647313986641818027793783444899167
9371983978350384838998613583550109454953058998394840527804890738
17742968065600869777997117178099120008806227996779671066598782477
95171757631618567547969378058101319095977407974576471722685707248
179442516254336035095939856017192629281064804949153053336361424407
883866679887686387045348316200118920991723744539683686788976669378
1757833359775372773980795643399148731994337588080467373577953337766
8435166957529110414789652978390527151927803558974240109357486725337
15770443805068120839588206065682044402866596128848380228615083340685
...



Daniel
_______________________________________________
Edu-sig mailing list
[email protected]
http://mail.python.org/mailman/listinfo/edu-sig

Reply via email to