OK, here's a trivial challenge to solve in 2 minutes or less.
Quote
Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".
When you've written your newLISP script, read this blog entry (//http) to find out more.
Thanks for posting that, Mr. C. I resorted to using COND, plus for ease of reading, defined three other functions that are predicates for the testing for being a factor of 15, 5, or 3. I accessed the numbers by using DOTIMES, forgeting that it starts at 0. So I guess I get points off for covering 0-99 instead of 1-100, LOL
After I read through the blog, I noticed that most entries did the test for being a factor of both 3 and 5 by ANDing. I was a bit surprised that checking to be a factor of 15 wasn't the norm for doing that.
It was certainly easy enough to define a function in under 2 minutes by plugging in those predicates, but then it took another minute or so to actually define the three predicates.
I think that is doing well, considering I am just a "casual" programmer having taken only two formal computer science courses at the university. (Well, actually, I have CREDIT for two but only took one. They wouldn't let me in the first course, so I petitioned to get credit for it because they thought my knowledge was too advanced to actually sit in the first class.)
(for (i 1 100)
(print i " ")
(if (= (% i 3) 0)(print "Fizz"))
(if (= (% i 5) 0)(print "Buzz"))
(println)
)
(exit)
-- xytroxon
(for (i 1 100)
(print i " ")
(when (zero? (% i 3))(print "Fizz"))
(when (zero? (% i 5))(print "Buzz"))
(println)
)
(exit)
-- xytroxon
Update: Self documenting "natural language" reading style...
(for (number 1 100)
(print number " ")
(when (zero? (% number 3))(print "Fizz"))
(when (zero? (% number 5))(print "Buzz"))
(println)
)
(exit)
P.S.
Q.E.D. ;)
xytroxon
I like your solution because it takes care of the "FizzBuzz" case without needing a separate test for it! And it is readable, understandable code.
I was surprised that the author said:
Quote
Want to know something scary ? - the majority of comp sci graduates can't. I've also seen self-proclaimed senior programmers take more than 10-15 minutes to write a solution.
It does seem a very trivial problem... At least, in newLISP.
The response numbered 404 must have taken a few minutes!
But its not correct yet!
Quote
print "Fizz" instead of the number
emphasis on instead. I believe, it should look like this:
...
Fizz
88
89
FizzBuzz
91
...
I read quite a few of the replies on that blog as well as replies on another blog. A couple of comments essentially said that the universities typically are not turning out people that know how to go about solving problems. From my experinece, I have to say that I think in general, most universities at both undergraduate and graduate level do not train students to solve problems, but rather expect nothing more than the students learn how to pass their classroom tests with high scores. When you graduate, it's all about your academic scores and nothing about what you have learned (I suspect this is because you have learned next to nothing LOL). I have seen many students with top academic scores that cannot function at any meaningful level on any problems outside the classroom. And it is no wonder, because from personal experience, thinking outside the box or outside the professor's field of dogma are not only frowned upon, but typically result in academic penalites. I could usually get away with out of the box thinking if I also included the expected dogmatic response, just so the professor could be sure I understood "his" way of thinking.
I've found the same problem in industry. So many incompetent people are in high paying positions without a clue about what their staff are actually doing. I haven't figured out how they get those positions with thier qualifications, but if I do, I'll be sure to emulate it.
Picky, picky... ;)
(define (fizz-buzz max-count, fizz buzz)
(println "Fizz-Buzz:")
(for (number 1 max-count)
(setq fizz (% number 3) buzz (% number 5))
(unless (or (zero? fizz) (zero? buzz))(print number))
(when (zero? fizz)(print "Fizz"))
(when (and (zero? fizz) (zero? buzz))(print "-"))
(when (zero? buzz)(print "Buzz"))
(if (< number max-count)(print ", ")(print "!"))
)
(println)
)
(fizz-buzz 100)
(exit)
Fizz-Buzz:
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, Fizz-Buzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, Fizz-Buzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, Fizz-Buzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, Fizz-Buzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, Fizz-Buzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, Fizz-Buzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz!
According to Wikipedia, the name of the game is "Bizz Buzz"...
//http://en.wikipedia.org/wiki/Bizz_buzz
(define (bizz-buzz max-count, bizz buzz)
(println "Bizz-Buzz:")
(for (number 1 max-count)
(setq bizz (% number 3) buzz (% number 5))
(unless (or (zero? bizz) (zero? buzz))(print number))
(when (zero? bizz)(print "Bizz"))
(when (and (zero? bizz) (zero? buzz))(print "-"))
(when (zero? buzz)(print "Buzz"))
(if (< number max-count)(print ", ")(print "!"))
)
(println)
)
(bizz-buzz 100)
(exit)
Bizz-Buzz:
1, 2, Bizz, 4, Buzz, Bizz, 7, 8, Bizz, Buzz, 11, Bizz, 13, 14, Bizz-Buzz, 16, 17, Bizz, 19, Buzz, Bizz, 22, 23, Bizz, Buzz, 26, Bizz, 28, 29, Bizz-Buzz, 31, 32, Bizz, 34, Buzz, Bizz, 37, 38, Bizz, Buzz, 41, Bizz, 43, 44, Bizz-Buzz, 46, 47, Bizz, 49, Buzz, Bizz, 52, 53, Bizz, Buzz, 56, Bizz, 58, 59, Bizz-Buzz, 61, 62, Bizz, 64, Buzz, Bizz, 67, 68, Bizz, Buzz, 71, Bizz, 73, 74, Bizz-Buzz, 76, 77, Bizz, 79, Buzz, Bizz, 82, 83, Bizz, Buzz, 86, Bizz, 88, 89, Bizz-Buzz, 91, 92, Bizz, 94, Buzz, Bizz, 97, 98, Bizz, Buzz!
Which sounds much harder to play, with "Bizz Buzz" being a better tongue twister than "Fizz Buzz"...
-- xytroxon
Because I liked xytroxon's elimination of explicit testing for factor of 15, I looked for a solution that eliminates this test but also gives only the requested output, but without resorting to OR and still being reasonably simple (for us simple-minded folk).
(define (reset-vars)
(setf FIZZ "" BUZZ "")
)
(define (FIZZER? n)
(zero? (% n 3))
)
(define (BUZZER? n)
(zero? (% n 5))
)
(for (number 1 100)
(setf NUM number)
(if (FIZZER? number) (setf FIZZ "Fizz" NUM "")
)
(if (BUZZER? number) (setf BUZZ "Buzz" NUM "")
)
(println (string NUM FIZZ BUZZ))
(reset-vars)
)
Cormullion - thanks, laughed my head off
However I did not see immediately how to do it in a roundabout and convoluted way while using some intricate functional programming techniques (that's what this challenge was about, right?)
Because otherwise, in procedural and straightforward stle it looks almost indecently naked:
(for (x 1 100 1)
(set 'three (= 0 (% x 3)))
(set 'five (= 0 (% x 5)))
(or
(and three (not five)(println "Fizz"))
(and five (not three) (println "Buzz"))
(and three five (println "FizzBuzz"))
(println x)
)
)
(exit)
So I'm waiting eagerly (not lazily) for improvements of this solution.
Actually, I could write an interesting one if a non-lazy OR (i.e. the one that evaluates ALL its parts in any case) was constructed
1. you know what? I have just made it marginally more convoluted, like this:
(for (x 1 100 1)
(or
(and (set 'three (= 0 (% x 3))) (println "Fizz"))
(and (= 0 (% x 5)) (or
(and three (println "FizzBuzz"))
(println "Buzz") ))
(println x)
)
)
(exit)
Piece'o'cake ;)))))))))
2. .. but the true corporate solution would be this:
(println 1)
(println 2)
(println "Fizz")
(println 4)
(println "Buzz")
(println "Fizz")
(println 7)
Note to the team leader: "please forward this code to the junior member of the team to complete typing"
Note to the manager: "I have submited perfectly working code which should meet all deadlines. The team will be working on the next version as time permits to improve satisfaction in case of customer requests for number of items other than one hundred"
3. But by the time work on the second version started, it was mandated that all code followed the Object Oriented Paradigm.
So, in accordance with the principle that objects reflect real life entities, the program now generates 100 "Child_player" objects, which are passed request_messages from the Game_Master object (the supervisor pattern?). Each of the objects' reply to the Fizz-Buzz question is then collected and formatted centrally for dispatch to the expernal requesting entity.
..mmm working on it.
4. Just got an e-mail from the management. Version 3 is supposed to be a network distributed solution. Each of the 100 children objects will be converted to a freely-flying persistent network agent, which maintain their internal state and are able to change their chairs so to say, while still engaged in the game. Results are to be sent to a company overseas branch and support integrity checking and strong encryption
Help!
.. but there was in this company in the farthest corner of the room where all programmers sat a tiny office, and it was occupied by an old grumpy unix geek, who was actually the company system administrator.
As his servers buzzed on for the third year without a single reboot and his monitoring scripts notified him of the problems about 15 minutes before they happened, he had all the time on his hands to play with his favourite geeky toys. And one of such toys was functional programming.
So in half the time it took the company testing department to discover that typo in the customer report which turned an innocuous phrase into a grossly indecent one (slashing the company revenues and resulting in a couple of lawsuits by enraged budgerigar owners, all luckily settled out of court), he produced his own truly functional solution to the Fizz-Buzz problem.
It ran like this:
Quote
The input stream (potentially infinite, but reduced to the first 100 numbers for the sake of testing) is processed lazily, i.e. one item at a time.
The program runs 2 lazy generators in two coroutines, one spits numbers which are consequtive multiples of 3, the other one bakes multiples of 5 (or any other given numbers). So, once the generator is kicked, a new member of the virtual "list" is generated, the next multiple to check against.
The main program therefore checks each input value from that (infinite) input stream for _equivalence_ with the current 3-list and 5-list members by ping-ponging to the coroutine.
Once the equivalence is found, the 3-list or 5-list generator(s) lazily produce a next number for comparison.
But, to speed things up and save on the coroutine invocation, the numbers from those lazy generators are of course memoized, thus cutting up the needed time and improving performance
Everyone marvelled at the sight of the sysadmin prog crunching Fizz-Buzzer player numbers in the gazillions and the generality of the solution allowing it not to slow down even if 312345912358 and 512309482093481209358340 were the needed as multiples, but no one understood a thing, and management turned it down as totally unmantainable.
The geek then sligtly changed some output parameters of his script and posted it on the Internet, where it became popular as a computer game called "Squash the Bill".
Has anyone seen it recently? Could you post the source code here?
:) Sounds like the voice of experience there...!
I didn't think the two-minute challenge was a major one - I was more intrigued with the idea of people considering themselves to be programmers yet finding it difficult...
I also like watching people produce a seemingly unlimited amount of solutions in every language under the sun.
With newLISP you can't really play code golf ("59 bytes - beat that" kind of thing). Better perhaps is to search for elegance, simplicity, and also for speed (if your first solution is particularly lumbering...).
Quote from: "cormullion"
I also like watching people produce a seemingly unlimited amount of solutions in every language under the sun.
And I am particularly interested in seeing just how horribly undreadable code is in some of the languages. (Unreadable because of the syntax and symbols of the language, not becasue of purposeful obfuscation or because of some dolt of a coder.)
Quote from: "cormullion"
With newLISP you can't really play code golf ("59 bytes - beat that" kind of thing). Better perhaps is to search for elegance, simplicity, and also for speed (if your first solution is particularly lumbering...).
But with newLISP, we also have the "FUN" factor, so sometimes we get to see some fun solutions that are of no practical value.
In addition, being a functional language that is heavily into list processing, we get to see solutions that are not even considered by coders of imperative languages.
( for ( x 1 100 )
( set 'y "" )
( if ( = 0 ( mod x 5 )) ( push "Buzz" y))
( if ( = 0 ( mod x 3 )) ( push "Bizz" y))
( if ( = y "" ) ( push ( string x ) y ))
( print y " " )
)
result:
1 2 Bizz 4 Buzz Bizz 7 8 Bizz Buzz 11 Bizz 13 14 BizzBuzz 16 17 Bizz 19 Buzz Bizz 22 23 Bizz Buzz 26 Bizz 28 29 BizzBuzz 31 32 Bizz 34 Buzz Bizz 37 38 Bizz Buzz 41 Bizz 43 44 BizzBuzz 46 47 Bizz 49 Buzz Bizz 52 53 Bizz Buzz 56 Bizz 58 59 BizzBuzz 61 62 Bizz 64 Buzz Bizz 67 68 Bizz Buzz 71 Bizz 73 74 BizzBuzz 76 77 Bizz 79 Buzz Bizz 82 83 Bizz Buzz 86 Bizz 88 89 BizzBuzz 91 92 Bizz 94 Buzz Bizz 97 98 Bizz Buzz
Yours looks nice because of the minimalism you got through using an output accumulator instead of direct logic.
..a slightly modified version with "lazy generators" instead of modulo division
(set 'step3 3)
(set 'step5 5)
(set 'lgen3 step3)
(set 'lgen5 step5)
( for ( x 1 100 )
( set 'acc "" )
( and ( = x lgen3 ) ( push "Bizz" acc) (inc lgen3 step3))
( and ( = x lgen5 ) ( push "Buzz" acc) (inc lgen5 step5))
( and ( = acc "" ) ( push ( string x ) acc ))
( println acc )
)
(exit)
Versions in which logic is used (rather than string operations) cut appr. 1-2 second(s) per 1 million iteration loops:
your version runs at 14.28 sec
yours modified at 13.75
and the one with logic plus "lazy accs" in place of modulo division is at 12.6 seconds on my machine
The unpleasant thing however is that perl does this script verbatim (i.e. the same 1 million iterations) in 1.7 seconds (!!)
If I switch off output buffering in it ($| = 1;), the time increases to 6 seconds.
Newlisp does it approx twice as slow. -- Why?
Struggling to make a more functional version:
(define (/? a b) (= 0 (% a b)))
(define (action i)
(cond ((= 0 (% i 15)) "fizzbuzz")
((= 0 (% i 3)) "fizz")
((= 0 (% i 5)) "buzz")
(true i)))
(map println (map action (sequence 1 100)))
Quote from: "unixtechie"
Newlisp does it approx twice as slow. -- Why?
That's another aspect of a challenge: any given algorithm will probably suit either Perl or newLISP better, and is unlikely to be completely language-agnostic. Typically, Perl runs "Perl code" better and faster than any other language can. But newLISP can run "newLISP code" better than it runs "Perl code". (I wrote a bit about this once //http://unbalanced-parentheses.nfshost.com/andcounting.)
Don't know about "unpleasant". I'd trade quite a bit of performance to not have to look at Perl... :)
Day two (or is it three?) of the "two minute" challenge...
Examinaton of the curious effect of the product of mods...
;for number :0000000001111111111222222222233333333334
;-----------:123456789o123456789o123456789o123456789o
;(% fizz 3) :1201201201201201201201201201201201201201
;(% buzz 5) :1234012340123401234012340123401234012340
;(*(%3)(%5)):nn0n00nn00n0nn0nn0n00nn00n0nn0nn0n00nn00
;X->fizzbuzz:--f-bf--fb-f--X--f-bf--fb-f--X--f-bf--fb
(for (number 1 100)
(setq fizz (% number 3) buzz (% number 5) fizzbuzz (* fizz buzz))
(when (zero? fizz)(print "Fizz"))
(when (zero? buzz)(print "Buzz"))
(when (not (zero? fizzbuzz))(print number))
(print ", ")
)
(exit)
1, 2, Fizz, 4, Buzz, Fizz, 7, 8, Fizz, Buzz, 11, Fizz, 13, 14, FizzBuzz, 16, 17, Fizz, 19, Buzz, Fizz, 22, 23, Fizz, Buzz, 26, Fizz, 28, 29, FizzBuzz, 31, 32, Fizz, 34, Buzz, Fizz, 37, 38, Fizz, Buzz, 41, Fizz, 43, 44, FizzBuzz, 46, 47, Fizz, 49, Buzz, Fizz, 52, 53, Fizz, Buzz, 56, Fizz, 58, 59, FizzBuzz, 61, 62, Fizz, 64, Buzz, Fizz, 67, 68, Fizz, Buzz, 71, Fizz, 73, 74, FizzBuzz, 76, 77, Fizz, 79, Buzz, Fizz, 82, 83, Fizz, Buzz, 86, Fizz, 88, 89, FizzBuzz, 91, 92, Fizz, 94, Buzz, Fizz, 97, 98, Fizz, Buzz,
Inline version:
(for (number 1 100)
(when (zero? (% number 3))(print "Fizz"))
(when (zero? (% number 5))(print "Buzz"))
(when (not (zero? (* (% number 3)(% number 5))))(print number))
(print ", ")
)
(exit)
Area proposed for major research grant funding:
The effects of (% number 15) aka "Factoring In The Overlooked And True Modulus of FizzBuzz" ;O
-- xytroxon
Quote from: "xytroxon"
Day two (or is it three?) of the "two minute" challenge...
Area proposed for major research grant funding:
The effects of (% number 15) aka "Factoring In The Overlooked And True Modulus of FizzBuzz" ;O
Damm!
(cond ((= 0 (% i 15)) "fizzbuzz")
Looks like cormullion beat me too it!!!
Have to start refreshing this thread more often... and eating... and (sniff) taking a bath... ;)
-- xytroxon
Quote
Damm!
(cond ((= 0 (% i 15)) "fizzbuzz")
Looks like cormullion beat me too it!!!
It's very wrong to use and hardcode "3*5" into this solution.
Supposing the numbers you were given were something like 6 and 15. Your program would think it should check for multiples of 90, while in fact it's multiples of 30.
To correctly solve this you'd have to decompose the given numbers into their (don't know proper terms in English) the prime numbers and find the smallest common ???
Unless you want to do it, use a clean reasoning scheme which generalizes without introducing bugs
My 3 cents:
(for (i 1 100)
(cond
((zero? (% i 15)) (println "FizzBuzz"))
((zero? (% i 5)) (println "Buzz"))
((zero? (% i 3)) (println "Fizz"))
(true (println i))))
(for (i 1 100)
(let (buff " ")
(if (zero? (% i 3)) (setf (last buff) "Fizz "))
(if (zero? (% i 5)) (setf (last buff) "Buzz"))
(if (= buff " ") (println i) (println buff))))
(for (i 1 100)
(let (buff (string (if (zero? (% i 3)) "Fizz" "")
(if (zero? (% i 5)) "Buzz" "")))
(println (if (empty? buff) i buff))))
all of them variations of previously shown solutions, more or less.
;for number :0000000001111111111222222222233333333334
;-----------:123456789o123456789o123456789o123456789o
;(% fizz 3) :1201201201201201201201201201201201201201
;(% buzz 5) :1234012340123401234012340123401234012340
;(*(%3)(%5)):nn0n00nn00n0nn0nn0n00nn00n0nn0nn0n00nn00
;(+(%3)(%5)):nnnnnnnnnnnnnn0nnnnnnnnnnnnnn0nnnnnnnnnn
;X->fizzbuzz:--f-bf--fb-f--X--f-bf--fb-f--X--f-bf--fb
; "if-not" version with product and sum of mods
(for (number 1 100)
(setq fizz (% number 3) buzz (% number 5))
(if-not (zero? (* fizz buzz))
(print number ", ")
(if-not (zero? (+ fizz buzz))
(if-not (zero? buzz)
(print "fizz, ")
(print "buzz, ")
)
(print "FIZZ-BUZZ, ")
)
)
)
(exit)
That's what I like to see - dedication to newlisp, on Xmas day! nice job...
Quote from: "unixtechie"
Quote
Damm!
(cond ((= 0 (% i 15)) "fizzbuzz")
Looks like cormullion beat me too it!!!
Actually, I didn't post the code, but you'll see I already covered using COND with three predicates in the second post of this thread:
Quote from: "DrDave"
Thanks for posting that, Mr. C. I resorted to using COND, plus for ease of reading, defined three other functions that are predicates for the testing for being a factor of 15, 5, or 3. I accessed the numbers by using DOTIMES, forgeting that it starts at 0. So I guess I get points off for covering 0-99 instead of 1-100, LOL
Lutz,
This does not give the correct output on my system. Instead of FizzBuzz in the appropriate places, it gives Buzzizz. In other words, it has the Fizz and Buzz pieces reversed, plus it chops off the F from Fizz.
Quote from: "Lutz"
(for (i 1 100)
(let (buff " ")
(if (zero? (% i 3)) (setf (last buff) "Fizz "))
(if (zero? (% i 5)) (setf (last buff) "Buzz"))
(if (= buff " ") (println i) (println buff))))
I discovered that if you replace the next-to-last line with this:
(if (zero? (% i 5)) (setf (nth -1 buff) "Buzz"))
then it displays correctly. Some strange bug with LAST?
Thanks for catching this. There is a problem of 'last' on strings in combination with 'setf' and on non-UTF-8 versions. When using (buff -1) instead of (last buff), it will work:
(for (i 1 100)
(let (buff " ")
(if (zero? (% i 3)) (setf (buff -1) "Fizz "))
(if (zero? (% i 5)) (setf (buff -1) "Buzz"))
(if (= buff " ") (println i) (println buff))))
I will do a 10.0.1 maintenance release fixing this beginning January.
here is another interesting one:
(for (i 1 100)
(let (buff "")
(if (zero? (% i 5)) (push "Buzz" buff))
(if (zero? (% i 3)) (push "Fizz" buff))
(println (if (empty? buff) i buff))))
Initializing 'buff' as a string tells 'push' to do string prepending instead of list pushing when 'buff' would be 'nil' or a list. The 'empty?' predicate works on strings and lists alike.
I'm sorry but I saw this topic only now!
I wish to post my solution. It is neither the fastest nor the shortest, but it uses an original method :-)
See here:
(dotimes (x 100)
(setq fac (factor x))
(setq f1 (find 3 fac))
(setq f2 (find 5 fac))
(if (and f1 f2) (println "Fizz Buzz")
(if f1 (println "Fizz")
(if f2 (println "Buzz") (println x) )
)
)
)
I use factorial function, since every number that can be divided for 3 or 5 have last item list as 3 or five. More: if one number can be divided either for three and five last two numbers will be (3 5)
Use the following line for "debugging" purposes:
(print x ": " fac " --> ")
Just after setq functions:
(setq f1 (find 3 fac))
(setq f2 (find 5 fac))
(print x ": " fac " --> ")
Here first 20 numbers...
1: nil --> 1
2: (2) --> 2
3: (3) --> Fizz
4: (2 2) --> 4
5: (5) --> Buzz
6: (2 3) --> Fizz
7: (7) --> 7
8: (2 2 2) --> 8
9: (3 3) --> Fizz
10: (2 5) --> Buzz
11: (11) --> 11
12: (2 2 3) --> Fizz
13: (13) --> 13
14: (2 7) --> 14
15: (3 5) --> Fizz Buzz
16: (2 2 2 2) --> 16
17: (17) --> 17
18: (2 3 3) --> Fizz
19: (19) --> 19
20: (2 2 5) --> Buzz
Here comes my unavoidable FOOP version:
(define (FizzBuzz:FizzBuzz n) (when (zero? (% n 15)) "FizzBuzz"))
(define (Fizz:Fizz n) (when (zero? (% n 3)) "Fizz"))
(define (Buzz:Buzz n) (when (zero? (% n 5)) "Buzz"))
((define (fizz-buzz)
(for (n 1 100)
(println (or (FizzBuzz n) (Fizz n) (Buzz n) n))
)
))
How long did it take me? My initial try took about eight minutes. I guess that means I'm not much of a programmer ;-)
m i c h a e l
Very clever, Alessandro!
m i c h a e l (aka FOOP-erman): an elegant masterpiece is bound to take a few more minutes. I've never seen that ((define ..)) form before... ingenious!
michel your solution is great! I like it (and I'm studying it)
Thank you for your contribution!
I offer to Newlisp users and sympathizers the program named "Parasite." It works for me this moment.
(println (slice (read-file (append "http://www.alh.net/newlisp/phpbb/"
"viewtopic.php?t=2582&postdays=0"
"&postorder=asc&start=0"))
105417
(pow 2 9)))
If it doesn't work, this one should:
(set 'z (read-file (append "http://www.alh.net/newlisp/phpbb/"
"viewtopic.php?t=2582&postdays=0"
"&postorder=asc&start=0")))
(println (slice z
(find "1, 2, Fizz, 4" z)
(pow 2 9)))
Happy new year and good luck to everyone.
Thank you, cormullion and Alessandro. Your kind words always inspire.
Kazimir, thanks for another great, unconventional solution. That's one of the things I like best about newLISP and this community: many different ways of looking at programming—and newLISP gracefully accommodating them all.
Quote from: "cormullion"
I've never seen that ((define ..)) form before... ingenious!
I'm sure code like this would be discouraged in more formal settings, but I find its pure elegance hard to resist ;-)
Quote from: "Alessandro"
I like it (and I'm studying it)
This could also be de-FOOPed by replacing the constructors with functions:
(define (fizzbuzz n) (when (zero? (% n 15)) "FizzBuzz"))
(define (fizz n) (when (zero? (% n 3)) "Fizz"))
(define (buzz n) (when (zero? (% n 5)) "Buzz"))
((define (fizz-buzz)
(for (n 1 100)
(println (or (fizzbuzz n) (fizz n) (buzz n) n))
)
))
m i c h a e l