P. 1
PicoLisp by Example

PicoLisp by Example

|Views: 4,233|Likes:
Published by tj64
More than 600 PicoLisp solutions for Rosetta Code programming tasks from a wide range of topics, written by Alexander Burger (the creator of PicoLisp) himself - plus the complete PicoLisp function reference. Learn a fascinating programming language that maximises expressive power while minimizing complexity 'by Example'.
More than 600 PicoLisp solutions for Rosetta Code programming tasks from a wide range of topics, written by Alexander Burger (the creator of PicoLisp) himself - plus the complete PicoLisp function reference. Learn a fascinating programming language that maximises expressive power while minimizing complexity 'by Example'.

More info:

Published by: tj64 on Aug 23, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

08/09/2014

pdf

text

original

Problem: You have 100 doors in a row that are all initially closed. You make 100
passes by the doors. The first time through, you visit every door and toggle the door
(if the door is closed, you open it; if it is open, you close it). The second time you
only visit every 2nd door (door #2, #4, #6, ...). The third time, every 3rd door (door
#3, #6, #9, ...), etc, until you only visit the 100th door.

Question: What state are the doors in after the last pass? Which are open, which are
closed?

Alternate: As noted in this page’s discussion page, the only doors that remain open
are whose numbers are perfect squares of integers. Opening only those doors is an
optimization that may also be expressed.

unoptimized

(let Doors (need 100)
(for I 100

(for (D (nth Doors I) D (cdr (nth D I)))
(set D (not (car D))) ) )

(println Doors) )

optimized

(let Doors (need 100)
(for I (sqrt 100)
(set (nth Doors (* I I)) T) )
(println Doors) )

47

48

2 Rosetta Code Tasks starting with Numbers

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->