Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

replaced http://codegolf.stackexchange.com/ with https://codegolf.stackexchange.com/
Source Link

I took my other answer my other answer and wrapped it in quasiquotes while adding input parameters. I print the resulting form as a single-line and remove unnecessary whitespace characters. The compiler is a little longer than the previous version, but the resulting score is reduced.

I took my other answer and wrapped it in quasiquotes while adding input parameters. I print the resulting form as a single-line and remove unnecessary whitespace characters. The compiler is a little longer than the previous version, but the resulting score is reduced.

I took my other answer and wrapped it in quasiquotes while adding input parameters. I print the resulting form as a single-line and remove unnecessary whitespace characters. The compiler is a little longer than the previous version, but the resulting score is reduced.

added 938 characters in body
Source Link
coredump
  • 6.9k
  • 25
  • 49

Common Lisp, 636(削除) 636 (削除ここまで) 577

(ql:quickload'cl-ppcre)(lambda(z)(pprint`princ(subseq(ppcre:regex-replace-all" *([(')]) *"(with-output-to-string(@)(print`(lambda(n)(dotimes(i n)(loop for(m s)in ',z if(=(mod(1+ i)m)0)do(princ s))(do()((fresh-line))(princ (1+ i)))))@))"\1円")1)))

I took my other answer and wrapped it in quasiquotes while adding input parameters. Since you require a textual output, I pprintprint the generatedresulting form. The generated code is not golfed, so there are as a single-line and remove unnecessary whitespace characters. Maybe I'll try to squeeze them out The compiler is a little longer than the previous version, but the resulting score is reduced.

(reduce #'+let '((Compiler*standard-output* 130(make-broadcast-stream)))
 (loop
 for form in '(215 ; Compiler
 () ; Count 159 ((1 "Golf")) ; Golf
 (Golf(3 "Fizz")(5 "Buzz"))) ; 168FizzBuzz
 for length = (if (numberp form) form
 (FizzBuzzlength 179(funcall *fun* form)))
 collect length into lengths
 sum length into :keysum
 #'second finally (return (values sum lengths))))

Returned values:

574
(215 111 119 129)
(defun fizz-buzz-compiler (specificationz)
 (pprintprinc (subseq
 (cl-ppcre:regex-replace-all
 " *([(')]) *"
 (with-output-to-string (stream)
 (print
 `(lambda(n)
 (dotimes(i n)
 (loop for (m s) in ',specificationz
 if (=(mod(1+ i)m)0)
 do (princ s))
 (do ()
 (do () ((fresh-line))
 (princ (1+ i))))) stream))
 "\1円") 1)))

... prints to standard output:

(LAMBDA(N)(DOTIMES(I N)(LOOP FOR(M S)IN'((3 "Fizz")(5 "Buzz"))IF(=(MOD(1+ I)M)0)DO(PRINC S))(DO NIL((FRESH-LINE))(PRINC(1+ I)))))

... which, pretty-printed, is:

Common Lisp, 636

(lambda(z)(pprint`(lambda(n)(dotimes(i n)(loop for(m s)in ',z if(=(mod(1+ i)m)0)do(princ s))(do()((fresh-line))(princ (1+ i)))))))

I took my other answer and wrapped it in quasiquotes while adding input parameters. Since you require a textual output, I pprint the generated form. The generated code is not golfed, so there are whitespace characters. Maybe I'll try to squeeze them out.

(reduce #'+ '((Compiler 130)
 (Count 159)
 (Golf 168)
 (FizzBuzz 179))
 :key #'second)
(defun fizz-buzz-compiler (specification)
 (pprint
 `(lambda(n)
 (dotimes(i n)
 (loop for (m s) in ',specification
 if (=(mod(1+ i)m)0)
 do (princ s))
 (do ()
 ((fresh-line))
 (princ (1+ i)))))))

... prints to standard output:

Common Lisp, (削除) 636 (削除ここまで) 577

(ql:quickload'cl-ppcre)(lambda(z)(princ(subseq(ppcre:regex-replace-all" *([(')]) *"(with-output-to-string(@)(print`(lambda(n)(dotimes(i n)(loop for(m s)in ',z if(=(mod(1+ i)m)0)do(princ s))(do()((fresh-line))(princ (1+ i)))))@))"\1円")1)))

I took my other answer and wrapped it in quasiquotes while adding input parameters. I print the resulting form as a single-line and remove unnecessary whitespace characters. The compiler is a little longer than the previous version, but the resulting score is reduced.

(let ((*standard-output* (make-broadcast-stream)))
 (loop
 for form in '(215 ; Compiler
 () ; Count  ((1 "Golf")) ; Golf
 ((3 "Fizz")(5 "Buzz"))) ; FizzBuzz
 for length = (if (numberp form) form
 (length (funcall *fun* form)))
 collect length into lengths
 sum length into sum
  finally (return (values sum lengths))))

Returned values:

574
(215 111 119 129)
(defun fizz-buzz-compiler (z)
 (princ (subseq
 (cl-ppcre:regex-replace-all
 " *([(')]) *"
 (with-output-to-string (stream)
 (print
 `(lambda(n)
 (dotimes(i n)
 (loop for (m s) in ',z
 if (=(mod(1+ i)m)0)
 do (princ s))
 (do () ((fresh-line))
 (princ (1+ i))))) stream))
 "\1円") 1)))

... prints to standard output:

(LAMBDA(N)(DOTIMES(I N)(LOOP FOR(M S)IN'((3 "Fizz")(5 "Buzz"))IF(=(MOD(1+ I)M)0)DO(PRINC S))(DO NIL((FRESH-LINE))(PRINC(1+ I)))))

... which, pretty-printed, is:

added 277 characters in body
Source Link
coredump
  • 6.9k
  • 25
  • 49

Common Lisp, ? (scoring)636

(lambda(z)(pprint`(lambda(n)(dotimes(i n)(loop for(m s)in ',z if(=(mod(1+ i)m)0)do(princ s))(do()((fresh-line))(princ (1+ i)))))))

I took my other answer and wrapped it in quasiquotes while adding input parameters. Since you require a textual output, I pprint the generated form. The generated code is not golfed, so there are whitespace characters. Maybe I'll try to squeeze them out.

Score

(reduce #'+ '((Compiler 130)
 (Count 159)
 (Golf 168)
 (FizzBuzz 179))
 :key #'second)

Common Lisp, ? (scoring)

(lambda(z)(pprint`(lambda(n)(dotimes(i n)(loop for(m s)in ',z if(=(mod(1+ i)m)0)do(princ s))(do()((fresh-line))(princ (1+ i)))))))

I took my other answer and wrapped it in quasiquotes while adding input parameters. Since you require a textual output, I pprint the generated form.

Common Lisp, 636

(lambda(z)(pprint`(lambda(n)(dotimes(i n)(loop for(m s)in ',z if(=(mod(1+ i)m)0)do(princ s))(do()((fresh-line))(princ (1+ i)))))))

I took my other answer and wrapped it in quasiquotes while adding input parameters. Since you require a textual output, I pprint the generated form. The generated code is not golfed, so there are whitespace characters. Maybe I'll try to squeeze them out.

Score

(reduce #'+ '((Compiler 130)
 (Count 159)
 (Golf 168)
 (FizzBuzz 179))
 :key #'second)
Source Link
coredump
  • 6.9k
  • 25
  • 49
Loading

AltStyle によって変換されたページ (->オリジナル) /