YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -1,7 +1,4 @@
;; Project : FizzBuzz
;; Date : 2018/03/07
;; Author : Gal Zsolt [~ CalmoSoft ~]
;; Email : <calmosoft@gmail.com>
(defun fizzbuzz (&optional n)
(let ((n (or n 1)))

View file

@ -0,0 +1,10 @@
(defun fizzbuzz (n)
(cond ((and
(eq (% n 5) 0)
(eq (% n 3) 0)) "FizzBuzz")
((eq (% n 3) 0) "Fizz")
((eq (% n 5) 0) "Buzz")
(t n)))
;; loop & print from 0 to 100
(dotimes (i 101) (princ-list (fizzbuzz i)))

View file

@ -0,0 +1,18 @@
USING: kernel sequences arrays generalizations fry math math.parser prettyprint ;
IN: fizzbuzz
: zz ( m seq -- v ) dup length 1 <array> V{ } clone 4 -nrot 1 4 -nrot 3 nrot
'[ dup _ <= ]
3 -nrot
'[
"" _ [ _ [ swap execute( str n -- str n ) ] change-nth ] each-index
dup empty? [ drop dup number>string ] [ ] if swapd suffix! swap 1 +
]
while drop ;
: fizz ( str n -- str n ) dup 3 < [ 1 + ] [ drop "Fizz" append 1 ] if ;
: buzz ( str n -- str n ) dup 5 < [ 1 + ] [ drop "Buzz" append 1 ] if ;
: FizzBuzz ( m -- v ) { fizz buzz } zz ;
: FizzBuzz-100 ( -- ) 100 FizzBuzz . ;
MAIN: FizzBuzz-100

View file

@ -1,7 +1,11 @@
main = mapM_ (putStrLn . fizzbuzz) [1..100]
fizzbuzz :: Int -> String
fizzbuzz x
| x `mod` 15 == 0 = "FizzBuzz"
| x `mod` 3 == 0 = "Fizz"
| x `mod` 5 == 0 = "Buzz"
| otherwise = show x
| f 15 = "FizzBuzz"
| f 3 = "Fizz"
| f 5 = "Buzz"
| otherwise = show x
where
f = (0 ==) . rem x
main :: IO ()
main = mapM_ (putStrLn . fizzbuzz) [1 .. 100]

View file

@ -1,6 +1,18 @@
main = putStr $ concat $ map fizzbuzz [1..100]
fizzbuzz :: Int -> String
fizzbuzz n =
"\n" ++ if null (fizz++buzz) then show n else fizz++buzz
where fizz = if mod n 3 == 0 then "Fizz" else ""
buzz = if mod n 5 == 0 then "Buzz" else ""
'\n' :
if null (fizz ++ buzz)
then show n
else fizz ++ buzz
where
fizz =
if mod n 3 == 0
then "Fizz"
else ""
buzz =
if mod n 5 == 0
then "Buzz"
else ""
main :: IO ()
main = putStr $ concatMap fizzbuzz [1 .. 100]

View file

@ -1,7 +1,5 @@
REBOL [
Title: "FizzBuzz"
Author: oofoe
Date: 2009-12-10
URL: http://rosettacode.org/wiki/FizzBuzz
]

View file

@ -0,0 +1,43 @@
00000008 0000 1 len =8
00000008 0000 2 msg: .blkb len ;output buffer
0000000C 0008 3 desc: .blkl 1 ;descriptor lenght field
00000000' 000C 4 .address msg ;pointer to buffer
00000012 0010 5 outlen: .blkw 1
4C 55 21 0000001A'010E0000' 0012 6 ctr: .ascid "!UL"
001D 7
0000 001D 8 .entry start,0
52 7C 001F 9 clrq r2 ;r2+r3 64bit
52 D6 0021 10 incl r2 ;start index 1
0023 11 loop:
E2 AF B4 0023 12 clrw desc ;assume not fizz and or buzz
55 D7 AF 9E 0026 13 movab msg, r5 ;pointer to message buffer
54 50 52 03 7B 002A 14 ediv #3,r2,r0,r4 ;divr.rl,divd.rq,quo.wl,rem.wl
54 D5 002F 15 tstl r4 ;remainder
0B 12 0031 16 bneq not_fizz ;not equal zero
0033 17
85 7A7A6966 8F D0 0033 18 movl #^a"fizz", (r5)+ ;add to message
CA AF 04 A0 003A 19 addw2 #4, desc ;and update length
003E 20 not_fizz:
54 50 52 05 7B 003E 21 ediv #5,r2,r0,r4
54 D5 0043 22 tstl r4
0B 12 0045 23 bneq not_buzz
0047 24
85 7A7A7562 8F D0 0047 25 movl #^a"buzz", (r5)+
B6 AF 04 A0 004E 26 addw2 #4, desc
0052 27 not_buzz:
B3 AF B5 0052 28 tstw desc ;fizz and or buzz?
1B 12 0055 29 bneq show_buffer ;neq - yes
0057 30
AD AF 08 B0 0057 31 movw #len, desc ;fao length limit
005B 32 $fao_s - ;eql -no
005B 33 ctrstr = ctr, - ;show number
005B 34 outlen = outlen, -
005B 35 outbuf = desc, -
005B 36 p1 = r2
96 AF A0 AF B0 006D 37 movw outlen, desc ;characters filled by fao
0072 38 show_buffer:
93 AF 7F 0072 39 pushaq desc
00000000'GF 01 FB 0075 40 calls #1, g^lib$put_output
9F 52 00000064 8F F3 007C 41 AOBLEQ #100,r2,loop ;limit.rl, index.ml
04 0084 42 ret
0085 43 .end start