FizzBuzz in Single Line Of Code
Enumerable.Range(1, 100). Select(Function(Number) New Tuple(Of Integer, String)(Number, If(Number Mod 3 = 0, "Fizz", ""))). Select(Function(Tuple) New Tuple(Of Integer, String)(Tuple.Item1, If(Tuple.Item1 Mod 5 = 0, Tuple.Item2 & "Buzz", Tuple.Item2))). Select(Function(Tuple) If(Tuple.Item2 <> "", Tuple.Item2, Tuple.Item1.ToString)). ToList. ForEach(AddressOf Console.WriteLine)
16 Comments On This Entry
Page 1 of 1
lucky3
16 November 2012 - 09:01 AM
Implicit Line Continuation: http://msdn.microsof...o/ee681551.aspx
jon.kiparsky
16 November 2012 - 10:34 AM
This is one of those weird FP tics, that if you can cram a bunch of operations in to a line, it's somehow easier to understand. It's nothing new, though. Here's how it would look in scheme:
However, it seems more sensible to format it so as to reflect the actual process:
(define fizzbuzz (lambda (x) (if (= 0 (modulo x 15)) "Fizzbuzz" (if (= 0 (modulo x 5)) "Buzz" (if (= 0 (modulo x 3)) "Fizz" " ")))))
However, it seems more sensible to format it so as to reflect the actual process:
(define fizzbuzz (lambda (x)
(if (= 0 (modulo x 15)) "Fizzbuzz"
(if (= 0 (modulo x 5)) "Buzz"
(if (= 0 (modulo x 3)) "Fizz" " ")
))))
jon.kiparsky
16 November 2012 - 11:34 AM
Wrong? Oh, okay, you want the number as return. Whatever. The point is, it's a pretty trivial program, and making it more complicated than it needs to be doesn't seem like much of a gain.
ishkabible
16 November 2012 - 03:04 PM
haskell:
or could also use list comprehension I suppose.
I think you need to define what a line is and what an expression is. I call a line an editor line and only well formatted short lines(e.g. 80 characters) really count. a semi-colon in C syntax langues is just an ending of different kinds of statements and has nothing to do with lines other than the fact that it is generally placed at the end of lines for good formatting.
map fb [1..100] where fb x
| x % 15 == 0 = "FizzBuzz"
| x % 5 == 0 = "Fizz"
| x % 3 == 0 = "Buzz"
| otherwise = show x
or could also use list comprehension I suppose.
I think you need to define what a line is and what an expression is. I call a line an editor line and only well formatted short lines(e.g. 80 characters) really count. a semi-colon in C syntax langues is just an ending of different kinds of statements and has nothing to do with lines other than the fact that it is generally placed at the end of lines for good formatting.
lar3ry
30 November 2012 - 03:45 PMjon.kiparsky, on 16 November 2012 - 09:51 AM, said:
A line is 80 columns. :)/>
You... You... Fortranner you!
Page 1 of 1
Search My Blog
Recent Entries
Recent Comments
4 user(s) viewing
4 Guests
0 member(s)
0 anonymous member(s)
0 member(s)
0 anonymous member(s)
← January 2022 →
| S | M | T | W | T | F | S |
|---|---|---|---|---|---|---|
| 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 |
Tags
- .net
- .net4
- bf
- brainfuck
- Codeplex
- Coding
- custom Control
- custom controls
- DIC CodeAID VS Gallery
- Dice
- Die
- DLL
- Englishify
- Extension
- Extension Method
- ExtMethods
- F#
- Functional
- Functional Programming
- Graph
- Graphs
- Language Intergrated Query.
- Library
- LINQ
- LINQ Codes
- LISP interpreter
- Macro
- My Games
- Nemerle.
- net
- podcast
- Project
- Project Cider
- RadixSort Generics (Of T)
- restricted textbox
- Rolling
- rss
- rss feed
- Scribblings
- shadowtext
- Tips
- Transparent Textbox
- vb
- vb.net
- VB.net +LINQ Extension Method
- vb.net 1-Liners
- vb.net visual basic vs2010 .net4
- vs2010
- Weird
- XM
- xml
- XML Literals



16 Comments









|