Skip to content

Latest commit

 

History

History
3098 lines (2215 loc) · 85.4 KB

VimGolf.org

File metadata and controls

3098 lines (2215 loc) · 85.4 KB
# -*- coding: utf-8; -*- #+TITLE: Emacs Solutions to [[http://www.vimgolf.com/][VimGolf]] #+OPTIONS: toc:nil #+NAME: progress | Total | Done | (%) | |-------+------+-------| | 345 | 347 | 100.6 | #+TBLFM: $2='(count-matches "^\\* ")::$3=($2/$1)*100;p4 #+TOC: headlines 1 * [[https://vimgolf.com/challenges/510b1c61e48b7e0002000028][Chinese Multiplication Table]] <2017-01-29 Sun> #+BEGIN_SRC emacs-lisp :exports both (loop for i from 1 to 9 concat (concat (mapconcat #'identity (loop for j from 1 to i collect (format "%d*%d=%d" i j (* i j))) " ") "\n")) #+END_SRC #+RESULTS: : 1*1=1 : 2*1=2 2*2=4 : 3*1=3 3*2=6 3*3=9 : 4*1=4 4*2=8 4*3=12 4*4=16 : 5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 : 6*1=6 6*2=12 6*3=18 6*4=24 6*5=30 6*6=36 : 7*1=7 7*2=14 7*3=21 7*4=28 7*5=35 7*6=42 7*7=49 : 8*1=8 8*2=16 8*3=24 8*4=32 8*5=40 8*6=48 8*7=56 8*8=64 : 9*1=9 9*2=18 9*3=27 9*4=36 9*5=45 9*6=54 9*7=63 9*8=72 9*9=81 注意上面有两处没有对齐。 * [[https://vimgolf.com/challenges/56fb2e75ccffcc0009026473][One number per line]] <2017-01-29 Sun> 1. ~M-x replace-string RET , RET C-q C-j RET~ 2. ~M-x delete-matching-lines RET ^$ RET~ * [[https://vimgolf.com/challenges/52c3cb0d9b8634000200000e][A HAPPY NEW YEAR 2014 !]] <2017-01-29 Sun> If necessary, use ~M-x org-increase-number-at-point~ or similar to increase/decrease number at point. * [[https://vimgolf.com/challenges/54862fbb3f90ac0002904cf5][Just the middle]] <2017-01-29 Sun> Just edit like in any normal text editor. Or mark the region of text which is useful and run the following command. #+BEGIN_SRC emacs-lisp (defun delete-whole-buffer-but-region (beg end) (interactive "*r") (delete-region end (point-max)) (delete-region (point-min) beg)) #+END_SRC * [[https://vimgolf.com/challenges/5462e3f41198b80002512673][I forgot quotes]] <2017-01-29 Sun> 1. Enable ~electric-pair-mode~ 2. Mark the region of text which needs quotes and enter one ~"~ * [[http://www.vimgolf.com/challenges/55bcdc3ef4219f456102374f][Vice versa]] <2017-01-29 Sun> > Little role switching. #+BEGIN_SRC diff - The quick brown fox jumps over the lazy dog. + The quick lazy dog jumps over the brown fox. #+END_SRC ** Solution Hmm, I have made a package (swap-regions) for this. 1. Select "brown fox" and cancel it with ~C-g~ 2. Select "lazy dog" 3. ~M-x swap-regions~ * [[http://www.vimgolf.com/challenges/5192f96ad8df110002000002][Words in parens]] <2017-01-29 Sun> Start file: #+BEGIN_EXAMPLE one two three #+END_EXAMPLE End file: #+BEGIN_EXAMPLE (one) (two) (three) #+END_EXAMPLE ** Solution *** Solution 1 with ~electric-pair-mode~ Enable it if necessary 1. Mark the word 2. Hit ~(~ *** Solution 2 with ~paredit-mode~ Enable it if necessary 1. Move point to the word and hit ~M-(~ By the way, 1) mark the word 2) hit ~(~. works too. * [[http://www.vimgolf.com/challenges/56d70389bbbe462aff01d42a][Swap values]] <2017-01-29 Sun> #+BEGIN_SRC diff - name=www-data, groups=developer + name=developer, groups=www-data #+END_SRC Use ~swap-regions~. * [[http://www.vimgolf.com/challenges/53d93fc3768e280002124f23][V to the i]] <2017-01-29 Sun> #+BEGIN_QUOTE Input is 99 V's. Output is 100 i's. #+END_QUOTE #+BEGIN_SRC diff - VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV + iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii #+END_SRC ** Solution 1. ~C-k~ 2. ~C-u 100 i~ (or simply type ~M-1 0 0 i~) * [[http://www.vimgolf.com/challenges/540629666a1e4000020d9e5a][-a-b-c-]] <2017-01-29 Sun> #+BEGIN_SRC diff - abcdefghijklm + -a-b-c-d-e-f-g-h-i-j-k-l-m- #+END_SRC ** Solution #+BEGIN_SRC emacs-lisp (defun put-hyphens-everywhere (beg end) (interactive "*r") (insert (concat "-" (mapconcat #'string (string-to-list (delete-and-extract-region beg end)) "-") "-"))) #+END_SRC * [[http://www.vimgolf.com/challenges/4f0720c8f037090001000007][switch variable]] <2017-01-29 Sun> #+BEGIN_SRC diff - int barins, foovariable = 1; + int foovariable, barins = 1; #+END_SRC ** Solution ~M-t~ (~transpose-words~) should just work for this case, thougth it is better to use ~C-M-t~ (~transpose-sexps~). * [[https://vimgolf.com/challenges/57343555fd77ad227900df4a][Split line with dots]] <2017-01-29 Sun> Start file #+BEGIN_SRC ruby class VimGolf def split_me MyModel .first_method.second_method(arg).third_method(arg.method_one.method_two) end end #+END_SRC End file #+BEGIN_SRC ruby class VimGolf def split_me MyModel .first_method .second_method(arg) .third_method(arg.method_one.method_two) end end #+END_SRC ** Solution ~electric-indent-mode~ defaults to ~t~, thus simply ~RET~ will indent code automatically. So the solution is moving point to ~.~ and type ~RET~. Just in case, I would have to repeat it a lot: define the following keyboard macro with ~~ and ~~ or ~C-x (~ and ~C-x )~. #+BEGIN_EXAMPLE C-s . C-b RET C-f #+END_EXAMPLE Run the last keyboard macro with ~C-x e~ (~kmacro-end-and-call-macro~). * [[https://vimgolf.com/challenges/583112d0215b7c3ed2016bdb][Order and join]] <2017-01-29 Sun> Start file #+BEGIN_EXAMPLE four one two five three six #+END_EXAMPLE End file #+BEGIN_EXAMPLE one two three four five six #+END_EXAMPLE ** Solution Type ~M-^~ (~delete-indentation~ or its alias ~join-line~) for several times and in several places. * [[https://vimgolf.com/challenges/559c30948ef59c0eb7000002][Collect List]] <2017-01-29 Sun> Start file #+BEGIN_EXAMPLE * item1 * item2 * item3 * item4 * item5 #+END_EXAMPLE End file #+BEGIN_EXAMPLE item1,item2,item3,item4,item5 #+END_EXAMPLE ** Solution 1. Remove the prefix "* " 1. Mark the rectangle region with ~C-x SPC~ 2. Delete it with ~C-w~ 2. Join the line with "," by ~M-% C-q C-j RET , RET~ (~query-replace~) * [[https://vimgolf.com/challenges/576c778ea4896a561b01b4f2][Copy three lines]] <2017-01-29 Sun> 1. Mark the text and copy it with ~M-w~ 2. Yank the text with ~M-y~ (~helm-show-kill-ring~) and delete unneeded text with ~C-k~ 3. Repeat step 2 * [[https://vimgolf.com/challenges/54595b13128576000257a3c1][Basic renumbering]] <2017-01-29 Sun> Start file #+BEGIN_EXAMPLE 10 PRINT "The actual" 15 PRINT "code doesn't" 16 PRINT "really matter." 20 PRINT "Just take" 25 PRINT "care of" 30 PRINT "the numbers." #+END_EXAMPLE End file #+BEGIN_EXAMPLE 10 PRINT "The actual" 20 PRINT "code doesn't" 30 PRINT "really matter." 40 PRINT "Just take" 50 PRINT "care of" 60 PRINT "the numbers." #+END_EXAMPLE ** Solution - Remove old prefix with ~C-x SPC~ (~rectangle-mark-mode~) and ~C-w~ - Insert new prefix with the following command (Notes that ~C-x r N~ (~rectangle-number-lines~)'s step always is 1 thus doesn't work here) #+BEGIN_SRC emacs-lisp (defun number-region (start end start-at step) (interactive "*r\nnNumber to count from: \nnStep: ") (apply-on-rectangle (lambda (start end _arg) (move-to-column start t) (insert (format "%d " start-at)) (incf start-at step)) start end nil)) #+END_SRC * [[https://vimgolf.com/challenges/51f4a64c6813e30002000018][quotes inside quotes]] <2017-01-30 Mon> Start file #+BEGIN_EXAMPLE This string contains a 'quoted' word. This string contains 'two' quoted 'words.' This 'string doesn't make things easy.' #+END_EXAMPLE End file #+BEGIN_EXAMPLE This string contains a "quoted" word. This string contains "two" quoted "words." This "string doesn't make things easy." #+END_EXAMPLE ** Solution 1. Mark the text (including quotes) 2. Call the following command #+BEGIN_SRC emacs-lisp (defun toggle-single-and-double-quote (beg end) (interactive "*r") (let ((s (buffer-substring beg end)) double-p) (if (and (> (length s) 2) (let ((left (aref s 0)) (right (aref s (1- (length s))))) (or (= left right ?') (prog1 (= left right ?\") (setq double-p t))))) (progn (delete-region beg end) (insert (if double-p ?' ?\") (substring s 1 -1) (if double-p ?' ?\"))) (message "You need mark a region of \"'foo'\" before calling this")))) #+END_SRC The following can help editing pairs or quotes under some particular situations nicely. - ~electric-pair-mode~ (built-in) - ParEdit (ELPA) - cycle-quotes (ELPA) * [[https://vimgolf.com/challenges/571808767dd9d30009000001][Align commas]] <2017-01-30 Mon> Start file #+BEGIN_EXAMPLE just = make, all, the, commas, line, up #+END_EXAMPLE End file #+BEGIN_EXAMPLE just = make , all , the , commas, line , up #+END_EXAMPLE ** Solution ~M-x align-regexp RET , RET~ works out of box. Though, I still don't know how this works. I will need to figure this out once facing more complex task. * [[https://vimgolf.com/challenges/4d1a1c36567bac34a9000002][Reformat/Refactor a Golfer Class]] <2017-01-30 Mon> Just edit normally. * [[https://vimgolf.com/challenges/4d1a8bf2b8cb3409320002c4][Search and Replace 0]] <2017-01-30 Mon> ~M-% aaa RET xaaax RET~ * [[https://vimgolf.com/challenges/53c66c482b4166000226bbee][Don't know what this is]] <2017-01-30 Mon> Start file #+BEGIN_EXAMPLE [1:0] [0:1] [1:100] [0:100] #+END_EXAMPLE End file #+BEGIN_EXAMPLE [ ] [ ] [ ] [ ] #+END_EXAMPLE ** Solution Use ~C-M-%~ (~query-replace-regexp~) then replace - ~\[\(.\)\]~ with - ~\,(format "[%s]" (make-string (length \1) ? ))~ For the use of ~\,~, see [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Regexp-Replace.html][(info "(emacs) Regexp Replace")]]. * [[http://www.vimgolf.com/challenges/56ef78d9f604b51ec4007b8d][Scrambled numbers]] <2017-01-30 Mon> Start file #+BEGIN_EXAMPLE Four is 1. One is 2. Five is 3. Three is 4. Six is 5. Two is 6. #+END_EXAMPLE End file #+BEGIN_EXAMPLE One is 1. Two is 2. Three is 3. Four is 4. Five is 5. Six is 6. #+END_EXAMPLE ** Solution - Enable ~swap-word-mode~ then - swap word up/down with ~~ and ~~ #+BEGIN_SRC emacs-lisp (defun swap-word-up->down () (interactive) (let ((b1 (bounds-of-thing-at-point 'word)) s1 e1 t1 s2 e2 t2) (when b1 (setq s1 (car b1) e1 (cdr b1) t1 (buffer-substring s1 e1)) (save-excursion (forward-line 1) (setq b2 (bounds-of-thing-at-point 'word) s2 (car b2) e2 (cdr b2) t2 (buffer-substring s2 e2)) (delete-region s2 e2) (insert t1)) (delete-region s1 e1) (insert t2)))) (defun swap-word-down->up () (interactive) (let ((b1 (bounds-of-thing-at-point 'word)) s1 e1 t1 b2 s2 e2 t2) (when b1 (save-excursion (forward-line -1) (setq b2 (bounds-of-thing-at-point 'word)) (when b2 (setq s1 (car b1) e1 (cdr b1) t1 (buffer-substring s1 e1) s2 (car b2) e2 (cdr b2) t2 (buffer-substring s2 e2)))) (delete-region s1 e1) (insert t2) (forward-line -1) (delete-region s2 e2) (insert t1)))) (define-minor-mode swap-word-mode "Swap word up/down." :init nil :lighter " Swap word" :keymap (let ((map (make-sparse-keymap))) (define-key map (kbd "") #'swap-word-down->up) (define-key map (kbd "") #'swap-word-up->down) map)) #+END_SRC * [[http://www.vimgolf.com/challenges/54df95a4a4b28331e9000003][Space out the alphabet]] <2017-01-30 Mon> 1. ~M-x replace-regexp RET \(.\) RET \1 RET~ 2. Delete leading white spaces with rectangle mark mode. By the way, I don't know how a regexp which matches any character but not at the beginning of a line. * [[http://www.vimgolf.com/challenges/4f438739f5a8d70001000019][replacing each line of a block selection]] <2017-01-30 Mon> Replace (or query-replace) string (or regexp) as usual. * [[http://www.vimgolf.com/challenges/4ef209ef78702b0001000019][Make it more readable]] <2017-01-30 Mon> - Replace ~#~ with ~\n\n#~ with ~M-x replace-string~ - Delete leading empty lines with the most obvious way (that is, delete multiple times or mark then delete) * [[http://www.vimgolf.com/challenges/539c50b188b4e20002053e38][Where should I put the Newline?]] <2017-01-30 Mon> Replace (or query-replace) ~--->newline<---~ with ~--->\n<---~. Notes, to enter ~\n~ from MiniBuffer, type ~C-q C-j~ (~C-q~ is bound to ~quoted-insert~). * [[http://www.vimgolf.com/challenges/4d716c76919202611400002b][Numbering a List]] <2017-01-30 Mon> 1. Mark the region 2. ~C-u C-x r N RET %1d. RET~ (i.e., call ~rectangle-number-lines~ with a prefix argument, and use the default start (that is 1), and enter the format) * [[http://www.vimgolf.com/challenges/54345d14d529ef0002227d4c][That hyphen]] <2017-01-30 Mon> Just normal edit. * [[http://www.vimgolf.com/challenges/58409414770f4b474601384c][Sort files from hosts]] <2017-01-31 Tue> Start file #+BEGIN_EXAMPLE dartacan: /etc/hosts dartacan: /etc/httpd/conf/httpd.conf dartacan: /opt/scripts/list_vhosts mozart: /etc/resolv.conf mozart: /usr/bin/vim mozart: /usr/bin/awesome mozart: ~/.gem/ruby/2.1.0/bin/vimgolf gullit: /bin/bash gullit: /etc/hosts gullit: /usr/bin/xorg gullit: /usr/bin/xeyes gullit: /usr/bin/X gullit: / #+END_EXAMPLE End file #+BEGIN_EXAMPLE dartacan: /etc/hosts /etc/httpd/conf/httpd.conf /opt/scripts/list_vhosts mozart: /etc/resolv.conf /usr/bin/vim /usr/bin/awesome ~/.gem/ruby/2.1.0/bin/vimgolf gullit: /bin/bash /etc/hosts /usr/bin/xorg /usr/bin/xeyes /usr/bin/X / #+END_EXAMPLE ** Solution 1. Define the following keyboard macro with ~C-x (~ and ~C-x )~ 2. Execute it with ~C-x e~ by moving point accordingly or ~M-x apply-macro-to-region-lines~ by select the region. #+BEGIN_EXAMPLE Last macro: C-a C-SPC C-s : C-f C-w M-^ #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/57a208ce38e7e83a43000003][Generate a list of numbers]] <2017-01-31 Tue> #+BEGIN_QUOTE Please generate list of numbers from 1 to 20. #+END_QUOTE ** Solution #+BEGIN_SRC emacs-lisp (loop for i from 1 to 20 do (insert (format "%s " i))) #+END_SRC * [[http://www.vimgolf.com/challenges/536cfa23fcccd100025678bd][Extract argument from function]] <2017-01-31 Tue> Nothing special, edit as usual. * [[http://www.vimgolf.com/challenges/4d1a4d82a860b7447200008d][Whitespace, empty lines and tabs]] <2017-01-31 Tue> 1. Replace one tab with one space with query-replace or just replace 2. Strip trailing whitespace with ~M-x delete-trailing-whitespace~ 3. Delete empty lines with ~M-x delete-matching-lines ^$~ In Emacs, ~untabify~ and ~whitespace-cleanup~ are much more sophisticated. * [[http://www.vimgolf.com/challenges/5100ce70326e09000200004a][Saving the hashes(#)]] <2017-01-31 Tue> #+BEGIN_QUOTE Our goal is to delete every line which doesn't contain a hash signs. The remaining hash signs with numbers are then sorted to get the final output. #+END_QUOTE ** Solution 1. Delete line which don't contain a hash with ~M-x delete-non-matching-lines #~ 2. Make all # on its own line with replace " #" with "\n#" 3. Reverse the lines (since it's sorted already) with ~M-x reverse-region~ * [[http://www.vimgolf.com/challenges/5421e49fdbded100021e4934][Count both ways]] <2017-01-31 Tue> 1. Copy "two three four five six seven eight nine ten eleven" and paste it to next line 2. Mark the second line and replace " " with "\n" with ~M-x replace-string~. * [[http://www.vimgolf.com/challenges/5526aef5814f89118e00f23c][camel riding]] <2017-01-31 Tue> #+BEGIN_SRC diff -val (schemas, activeCount, techTagCount, sharedCount, allowedPathsCount, rootCount, searchableCount) = fieldStats(store) +val (schemas, schActiveCount, schTechTagCount, schSharedCount, schAllowedPathsCount, schRootCount, schSearchableCount) = fieldStats(store) #+END_SRC Define a keyboard macro of simple edit plus ~M-x upcase-initials-region~. * [[http://www.vimgolf.com/challenges/53b473a3ac0ceb00022303bd][Do you demand a shrubbery?]] <2017-01-31 Tue> Normal edit. * [[http://www.vimgolf.com/challenges/57a87f444f1a8e3c4000ff8c][Pretty multi-line bash]] <2017-01-31 Tue> ~M-x align-regexp RET && RET~ * [[http://www.vimgolf.com/challenges/54698da795f6da00020d85ed][Condensed Cases]] <2017-01-31 Tue> # \nbsp stands for one space, see (info "(org) Special symbols") for # more info 1. Set "\nbsp\nbsp\nbsp\nbsp{}case" as ~fill-prefix~ by moving point right after it and hitting ~C-.~ (or ~M-x set-fill-prefix~). 2. Join the line with previous one with ~M-^~ (or ~M-x delete-indentation~) 3. Replace " " with " ," by using query-replace on a region. * [[http://www.vimgolf.com/challenges/5325695c6092800002072d06][Mess in revision history]] <2017-01-31 Tue> Use ~C-x SPC~ (~rectangle-mark-mode~) to mark the region and ~C-x r t~ (~string-rectangle~) to insert the leading spaces. * [[http://www.vimgolf.com/challenges/5054baaafa0b390002000029][SFD-ROC: vimvimvim]] <2017-01-31 Tue> Replace "vim" with "vim\n" by typing ~M-x replace-string RET vim RET vim C-q C-j RET~. * [[http://www.vimgolf.com/challenges/56680033ac11043d6306aa07][Replace and keep the case]] <2017-01-31 Tue> Emacs by default does this, simply run ~M-%~ (~query-replace~) or just ~M-x replace-string~. * [[http://www.vimgolf.com/challenges/580c21b5c177c54b0d067069][Start coding format]] <2017-01-31 Tue> Type it literally. CC Mode is powerful. * [[http://www.vimgolf.com/challenges/51e023f92b2f6d0002000066][Hole-in-one]] <2017-01-31 Tue> Edit as usual. * [[http://www.vimgolf.com/challenges/4d1e634e509d6e19d8000081][Shebangs for all]] <2017-01-31 Tue> Edit as usual. * [[http://www.vimgolf.com/challenges/5447b459380e8b0002000db3][Gray area]] <2017-01-31 Tue> Edit as usual. - Copy a region with ~M-w~ (~kill-ring-save~) - Clear a region with ~C-x r c~ (~clear-rectangle~) - Delete a region with ~C-w~ (~kill-region~) * [[http://www.vimgolf.com/challenges/53369b712a09c1000223fb57][Two become one]] <2017-01-31 Tue> Edit as usual, nothing special. * [[https://vimgolf.com/challenges/4ed3d247a745c1000100002a][remove dupes from array]] <2017-01-31 Tue> Start file #+BEGIN_EXAMPLE [11, 2, 3,5 , 1,1, 22, 4] #+END_EXAMPLE End file #+BEGIN_EXAMPLE [1, 2, 3, 4, 5, 11, 22] #+END_EXAMPLE ** Solution Mark the numbers in the region and run the following command. #+BEGIN_SRC emacs-lisp (defun sort-and-remove-dup-in-region (start end) (interactive "*r") (let* ((str (buffer-substring start end)) (replace (mapconcat #'number-to-string (sort (mapcar #'string-to-number (delete-dups (split-string str "[ ]*,[ ]*"))) #'<) ", "))) (delete-region start end) (insert replace))) #+END_SRC * [[https://vimgolf.com/challenges/584dd156842bd00769000001][Double and switch]] <2017-01-31 Tue> Oh, I don't really know the answer and also don't have much interest to find it out. I decide to give it up. The following minor mode is for enlarge/shrink the region in binary way, which might be helpful for answering this challenge. #+BEGIN_SRC emacs-lisp (defvar binary-region-mode-map (let ((map (make-sparse-keymap))) (define-key map [?+] #'binary-region+) (define-key map [?-] #'binary-region-) map)) (define-minor-mode binary-region-mode "用二分法扩大或缩小 the region." :lighter " Binary-Region" :keymap binary-region-mode-map) (defun binary-region+ (start end) (interactive "r") (when (use-region-p) (set-mark start) (goto-char (+ (- end start) end)))) (defun binary-region- (start end) (interactive "r") (when (use-region-p) (set-mark start) (goto-char (+ (/ (- end start) 2) start)))) #+END_SRC * [[https://vimgolf.com/challenges/4d1a71b5b8cb340932000109][Change the content of a string]] <2017-01-31 Tue> Edit as usual. * [[https://vimgolf.com/challenges/54ddd1d261cec11d1b01707c][Mute the second method of this script]] <2017-01-31 Tue> 1. Mark the method with ~C-M-h~ (~mark-defun~) 2. Comment the region with ~M-:~ (~comment-dwim~) * [[https://vimgolf.com/challenges/50ae009b65b8db0002000047][Let's play some Ivmgolf]] <2017-01-31 Tue> 1. Mark "Iv" across 4 lines in rectangle mode with ~C-x SPC~ (~rectangle-mark-mode~) 2. ~C-x r t Vi RET~ (~string-rectangle~) * [[https://vimgolf.com/challenges/57a021b0d938573add00bcd0][A grid of punctuation]] <2017-01-31 Tue> 1. Record a keyboard macro for yanking "-=" and ~C-u 40 C-x e~ (~kmacro-end-and-call-macro~) to yank 40 times 2. Make the second line by some manually edits 3. Do the similar thing in 1 * [[https://vimgolf.com/challenges/56462467f20fe74c93000001][lipsum lines]] <2017-01-31 Tue> 1. Delete double-quotes 2. Wrap lines in ~"\1",~ with ~C-M-%~ (~query-replace-regexp~) 3. Cleanup * [[http://www.vimgolf.com/challenges/4d1ccfde35b40650b80004ae][The Cake is a Lie]] <2017-02-01 Wed> Simply run ~M-c~ (~capitalize-word~) a few times. 1. Delete words with ~M-x replace-regexp RET [a-z ]* RET \n RET~ 2. Record keyboard macro ~C-a C-SPC C-e " , M-^~ then mark the appropriate region and run ~M-x apply-macro-to-region-lines~ 3. Cleanup * [[http://www.vimgolf.com/challenges/4fc9d767d3a0d4000100000e][Append semicolon after expressions]] <2017-02-01 Wed> ~C-M-% ^\(.+\)$ RET \1; RET~ (~query-replace-regexp~) * [[http://www.vimgolf.com/challenges/4d1a5275a860b74472000110][Sort and add attributes]] <2017-02-01 Wed> 1. Sort via ~M-x sort-lines~ 2. Add attributes via ~M-x replace-string RET ) RET , :country => "USA") RET~ * [[http://www.vimgolf.com/challenges/55d7692d134b34420f05ac0b][Add to end of each line... kinda]] <2017-02-01 Wed> Replace or query-replace as usual. * [[http://www.vimgolf.com/challenges/4d1e29fda93ce03311000066][Ruby 1.9 hashes]] <2017-02-01 Wed> Use ~query-replace-regexp~ or ~rectangle-mark-mode~. * [[http://www.vimgolf.com/challenges/4d1a6a8eb8cb34093200007a][Reconstruct the Sentence]] <2017-02-01 Wed> 1. Sort lines with ~C-u -1 M-x sort-numeric-fields~ 2. Join lines via ~M-x replace-regexp~ * [[http://www.vimgolf.com/challenges/54a8fb2ff4048c0002479f12][Happy TvvO]] <2017-02-01 Wed> Edit as usual. * [[http://www.vimgolf.com/challenges/4fa0d2fa2037000001000057][Exchanging Quotes]] <2017-02-01 Wed> Replace - ~'~ to ~"~ - ~\'~ to ~'~ with ~M-x plur-query-replace RET {',\'} RET {",'} RET~ (Notes that the command is from plur package, which is written by me and available from melpa) * [[http://www.vimgolf.com/challenges/553b97364ba96c319d0296eb][readability]] <2017-02-01 Wed> Surround ~[-=*+/]~ with one space by using ~M-x replace-regexp~. Notes that ~-~ is a special character in ~[]~, to include it, it should be placed at the beginning or end of ~[]~. * [[https://vimgolf.com/challenges/55771cc4750ef86573003b83][Line 'em up!]] <2017-02-01 Wed> ~M-x align-regexp RET => RET~ * [[https://vimgolf.com/challenges/54e05c0e3da7a40ce4002226][ASCII box]] <2017-02-03 Fri> ~M-x comment-box RET * RET~ * [[https://vimgolf.com/challenges/4d1cdb0635b40650b8000527][Make Fancy Header]] <2017-02-03 Fri> I don't know fancy method, simply edit as usual. * [[https://vimgolf.com/challenges/53eb4ac3f690b50002f871b6][Lisp Condense]] <2017-02-03 Fri> Emacs understands Lisp. Type ~M-R~ (~paredit-raise-sexp~) or ~M-x raise-sexp~. * [[https://vimgolf.com/challenges/56e69da07b3d84520a000001][Mirrored text]] <2017-02-04 Sat> #+BEGIN_SRC emacs-lisp (defun chunyang-eval-on-region (beg end) (interactive "r") (let ((text (buffer-substring-no-properties beg end))) (eval (read--expression "Eval on region (local var: beg, end, text): ")))) #+END_SRC ~M-x chunyang-eval-on-region RET (kill-new (nreverse text)) RET~ * [[https://vimgolf.com/challenges/53e1d5a0f201bc0002226501][120 Degrees]] <2017-02-04 Sat> #+BEGIN_QUOTE Rotate that triangle. #+END_QUOTE Start file #+BEGIN_EXAMPLE 4 3 5 2 6 1 9 8 7 #+END_EXAMPLE End file #+BEGIN_EXAMPLE 4 3 5 2 6 1 9 8 7 #+END_EXAMPLE ** Solution Select that triangle and execute the following command #+BEGIN_SRC emacs-lisp (defun rotate-that-triangle (beg end) (interactive "*r") (let* ((text (buffer-substring beg end)) (list (split-string text)) (sorted (loop for i in '(0 2 4 8 7 6 5 3 1) collect (nth i list))) (rotated (append (seq-subseq sorted 3) (seq-subseq sorted 0 3)))) (goto-char beg) (loop for i in '(0 8 1 7 2 6 5 4 3) do (forward-to-word 1) (cl-destructuring-bind (b . e) (bounds-of-thing-at-point 'word) (delete-region b e) (insert (nth i rotated)))))) #+END_SRC * [[https://vimgolf.com/challenges/4d1a4f2ba860b744720000bf][Flodder-challenge]] <2017-02-04 Sat> Use ~M-c~ (~capitalize-word~), ~M-u~ (~upcase-word~) and ~M-L~ (~downcase-dwim~). * [[https://vimgolf.com/challenges/4d1c1a3cf655cd081000000d][A Simple One]] <2017-02-04 Sat> hmm, just delete the old and insert the new. Though, ~org-increase-number-at-point~ works (prefix with ~C-u 25~ and ~C-u 49~). * [[https://vimgolf.com/challenges/54f6e85d8dca0315e1010de1][Logging with key]] <2017-02-04 Sat> Edit as usual. * [[https://vimgolf.com/challenges/56a260eedb173f2f5d00f6f8][JS notation to Immutable.js notation]] <2017-02-04 Sat> Use keyboard macro and rectangle region mode. * [[https://vimgolf.com/challenges/4d1b1b97c58eaa2a8a0002fc][Python Hello World! Reformatting]] <2017-02-04 Sat> Edit as usual. * [[https://vimgolf.com/challenges/521c805d860021000200007d][VimGolfNight]] <2017-02-04 Sat> Edit as usual. * [[https://vimgolf.com/challenges/50519ca330c82d0002000035][The name of the game]] <2017-02-04 Sat> Edit as usual. * [[https://vimgolf.com/challenges/50d0d80eaa503f000200001b][Swap assigned value]] <2017-02-05 Sun> Use ~swap-regions~. * [[https://vimgolf.com/challenges/4d1db1b8de2f897c2a00014a][Reverse Simple Deletion]] <2017-02-05 Sun> ~C-M-% . RET \& C-q C-j RET~ (~query-replace-regexp~) * [[https://vimgolf.com/challenges/5107179a44d65e0002000048][Minimalist Limerick]] <2017-02-05 Sun> Edit as usual. * [[https://vimgolf.com/challenges/53ab5ade4367c700025ce66a][Shuffle puzzle]] <2017-02-05 Sun> Edit as usual. * [[https://vimgolf.com/challenges/4d3c51f1aabf526ed6000030][HTML to Haml]] <2017-02-06 Mon> Edit as usual. * [[https://vimgolf.com/challenges/55358965015b7c2d46000001][Shuffled numbers]] <2017-02-06 Mon> Select the region and execute the following command. #+BEGIN_SRC emacs-lisp (defun my-sort-lines (reverse beg end) (interactive "P\nr") (save-excursion (save-restriction (narrow-to-region beg end) (goto-char (point-min)) (let ;; To make `forward-word' and etc. to ignore fields. ((inhibit-field-text-motion t)) (sort-subr reverse 'forward-line 'end-of-line nil 'forward-word (lambda (x y) (let ((list '(zero one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen twenty)) (s1 (buffer-substring (car x) (cdr x))) (s2 (buffer-substring (car y) (cdr y)))) (< (seq-position list (intern s1)) (seq-position list (intern s2)))))))))) #+END_SRC * [[https://vimgolf.com/challenges/4d2c9d06eda6262e4e00007a][Assignment Alignment]] <2017-02-06 Mon> ~M-x align-regexp RET = RET~ * [[https://vimgolf.com/challenges/4f99b09353e306000100003f][The meaning]] <2017-02-07 Tue> Go to the line end via ~C-e~ (~move-end-of-line~) and swap the chars with ~C-t~ (~transpose-chars~). * [[https://vimgolf.com/challenges/50bda7a73645b3000200004b][lamb had a little Mary]] <2017-02-07 Tue> Use ~M-x plur-replace~ or ~M-x query-replace-regexp~. * [[https://vimgolf.com/challenges/50ee7504c0e3aa0002000040][Prefixes and suffixes]] <2017-02-07 Tue> Use keyboard macro. * [[https://vimgolf.com/challenges/55e814a35f5608403d000001][Vim's not included features]] <2017-02-07 Tue> #+BEGIN_SRC emacs-lisp (while (re-search-forward "-[_[:word:]]+" nil t) (message "%s" (match-string 0))) #+END_SRC Notes that the order is not the same as the end file. * [[https://vimgolf.com/challenges/56e3697dd64dfc4d1800a774][Free hyphen!]] <2017-02-07 Tue> Do it manually or record a keyboard macro. * [[https://vimgolf.com/challenges/525ee6a5de92470002000039][Split the words]] <2017-02-07 Tue> Do it manually or simply ignore this challenge. * [[https://vimgolf.com/challenges/4d4ab047795d626036000034][imports alignment (python)]] <2017-02-07 Tue> Do it manually. * [[https://vimgolf.com/challenges/56d30b70a365ed316105641b][Sorting a glossary]] <2017-02-07 Tue> Kill and Yank. * [[https://vimgolf.com/challenges/51103ad8041832000200003f][vim = 22 / 7]] <2017-02-07 Tue> Use keyboard macro. * [[https://vimgolf.com/challenges/51d6ddf4b0c5d6000200002e][Pairs of numbers]] <2017-02-07 Tue> Execute the following command: #+BEGIN_SRC emacs-lisp (defun foo () (interactive) (let (numbers) ;; Collect numbers (while (re-search-forward "-?[.0-9]+" nil t) (push (match-string 0) numbers)) (setq numbers (nreverse numbers)) ;; Compute and insert the result (goto-char (point-max)) (seq-let (group1 group2) (seq-partition numbers (/ (length numbers) 2)) (seq-mapn (lambda (x y) (insert (format "[%s, %s]\n" x y))) group1 group2)))) #+END_SRC * [[https://vimgolf.com/challenges/4d1aaf2fb11838287d000036][Reverse characters in a line]] <2017-02-07 Tue> ~M-: (insert (nreverse "text"))~ (~eval-expression~) * [[http://www.vimgolf.com/challenges/53fdb108658ede0002599a8f][Suffix sort]] <2017-02-08 Wed> Select the region and run the command: #+BEGIN_SRC emacs-lisp (defun suffix-sort (beg end) "Sort from the end of the line, as if the letters in each line were reversed." (interactive "*r") (save-excursion (save-restriction (narrow-to-region beg end) (goto-char (point-min)) (sort-subr nil #'forward-line #'end-of-line nil nil (lambda (x y) (let ((s1 (buffer-substring (car x) (cdr x))) (s2 (buffer-substring (car y) (cdr y)))) (string< (nreverse s1) (nreverse s2)))))))) #+END_SRC * [[http://www.vimgolf.com/challenges/50502d985cfbf50002000022][NATO phonetic alphabet]] <2017-02-08 Wed> 1. Use ~M-%~ (~query-replace~) to split text into lines 2. Use ~C-x r M-w~ (~copy-rectangle-as-kill~) and ~C-x r y~ (~yank-rectangle~) to add the prefix * [[http://www.vimgolf.com/challenges/508fe9f57acca60002000037][Stairs Indenting]] <2017-02-08 Wed> ~C-M-% [0-9]+ RET \,(format "%s%s" (make-string (string-to-number \&) ? ) \&) RET~ (~query-replace-regexp~) Tips: - Use ~\,~ to follow a sexp - Use ~\&~ to denote the whole match * [[http://www.vimgolf.com/challenges/4d1a790fb8cb3409320001a8][Reformat most common surnames]] <2017-02-08 Wed> 1. Remove unneed parts with ~C-M-%~ (~query-replace-regexp~) 2. Fix cases by select the region and ~M-x capitalize-dwim~ 3. Add number prefix with ~C-u C-x r N %d. RET~ (~rectangle-number-lines~) * [[http://www.vimgolf.com/challenges/50af864132b7ed0002000075][A simple change]] <2017-02-08 Wed> Edit as usual. * [[http://www.vimgolf.com/challenges/4d1a6bafb8cb34093200008e][Wrap the text of an email message to 79 characters]] <2017-02-08 Wed> 1. Change ~fill-column~ to 79 with ~C-x f~ (or ~M-x set-fill-column~) 2. Change ~fill-prefix~ to "> " with ~C-x .~ (or ~M-x set-fill-prefix~) 3. Fill with ~M-q~ (~fill-paragraph~) (need to go through step 2) * [[http://www.vimgolf.com/challenges/4f026d9b50582b000100002e][Replacing some words]] <2017-02-08 Wed> Pass (not very meaningful). * [[http://www.vimgolf.com/challenges/4dcd7b572c8e510001000005][Interweave two blocks of text]] <2017-02-08 Wed> 1. Make "one two ..." the same width 2. Copy and yank the numbers with ~C-w~ (~kill-region~) and ~C-x r y~ (~yank-rectangle~) * [[http://www.vimgolf.com/challenges/4d1ac1800a045132c0000011][Reformat a C golf submission]] <2017-02-08 Wed> Edit as usual. * [[http://www.vimgolf.com/challenges/4d1a6ed2b8cb3409320000c9][Add fold markers to a .c file]] <2017-02-08 Wed> Edit as usual or simply pass (makes no sense for Emacs). * [[http://www.vimgolf.com/challenges/4d1cc35a35b40650b800043a][Increment, increment, increment....]] <2017-02-08 Wed> Recoard the macro with ~M-1 F3 F3 RET F4~ and execute the macro repeatly. - ~M-1 F3~ to start recoarding and set keyboard macro counter to 1 (defaults to 0) - the second ~F3~ to insert the counter Notes that keyboard macro counter is incremented each time its value is inserted into the buffer. For more info, see [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Keyboard-Macro-Counter.html][(emacs) Keyboard Macro Counter]]. * [[http://www.vimgolf.com/challenges/4d1b76d9c58eaa2a8a000866][Context insensitive completion 0]] <2017-02-08 Wed> Pass (I don't understand the question and have no interest to find out). * [[http://www.vimgolf.com/challenges/4d1b3d57c58eaa2a8a000510][Sorting paragraphs]] <2017-02-08 Wed> ~M-x sort-paragraphs~ * [[https://vimgolf.com/challenges/53d1f9344ab5290002ab30e0][Subtraction]] <2017-02-08 Wed> Run ~C-M-%~ (~query-replace-regexp~) with the following arguments. #+BEGIN_SRC emacs-lisp ^\(x+\) - \(.+\) =$ => \1 - \2 = \,(make-string (- (length \1) (length \2)) ?x) #+END_SRC /Wow, being able to run arbitrary Lisp is really awesome./ * [[https://vimgolf.com/challenges/50be61aea748a30002000047][abcd > a b c d]] <2017-02-08 Wed> Replace one space with one tab via ~M-%~ (~query-replace~). * [[https://vimgolf.com/challenges/4ea9bc988b36f70001000008][Sort entries based on date]] <2017-02-08 Wed> Select the region and run the command: #+BEGIN_SRC emacs-lisp ;; Adapt from `sort-paragraphs' (defun sort-paragraphs-based-on-date (reverse beg end) (interactive "P\nr") (save-excursion (save-restriction (narrow-to-region beg end) (goto-char (point-min)) (sort-subr reverse (lambda () (while (and (not (eobp)) (looking-at paragraph-separate)) (forward-line 1))) #'forward-paragraph nil (lambda () (re-search-forward (rx (repeat 2 (in digit)) "." (repeat 2 (in digit)) "." (repeat 4 (in digit))))) (lambda (x y) (let ((s1 (buffer-substring (car x) (cdr x))) (s2 (buffer-substring (car y) (cdr y)))) (< (string-to-number (apply #'concat (nreverse (split-string s1 "\\.")))) (string-to-number (apply #'concat (nreverse (split-string s2 "\\."))))))))))) #+END_SRC /~sort-subr~ is simply amazing/ * [[https://vimgolf.com/challenges/513b1dcd2d1ae10002000010][Sort the VimGolf challenges by popularity]] <2017-02-08 Wed> 1. Remove unneeded lines with ~M-x delete-non-matching-lines~ 2. Sort lines with ~C-u -2 M-x sort-numeric-fields~ 3. Reverse lines with ~M-x reverse-region~ * [[https://vimgolf.com/challenges/52552abfb089a00002000007][Create Leading Zeros]] <2017-02-08 Wed> Run ~C-M-%~ (~query-replace-regexp~) with the following arguments. #+BEGIN_EXAMPLE ^[0-9]+ => \,(format "%04d" (string-to-number \&)) #+END_EXAMPLE * [[https://vimgolf.com/challenges/544bcdd93cafc700021ee30e][learn vim in short time]] <2017-02-08 Wed> Edit as usual. * [[https://vimgolf.com/challenges/55389fb1d6367c11201571d1][remove all lines in first part]] <2017-02-08 Wed> Make the region and type ~M-x delete-duplicate-lines~. * [[https://vimgolf.com/challenges/56e4fe988cf590220106e9bb][Fun With The Diagonal]] <2017-02-08 Wed> Record keyboard macro ~M-c C-n~ and run it for several times. * [[https://vimgolf.com/challenges/4d1e037dde2f897c2a000417][Reverse and count]] <2017-02-08 Wed> 1. Reverse with ~M-x reverse-region~ 2. Count with ~C-u C-x r N RET RET %d. RET~ * [[https://vimgolf.com/challenges/4d2478e20947c63e2600009c][Insert a Markdown link]] <2017-02-08 Wed> Do it manually or use feature provided by markdowm-mode (check the Menu Bar). * [[https://vimgolf.com/challenges/4d26f42298e8d72471000025][Generate English Alphabets]] <2017-02-08 Wed> #+BEGIN_SRC emacs-lisp (loop for i from ?a to ?z do (insert i ?\n)) #+END_SRC * [[https://vimgolf.com/challenges/4d34af20e747f561b3000081][Rotating Philosophers Problem]] <2017-02-09 Thu> Use Keyboard Macro. * [[https://vimgolf.com/challenges/4d1b9703c8bb5704eb000081][Hatsuyume]] <2017-02-09 Thu> Select the region and type ~C-u M-| nl -s ' ' -w 1 RET~ (~shell-command-on-region~). Notes that for nl(1) from GNU Coreutils: - ~-s STRING~ / ~--number-separator=STRING~ :: Separator - ~-w NUMBER~ :: ~--number-width=NUMBER~ :: Width * [[https://vimgolf.com/challenges/55054f0ac64edd79b00265ac][Interleave lines]] <2017-02-09 Thu> Kill-and-yank as usual. * [[https://vimgolf.com/challenges/54a480bb5db1600002939b54][increment by column in XML]] <2017-02-09 Thu> Run ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE @@@@@ => \,(number-to-string (+ 10000 \#)) #+END_EXAMPLE Notes that - ~\,~ starts a Lisp expression - ~\#~ means the number of replacements done so far (starting with 0) /query-replace-regexp is awesome/ * [[https://vimgolf.com/challenges/53cee5e1c5f4b4000208b285][Change name of a variable]] <2017-02-09 Thu> Edit as usual. * [[https://vimgolf.com/challenges/546a627195f6da000265742d][Pretty format for variable declarations]] <2017-02-09 Thu> ~M-x align-regexp RET = RET~ * [[https://vimgolf.com/challenges/50b5266f448d770002000106][Readable Rubyhash]] <2017-02-09 Thu> Use ~C-M-%~ (~query-replace-regexp~). * [[https://vimgolf.com/challenges/50d42c56dffb94000200000c][Enumerate words]] <2017-02-09 Thu> 1. Split text into lines with ~C-M-% [[:punct:] ] RET C-q C-j RET~ (~query-replace-regexp~) 2. Delete empty lines with ~M-x delete-matching-lines RET ^$~ 3. Capitalize lines by selecting the region and type ~M-x capitalize-dwim~ 4. Sort lines with ~M-x sort-lines~ * [[http://www.vimgolf.com/challenges/4d28637c4bcd032f1c00003d][Reformat long lines]] <2017-02-10 Fri> Edit normally. * [[http://www.vimgolf.com/challenges/4d1bfa8fb2c3e06468000127][Table Reshuffle]] <2017-02-10 Fri> Record keyboard macro. Note that 1. Use ~M-t~ (~transpose-words~) 2. Use ~C-M-w~ (~append-next-kill~) * [[http://www.vimgolf.com/challenges/51b4e3b920faf70002000001][Number an outline]] <2017-02-10 Fri> #+BEGIN_SRC emacs-lisp (defvar english-number-alist '((One . 1) (Two . 2) (Three . 3) (Four . 4) (Five . 5) (Six . 6))) #+END_SRC and run ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE [0-9]\. \(\w+\)$ => \,(format "%d. %s" (alist-get (intern \1) english-number-alist) \1) #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/4d1a7a05b8cb3409320001b4][Get rid of html tags]] <2017-02-10 Fri> Delete tags with ~C-M-% <.+?> RET RET~ (~query-replace-regexp~) * [[http://www.vimgolf.com/challenges/55e704665f560803fa000001][Assign numbers to fields]] <2017-02-10 Fri> ~C-M-% \w+ RET \#:\& RET~ (~query-replace-regexp~) * TODO [[http://www.vimgolf.com/challenges/556d7209f6d1a10ee6000001][swap or reverse]] <2017-02-10 Fri> * [[http://www.vimgolf.com/challenges/50f3c2d55c891f0002000002][Word frequency alignment]] <2017-02-10 Fri> ~M-x align-regexp RET [0-9] RET~ * [[http://www.vimgolf.com/challenges/53f388dfb2a65900028494ae][NBCU Weekly Challenge - #0]] <2017-02-10 Fri> Edit as usual. * [[http://www.vimgolf.com/challenges/4d1e93e825ba287b2a0000ed][The holy-grail may help]] <2017-02-10 Fri> Edit as usual. * [[http://www.vimgolf.com/challenges/54cb9296b2df9e000307809a][Winning streak]] <2017-02-10 Fri> Use ~C-x r N~ (~rectangle-number-lines~) and cut-and-paste the rectangle region. * [[https://vimgolf.com/challenges/50e32889d5e627000200000d][Change your calendar]] <2017-02-11 Sat> Delete the old and insert the new one via ~M-x calendar~. * [[https://vimgolf.com/challenges/4e5ec5851836e0000100003e][Alphabetize the directory]] <2017-02-11 Sat> Paste text into an Org buffer and sort headings with ~C-c ^~ (~org-sort~). * [[https://vimgolf.com/challenges/5486c522908f4600023c53fa][Test everything!]] <2017-02-11 Sat> Use keyboard macro as usual. * [[https://vimgolf.com/challenges/51cf1fae5e439e0002000001][Top X]] <2017-02-11 Sat> 1. Split into lines by replacing space into newline via ~M-%~ (~query-replace~) 2. Remove duplicates via ~M-x delete-duplicate-lines~ 3. Join lines by replaing newline into space via ~M-%~ (~query-replace~) * [[https://vimgolf.com/challenges/5598ef76c0132f45c9005238][Entries sort]] <2017-02-11 Sat> 1. Cut parts accros lines 2. Sort lines 3. Paste them back * [[https://vimgolf.com/challenges/512eda055d6ed80002000025][Parsing with CSV: Unify lines and result.]] <2017-02-11 Sat> Edit manually. * [[https://vimgolf.com/challenges/51cd1be19f3290000200000e][Assign list]] <2017-02-11 Sat> Use ~M-%~ (~query-replace~) and keyboard macro. * [[https://vimgolf.com/challenges/4d1c6d0535b40650b800017e][Compile C]] <2017-02-11 Sat> ~C-u M-! cc foo.c && ./a.out~ (~shell-command~) * [[https://vimgolf.com/challenges/5078889ceedfc90002000047][Python to Ruby]] <2017-02-11 Sat> Edit as usual. * [[https://vimgolf.com/challenges/4d1a87fcb8cb340932000290][Deleting folded text]] <2017-02-11 Sat> Select the region via isearch and delete text in the region, since it is not easy to build regexp for it. * [[https://vimgolf.com/challenges/4fe62f8a8b2f800001000043][Cleanining up 80 column concatenated text]] <2017-02-12 Sun> Cut-and-paste. Notes that use ~C-M-w~ (~append-next-kill~). * [[https://vimgolf.com/challenges/4d1be79bb2c3e064680000c6][Fix the Haiku]] <2017-02-12 Sun> Use ~M-c~ (~capitalize-word~) and ~C-x r t~ (~string-rectangle~). * [[https://vimgolf.com/challenges/56fcc3204a7725120c00c91c][SQL to YAML]] <2017-02-12 Sun> Pass (or use keyboard macro and maybe plus some manual edits). * [[https://vimgolf.com/challenges/4d1d0d5e35b40650b8000711][82 bottles of beer on the wall]] <2017-02-12 Sun> Duplicates the text 82 times and ~C-M-%~ (~query-replace-regexp~). * [[https://vimgolf.com/challenges/511991607729fb0002000003][Refactor arguments into object argument]] <2017-02-12 Sun> Pass (or edit manually). * [[https://vimgolf.com/challenges/4d1c27940e3d7832db000010][Prime Numbers]] <2017-02-12 Sun> #+BEGIN_SRC emacs-lisp (defun prime-numbers (until) (assert (> until 1)) (loop for n from 2 to until if (loop for i from 2 to (1- n) if (= 0 (% n i)) return nil finally return t) collect n)) (insert (mapconcat #'number-to-string (prime-numbers 542) "\n")) #+END_SRC * [[https://vimgolf.com/challenges/50c2c246b0544c000200003f][Block Fun 1]] <2017-02-12 Sun> Recoard keyboard macro which uses ~C-x r M-w~ (~copy-rectangle-as-kill~) and ~C-x r y~ (~yank-rectangle~). * [[https://vimgolf.com/challenges/54c392acbd7cbe0003329b7c][Separating firstname & lastname]] <2017-02-12 Sun> Type ~C-u M-x align-regexp~ with the following arguments: #+BEGIN_EXAMPLE \(\) -> RegExp 1 -> Group 1 6 -> 6 white spaces y -> Repeat (Don't not matter in this case) #+END_EXAMPLE * [[https://vimgolf.com/challenges/55faae943e9b67549b000001][Sudoku table]] <2017-02-12 Sun> Use Rectangle Region Mode heavily. * [[https://vimgolf.com/challenges/4d665abd7d73e02a55000009][Java Array2List]] <2017-02-12 Sun> Run ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE \([0-9.]+\),? ? => c.add(\1); #+END_EXAMPLE * [[https://vimgolf.com/challenges/543e53c037ba3a00022b3ec7][Winding path]] <2017-02-14 Tue> Edit manually (use keyboard macro if convenient) * [[https://vimgolf.com/challenges/5035e5b3838d9e000200006d][Dehamlizing]] <2017-02-14 Tue> Edit manually or use haml directly. * TODO [[https://vimgolf.com/challenges/4fe9ab8b5089660001000002][Shuffle and Sort]] <2017-02-14 Tue> * [[https://vimgolf.com/challenges/54fb143d91984a0e75007579][Fill visual area]] <2017-02-14 Tue> Pass. * [[https://vimgolf.com/challenges/5491377167afde00024ba4cf][Refactoring useless Method away]] <2017-02-14 Tue> Use keyboard macro. * [[https://vimgolf.com/challenges/4d1c5e6035b40650b8000111][Another Mixed-Up Haiku]] <2017-02-14 Tue> Use keyboard macro. * [[https://vimgolf.com/challenges/4d6f45b938c0aa691b000003][Recursively Palindrome]] <2017-02-14 Tue> Insert a ~a~ in a new line then run the following command for 5 times. #+BEGIN_SRC emacs-lisp (defun palindrome () "Palindrome current line." (interactive) (let* ((beg (line-beginning-position)) (end (line-end-position)) (line (buffer-substring beg end)) (next (1+ (nth (/ (1- (length line)) 2) (string-to-list line))))) (delete-region beg end) (insert (format "%s%c%s" line next line)))) #+END_SRC * [[https://vimgolf.com/challenges/4fdb12a383de630001000005][Aligning function arguments to match a specific coding style]] <2017-02-14 Tue> Run ~C-u M-x align-regexp~ with ~[^ ]\( \)[^ ]~. * [[https://vimgolf.com/challenges/5508d1ded05c5e2a710d7e93][Rail fence transposition cipher]] <2017-02-14 Tue> Pass. * [[https://vimgolf.com/challenges/4dab05bff1161c5a78000011][Sort the cardinal numbers]] <2017-02-14 Tue> Edit manually. * [[https://vimgolf.com/challenges/4db2c9272a007d1ee7000015][Complete the hex array data]] <2017-02-14 Tue> Use this code to insert the extra hex numbers #+BEGIN_SRC emacs-lisp (loop for i from #x10 to #xff for j from 1 do (insert (format "0x%02x, " i)) (when (zerop (% j 8)) (insert "\n"))) #+END_SRC * [[https://vimgolf.com/challenges/4d1eaf7225ba287b2a00018b][Generate Fibonacci Numbers]] <2017-02-14 Tue> Insert #+BEGIN_EXAMPLE 0 1 #+END_EXAMPLE and repeat this command for many times. #+BEGIN_SRC emacs-lisp (defun sum-prev-two-lines () (interactive) (let ((sum (save-excursion (let ((a (progn (forward-line -1) (number-at-point))) (b (progn (forward-line -1) (number-at-point)))) (+ a b))))) (insert (format "%d\n" sum)))) #+END_SRC * [[https://vimgolf.com/challenges/4fe354e8f73248000100002d][Inconsistent real estate paste]] <2017-02-14 Tue> Edit manually. * [[https://vimgolf.com/challenges/50d0c33daa503f000200000f][Groups magic]] <2017-02-14 Tue> Run ~C-M-%~ (~query-replace-regexp~) with #+BEGIN_EXAMPLE [^ ] => _ #+END_EXAMPLE * [[https://vimgolf.com/challenges/50d62c51162fd30002000052][REDRUM]] <2017-02-14 Tue> #+BEGIN_QUOTE REDRUM -reverse-> murder #+END_QUOTE Run ~C-M-%~ (~query-replace-regexp~) with #+BEGIN_EXAMPLE ^.*$ => \,(nreverse \&) #+END_EXAMPLE * [[https://vimgolf.com/challenges/4d23054b7f75b01e0700014a][It'ss tooo coold too typpe todaay]] <2017-02-14 Tue> Use ispell. * [[https://vimgolf.com/challenges/4f081a4ef037090001000074][constructor]] <2017-02-14 Tue> Pass. * [[https://vimgolf.com/challenges/532bdb79fbefce0002650940][Piphilology]] <2017-02-14 Tue> - Open Calc with ~C-x * *~ (~calc-dispatch~) - Change precision to 33 with ~p 33~ - Get the value of \pi{} with ~P~ * [[https://vimgolf.com/challenges/5501297312685a3ca601d3d8][Land of the Lost]] <2017-02-14 Tue> Pass. * [[https://vimgolf.com/challenges/4de6287b17a57a000100003f][formatted text to markdown]] <2017-02-14 Tue> Pass. * [[https://vimgolf.com/challenges/4d22bb117f75b01e070000fb][Cartesian product]] <2017-02-15 Wed> #+BEGIN_SRC emacs-lisp (dolist (i (number-sequence 1 5)) (dolist (j (number-sequence 1 5)) (insert (format "%d %d\n" i j)))) #+END_SRC * [[https://vimgolf.com/challenges/50f1b2e316e0bb0002000051][Circle in a square]] <2017-02-15 Wed> Pass. * [[https://vimgolf.com/challenges/4dddc7c1ed7380000100000d][Multiplication table.]] <2017-02-15 Wed> Run the following to insert the numbers #+BEGIN_SRC emacs-lisp (dolist (i (number-sequence 1 10)) (dolist (j (number-sequence 1 10)) (insert (format "%d " (* i j)))) (insert "\n")) #+END_SRC and align the result by calling ~C-u M-x align-regexp~ with the following argument: #+BEGIN_EXAMPLE \(\) 1 1 y #+END_EXAMPLE * [[https://vimgolf.com/challenges/4d1b78e281502541ad000009][Turn this csv list into queries]] <2017-02-15 Wed> Pass. (It might be uneasy to record a keyboard macro). * [[https://vimgolf.com/challenges/5054b8c6fa0b39000200001e][SFD-ROC: The Quick Brown Fox]] <2017-02-15 Wed> Pass. * [[https://vimgolf.com/challenges/530d2148f78def0002660c96][Write Setters and Getters for PHP]] <2017-02-15 Wed> Pass. * [[https://vimgolf.com/challenges/519cb48135fc71000200004a][Draw the Go board]] <2017-02-15 Wed> Use keyboard macros. * [[https://vimgolf.com/challenges/52bc9404cbab90000200001c][O Christmas Tree]] <2017-02-15 Wed> Pass. * [[https://vimgolf.com/challenges/51093f4c6db41b0002000003][Define to require]] <2017-02-15 Wed> Pass. * [[https://vimgolf.com/challenges/500855e60599d90002000073][Convert pandoc unordered list to a numbered list]] <2017-02-15 Wed> Run ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE ^\(\s-+\)\*\,(concat \1 (number-to-string (1+ \#))) #+END_EXAMPLE * [[https://vimgolf.com/challenges/4d1df910de2f897c2a0003c0][Almost encrypted]] <2017-02-16 Thu> #+BEGIN_SRC emacs-lisp (defun foo (char) (cond ((<= ?a char ?m) (+ 13 char)) ((<= ?n char ?z) (+ -13 char)) ((<= ?A char ?M) (+ 13 char)) ((<= ?N char ?Z) (+ -13 char)) (t char))) #+END_SRC * [[https://vimgolf.com/challenges/50ad2cb165b8db0002000029][Unwrap the text of an email message]] <2017-02-16 Thu> 1. Remove prefix 2. Join line with ~M-^~ (~delete-indentation~) or ~M-%~ (~query-replace~) * [[https://vimgolf.com/challenges/5054b935fa0b390002000020][SFD-ROC: Tic-Tac-Toe]] <2017-02-16 Thu> Edit manually. * [[https://vimgolf.com/challenges/53f44761ba79e3000235fc6f][Comparing scores]] <2017-02-16 Thu> Use ~sort-lines~ and ~sort-fields~. * [[https://vimgolf.com/challenges/55f9720b4a665c2acf0008c8][Lower cased and dashed strings]] <2017-02-16 Thu> Run ~C-M-%~ (~query-replace-regexp~) with ~^.$~ as search pattern and the following as replace pattern #+BEGIN_EXAMPLE (format "%s\n name: \"%s\"" (downcase (replace-regexp-in-string " " "-" \&)) \&) #+END_EXAMPLE * [[https://vimgolf.com/challenges/50b746da523acc0002000018][Checkerboard case pattern]] <2017-02-16 Thu> Use ~M-c~ (~capitalize-word~). * TODO [[https://vimgolf.com/challenges/541022801a2d8b0002238a17][Roman numerals]] <2017-02-16 Thu> * [[https://vimgolf.com/challenges/4d1aa1d9b8cb34093200039f][PEP8 Python Wrapping Comments and Code]] <2017-02-16 Thu> Use ~C-x f~ (~set-fill-column~) to change ~fill-column~. * [[https://vimgolf.com/challenges/4fe3d2c2f73248000100004b][Changing URL path in CSS]] <2017-02-16 Thu> Use ~C-M-%~ (~query-replace-regexp~). * [[https://vimgolf.com/challenges/4d2061daf1a3f252f4000087][Solve the Sokoban]] <2017-02-16 Thu> Pass. * [[http://www.vimgolf.com/challenges/5490a40f6571cc0002bc6920][Square numbers]] <2017-02-17 Fri> 1. Insert numbers with ~C-u C-x r N~ (~rectangle-number-lines~) 2. Squre with ~C-M-%~ (~query-replace-regexp~) #+BEGIN_EXAMPLE ^.*$\,(number-to-string (expt (string-to-number \&) 2)) #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/50b1517e9aad890002000004][Printable ASCII characters]] <2017-02-17 Fri> #+BEGIN_SRC emacs-lisp (loop for i from ?\s to ?~ do (insert (format "%c\n" i))) #+END_SRC * [[http://www.vimgolf.com/challenges/4fca76aad3a0d4000100007e][Calculate the table totals]] <2017-02-17 Fri> #+BEGIN_SRC org ,#+tblfm: $4=$2*$3;%.2f #+END_SRC * [[http://www.vimgolf.com/challenges/52409a089e26e1000200006d][Ninjas Leaderboard]] <2017-02-17 Fri> Pass. * [[http://www.vimgolf.com/challenges/4d2fb20e63b08b08b0000075][Overall Vimgolf Rank]] <2017-02-17 Fri> Run ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE - Rank: \([0-9]+\)/\,(progn (incf foo (string-to-number \1)) \&) #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/537a553282aa3e000222048a][HTML formatting: vertical alignment for readability]] <2017-02-17 Fri> Enable ~html-mode~ then mark the whole buffer and press ~TAB~. Adjust ~sgml-basic-offset~ to 4 if like. * [[http://www.vimgolf.com/challenges/4d247aa50947c63e260000a4][Happy New Year!]] <2017-02-17 Fri> Run ~C-M-%~ (~query-replace-regexp~) with the following #+BEGIN_EXAMPLE .\,(let ((c (string-to-char \&))) (format "<%c> %d, Hex %x, Octal %o\n" c c c c)) #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/4d22dcfa7f75b01e0700010e][Getters & Setters: Java]] <2017-02-17 Fri> Pass. * [[http://www.vimgolf.com/challenges/5054ba0cfa0b390002000023][SFD-ROC: Pipe Dreams]] <2017-02-17 Fri> Pass. * [[http://www.vimgolf.com/challenges/555b647e6337c25795003d2c][Tiny column alignment]] <2017-02-17 Fri> Pass. * [[http://www.vimgolf.com/challenges/4d28aef94bcd032f1c0000dc][The Universal Declaration of Human Rights, Article 1]] <2017-02-18 Sat> Pass. * [[http://www.vimgolf.com/challenges/51a115429bada1000200001b][paste indent correction - JS]] <2017-02-18 Sat> Use major-mode's feature to indent. * [[http://www.vimgolf.com/challenges/4dd3e19aec9eb6000100000d][Complete the hex array data (Part II)]] <2017-02-18 Sat> #+BEGIN_SRC emacs-lisp (loop for i from #x00 to #xFF do (insert (format "0x%x, " i)) when (zerop (% (1+ i) 8)) do (insert "\n")) #+END_SRC * [[http://www.vimgolf.com/challenges/4fbf8e303be58b0001000024][Format the output]] <2017-02-18 Sat> Pass. * [[http://www.vimgolf.com/challenges/55007a7412685a180e000005][Not enough Ps]] <2017-02-18 Sat> Replace "B" with "P" via ~M-%~ (~query-replace~). * [[http://www.vimgolf.com/challenges/4d1dfe2cde2f897c2a0003e3][Letters are numbers]] <2017-02-18 Sat> #+BEGIN_SRC emacs-lisp (mapconcat #'number-to-string (string-to-list "abc") "") #+END_SRC #+RESULTS: : 979899 * [[http://www.vimgolf.com/challenges/4d2482950947c63e260000b1][Word Blender]] <2017-02-18 Sat> Pass. * [[http://www.vimgolf.com/challenges/51459ef6b94aa50002000002][It's a factor]] <2017-02-18 Sat> #+BEGIN_SRC emacs-lisp (defun find-factors (number) (delete-dups (loop for i from 1 to number if (zerop (% number i)) collect i))) (find-factors 9) #+END_SRC #+RESULTS: | 1 | 3 | 9 | * [[http://www.vimgolf.com/challenges/54bd44d755bd48000310c6e0][Greek column realign]] <2017-02-18 Sat> Edit as qusual. * [[http://www.vimgolf.com/challenges/54a94976f4048c00026d8ed6][C to VimDict]] <2017-02-18 Sat> Pass. * [[http://www.vimgolf.com/challenges/50ef5caf767623000200004b][Execute immediate SQL]] <2017-02-19 Sun> Pass. * [[http://www.vimgolf.com/challenges/4d1ba304c8bb5704eb00012d][Linear congruential generator]] <2017-02-19 Sun> #+BEGIN_SRC emacs-lisp (defun insert-next () (interactive) (let* ((this (number-at-point)) (next (% (+ (* 25 this) 7) 48))) (goto-char (line-end-position)) (insert (format "\n%s" next)))) #+END_SRC * [[http://www.vimgolf.com/challenges/518360f3fa5db2000200001a][Lookahead and Lookbehind]] <2017-02-19 Sun> Pass. * [[http://www.vimgolf.com/challenges/5521ef575709ea270a00ce69][Remove hard line breaks]] <2017-02-19 Sun> - Set ~fill-column~ to a large number with ~C-x f~ (~set-fill-column~) - then fill with ~M-q~ (~fill-paragraph~) * [[http://www.vimgolf.com/challenges/4d1c7ee635b40650b8000203][Remove Accent off the Letter]] <2017-02-19 Sun> Pass. * [[http://www.vimgolf.com/challenges/548879e3844403000250b6aa][JSON string rotation]] <2017-02-19 Sun> Pass. * [[http://www.vimgolf.com/challenges/50b4b5e6448d77000200004d][Chucking wood]] <2017-02-19 Sun> Pass. * [[http://www.vimgolf.com/challenges/51e3f82a0754780002000078][Hanging Indent for Footnotes]] <2017-02-19 Sun> - Unfill - set fill-column/fill-prefix - fill - cleanup there is some better way, looks like change-log-mode has such function. * [[http://www.vimgolf.com/challenges/5054bb26fa0b39000200002b][SFD-ROC: ROT13 ]] <2017-02-19 Sun> Sort twice. * [[http://www.vimgolf.com/challenges/50128129201f450002000027][Complete the circuit grid!]] <2017-02-19 Sun> Pass. * [[http://www.vimgolf.com/challenges/50127eba201f450002000024][Make the circuit grid!]] <2017-02-22 Wed> Pass. * [[http://www.vimgolf.com/challenges/50d76e775539af000200006f][Transposition]] <2017-02-22 Wed> Use this ~foo~ to transpose the text, then use ~C-u M-x align-regexp~ to align. #+BEGIN_SRC emacs-lisp (defun chunyang-transpose (lists) "Return the transpose of a martrix LISTS. See URL `https://en.wikipedia.org/wiki/Transpose'." ;; NOTE assuming LISTS is a valid martrix (cl-loop for idx from 0 to (1- (length (car lists))) collect (cl-loop for lst in lists collect (nth idx lst)))) (defun lines-into-lists (beg end) (interactive "r") (let ((lines (split-string (buffer-substring beg end) "\n" ))) (delq nil (mapcar (lambda (line) (split-string line " " t)) lines)))) (defun insert-lists (lists) (loop for lst in lists do (insert (mapconcat #'identity lst " ") "\n"))) (defun foo () (interactive) (insert-lists (chunyang-transpose (call-interactively #'lines-into-lists)))) #+END_SRC * [[http://www.vimgolf.com/challenges/50ba20af5b346c0002000035][Python: Lots of function arguments]] <2017-02-22 Wed> ~M-q~ (~fill-paragraph~). * [[http://www.vimgolf.com/challenges/549fc5c05874e9000220eb54][Binary and Increment]] <2017-02-22 Wed> The function ~format~ supports hex and octal, but not binary. For now, I can use the following: #+BEGIN_SRC emacs-lisp (defun chunyang-format-as-binary (number) ;; FIXME: It might be better to calculate directly (let ((map '((?0 . "000") (?1 . "001") (?2 . "010") (?3 . "011") (?4 . "100") (?5 . "101") (?6 . "110") (?7 . "111")))) (replace-regexp-in-string "\\`0+" "" (mapconcat #'identity (mapcar (lambda (c) (cdr (assq c map))) (string-to-list (format "%o" number))) "")))) #+END_SRC * [[http://www.vimgolf.com/challenges/4e379f2fdfb67a000100002e][PHP <--> Java class conversion Part 2]] <2017-02-22 Wed> Pass. * [[http://www.vimgolf.com/challenges/5054ba5efa0b390002000026][SFD-ROC: ASCII Logo Border]] <2017-02-22 Wed> Pass. * [[http://www.vimgolf.com/challenges/502f2e628f37220002000031][Create an alphabet diamond]] <2017-02-22 Wed> Run the following to creeate the half, then use ~M-x reverse-region~ to create the rest. #+BEGIN_SRC emacs-lisp :exports both (cl-loop for char from ?Z downto ?A for text from 52 downto 2 by 2 for space from 0 concat (concat (make-string space ?\s) (make-string text char) "\n")) #+END_SRC #+RESULTS: #+begin_example ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV UUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR QQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQQ PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO NNNNNNNNNNNNNNNNNNNNNNNNNNNN MMMMMMMMMMMMMMMMMMMMMMMMMM LLLLLLLLLLLLLLLLLLLLLLLL KKKKKKKKKKKKKKKKKKKKKK JJJJJJJJJJJJJJJJJJJJ IIIIIIIIIIIIIIIIII HHHHHHHHHHHHHHHH GGGGGGGGGGGGGG FFFFFFFFFFFF EEEEEEEEEE DDDDDDDD CCCCCC BBBB AA #+end_example * [[http://www.vimgolf.com/challenges/50a1b172c654360002000033][Add links to an existing HTML table]] <2017-02-22 Wed> Pass. * [[http://www.vimgolf.com/challenges/4d29ae2107e0177c7e000036][Before there was Farmville...]] <2017-02-22 Wed> Pass. * [[http://www.vimgolf.com/challenges/5314fc4e6e902e00027b74d1][Five Pillars]] <2017-02-22 Wed> - Use ~C-M-%~ (~query-replace-regexp~) to delete punctuation characters ~\s.~. - Use keyboard macros to split text into lines - Use ~C-u M-x align-regexp RET \(\s-*\) RET 1 RET 0 RET y RET~ to align. * [[http://www.vimgolf.com/challenges/50525d0730c82d0002000077][Circle of Fifths with Sharps]] <2017-02-23 Thu> Use the same method as in Transposition. * [[http://www.vimgolf.com/challenges/50b375efd028d90002000050][Flip the chessboard]] <2017-02-23 Thu> Pass. * [[http://www.vimgolf.com/challenges/5301e83c0cb38c0002000008][Carriage return]] <2017-02-23 Thu> Pass. * [[http://www.vimgolf.com/challenges/50c13afab855760002000049][Harder than "abcd > a b c d"]] <2017-02-23 Thu> Run ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE \,(make-string (1+ \#) ? ) #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/54d5f51d20b05716be00036d][Sort with uniq OpenEmbedded package names]] <2017-02-23 Thu> Pass. * [[http://www.vimgolf.com/challenges/4d1da368de2f897c2a000114][Dumb to smart]] <2017-02-23 Thu> Do it manually. * TODO [[http://www.vimgolf.com/challenges/5039216a1eb07a0002000026][Sierpinski's Triangle]] <2017-02-23 Thu> * [[http://www.vimgolf.com/challenges/55b35f751b16ea1bc100a0e2][Maze path]] <2017-02-23 Thu> Pass. * [[http://www.vimgolf.com/challenges/50c195c1b85576000200005b][fib.c cleanup]] <2017-02-23 Thu> Pass. * [[http://www.vimgolf.com/challenges/4d2513c10947c63e2600019f][Here, piggy, piggy...]] <2017-02-23 Thu> Pass. * [[http://www.vimgolf.com/challenges/55250aff5eba2c043f0318f5][Merge blank lines and properly capitalize]] <2017-02-24 Fri> 1. Delete unwanted blank with ~C-x C-o~ (~delete-blank-lines~) or ~C-M-%~ (~query-replace-regexp~) 2. Capitalize manually * [[http://www.vimgolf.com/challenges/565bb80fceffe53baa038f0c][No naked if allowed!]] <2017-02-24 Fri> 1. Add one space after ~//~ with ~M-%~ (~query-replace~) 2. Move comment on its one line with ~C-u M-;~ (~comment-dwim~) and yank * [[http://www.vimgolf.com/challenges/56f8745e27bf6e0006010ec1][Convert pasted text into Markdown]] <2017-02-24 Fri> 1. Add one blank line with ~M-%~ (~query-replace~) 2. Fill qith ~M-q~ (~fill-paragraph~) * [[http://www.vimgolf.com/challenges/521df209452feb000200012d][Recursive Cowsay]] <2017-02-24 Fri> Pass. * [[http://www.vimgolf.com/challenges/5287aac7bba8eb0002000002][Permutations N=4]] <2017-02-24 Fri> #+BEGIN_SRC emacs-lisp (let ((l '(1 2 3 4)) result) (dolist (i l) (dolist (j (remove i l)) (dolist (k (remove j (remove i l))) (push (list i j k (car (remove k (remove j (remove i l))))) result)))) (dolist (list (nreverse result)) (insert (mapconcat #'number-to-string list "") ?\n))) #+END_SRC * [[http://www.vimgolf.com/challenges/54d6ed13bb73ec0688000001][50 factorials mod 97]] <2017-02-24 Fri> #+BEGIN_SRC emacs-lisp :exports both (loop for i from 1 to 50 collect (calc-eval (format "%d! %% 97" i))) #+END_SRC #+RESULTS: | 1 | 2 | 6 | 24 | 23 | 41 | 93 | 65 | 3 | 30 | 39 | 80 | 70 | 10 | 53 | 72 | 60 | 13 | 53 | 90 | 47 | 64 | 17 | 20 | 15 | 2 | 54 | 57 | 4 | 23 | 34 | 21 | 14 | 88 | 73 | 9 | 42 | 44 | 67 | 61 | 76 | 88 | 1 | 44 | 40 | 94 | 53 | 22 | 11 | 65 | * [[http://www.vimgolf.com/challenges/5474ef0bcf59b600024c64de][Config Sections]] <2017-02-25 Sat> #+BEGIN_SRC emacs-lisp (defun foo (beg end) (interactive "*r") (let ((s (delete-and-extract-region beg end))) (insert (make-string 30 ?#) "\n" (format "## %s ##" (s-center (- 30 6) s)) "\n" (make-string 30 ?#) "\n"))) #+END_SRC * [[http://www.vimgolf.com/challenges/50ed6ac0c0e3aa0002000003][Coordinates placeholder]] <2017-02-25 Sat> #+BEGIN_SRC emacs-lisp (while (search-forward "test" nil t) (message "%d,%d" (save-excursion (goto-char (match-beginning 0)) (1+ (current-column))) (line-number-at-pos))) #+END_SRC * [[http://www.vimgolf.com/challenges/5052dd5c2a8bfe000200001c][Enharmonic Equivalents]] <2017-02-25 Sat> Pass. * [[http://www.vimgolf.com/challenges/5014b2156318a4000200000b][Convert regular pandoc footnotes to in-line notes]] <2017-02-25 Sat> Pass. * [[http://www.vimgolf.com/challenges/547dae4372572300022c560e][Simple Maths]] <2017-02-25 Sat> Pass. * [[http://www.vimgolf.com/challenges/4d22038df74d0b11490000fb][Return the cow]] <2017-02-25 Sat> #+BEGIN_SRC emacs-lisp (defun return-the-cow (beg end) (interactive "*r") (let* ((s (delete-and-extract-region beg end)) (s (apply #'string (mapcar (lambda (c) (cl-case c (?\\ ?/) (?/ ?\\) (?\( ?\)) (?\) ?\() (t c))) (string-to-list s)))) (lines (split-string s "\n")) (max (apply #'max (mapcar #'length lines)))) (insert (mapconcat #'identity (mapcar (lambda (line) (nreverse (format (format "%%-%ds" max) line))) lines) "\n")))) #+END_SRC * [[http://www.vimgolf.com/challenges/50a9cedcf54bf60002000028][Sort by sum of numbers in a line(?)]] <2017-02-25 Sat> Use ~sort-numeric-fields~. * [[http://www.vimgolf.com/challenges/4f6144f46938f20001000061][un-C-escape string]] <2017-02-26 Sun> Use ~M-%~ (~query-replace~). * [[http://www.vimgolf.com/challenges/55ff7ea45a2b52043e06dee2][Forgot to follow the naming convention...]] <2017-02-26 Sun> Use the following to do it one by one or simply use ~C-M-%~ (~query-replace-regexp~). #+BEGIN_SRC emacs-lisp (defun foo () (interactive) (cl-destructuring-bind (beg . end) (bounds-of-thing-at-point 'symbol) (capitalize-region beg end) (replace-string "_" "" nil beg end))) #+END_SRC * [[http://www.vimgolf.com/challenges/52232097e52582000200002c][Untangle my tail, please!]] <2017-02-26 Sun> Pass. * [[http://www.vimgolf.com/challenges/51bd468414b59a0002000012][Across-Down Flip]] <2017-02-26 Sun> Pass. * [[http://www.vimgolf.com/challenges/5223a618e52582000200005c][Under the cupola]] <2017-02-26 Sun> #+BEGIN_SRC emacs-lisp (defun foo () (interactive) (let* ((text "The pink stars are falling in lines") (words (split-string text " ")) (max (apply #'max (mapcar #'length words))) (words (mapcar (lambda (s) (substring (concat s (make-string max ?\s)) 0 max)) words)) (lists (mapcar #'string-to-list words))) (insert (mapconcat #'identity (mapcar (lambda (l) (mapconcat #'string l " ")) (chunyang-transpose lists)) "\n")))) #+END_SRC * [[http://www.vimgolf.com/challenges/51330725b051320002000042][Extended Customer 2]] <2017-02-26 Sun> Pass. * [[http://www.vimgolf.com/challenges/50ea3ca82bf6290002000040][XML to JSON]] <2017-02-27 Mon> Pass. * [[http://www.vimgolf.com/challenges/50ab5251aeb26e0002000033][Sort by your own sum]] <2017-02-27 Mon> #+BEGIN_SRC emacs-lisp (defun foo (beg end) (interactive "r") (save-excursion (save-restriction (narrow-to-region beg end) (goto-char (point-min)) (sort-subr t 'forward-line 'end-of-line nil nil (lambda (x y) (let ((s1 (buffer-substring (car x) (cdr x))) (s2 (buffer-substring (car y) (cdr y)))) (< (string-to-number (calc-eval s1)) (string-to-number (calc-eval s2))))))))) #+END_SRC * [[http://www.vimgolf.com/challenges/50406e76badccf000200003b][maximun and minimun]] <2017-02-27 Mon> Use keyboard macro to run this command on every line then align the result with ~M-x align-regexp~. #+BEGIN_SRC emacs-lisp (defun foo () (interactive) (let* ((line (buffer-substring (line-beginning-position) (line-end-position))) (list (append (read (replace-regexp-in-string "," "" line)) nil)) (min (apply #'min list)) (max (apply #'max list))) (goto-char (line-end-position)) (insert (format " %s <> %s" min max)))) #+END_SRC * [[http://www.vimgolf.com/challenges/50d8b2039d73b70002000046][Greek Letters]] <2017-02-27 Mon> #+NAME: greek letters | alpha | Α | α | | beta | Β | β | | gamma | Γ | γ | | delta | Δ | δ | | epsilon | Ε | ε | | zeta | Ζ | ζ | | eta | Η | η | | theta | Θ | θ | | iota | Ι | ι | | kappa | Κ | κ | | lambda | Λ | λ | | mu | Μ | μ | | nu | Ν | ν | | ksi | Ξ | ξ | | omicron | Ο | ο | | pi | Π | π | | rho | Ρ | ρ | | sigma | Σ | σ | | tau | Τ | τ | | upsilon | Υ | υ | | phї | Φ | φ | | chi | Χ | χ | | psi | Ψ | ψ | | omega | Ω | ω | Pass. * [[http://www.vimgolf.com/challenges/50a2bdd4f0ea8a0002000055][Presidential Sorting]] <2017-02-27 Mon> Use ~align-regexp~. * [[http://www.vimgolf.com/challenges/55213dc25709ea0851015904][Custom McCarthy sequence]] <2017-02-27 Mon> Notes that ~m91~ in the following is standard, I am ignoring the question. #+BEGIN_SRC emacs-lisp :exports both (defun m91 (n) (cond ((<= n 100) (m91 (m91 (+ n 11)))) (t (- n 10)))) (loop for i from 1 to 120 collect (m91 i)) #+END_SRC #+RESULTS: | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | * [[http://www.vimgolf.com/challenges/5123331bb2bc340002000003][Fibonacci Triangles]] <2017-02-27 Mon> Pass. * [[http://www.vimgolf.com/challenges/510a052c6db41b0002000028][LaTeX to XML Math Delimiters]] <2017-02-27 Mon> Use ~C-M-%~ (~query-replace-regexp~), I think. * [[http://www.vimgolf.com/challenges/54a5b367b5be62000263f9ef][range(10) digit rotation]] <2017-02-27 Mon> #+BEGIN_SRC emacs-lisp :exports both (loop with nums = (number-sequence 0 9) for i from 0 to 9 collect (-replace 5 '* (-rotate (- i) nums))) #+END_SRC #+RESULTS: | 0 | 1 | 2 | 3 | 4 | * | 6 | 7 | 8 | 9 | | 1 | 2 | 3 | 4 | * | 6 | 7 | 8 | 9 | 0 | | 2 | 3 | 4 | * | 6 | 7 | 8 | 9 | 0 | 1 | | 3 | 4 | * | 6 | 7 | 8 | 9 | 0 | 1 | 2 | | 4 | * | 6 | 7 | 8 | 9 | 0 | 1 | 2 | 3 | | * | 6 | 7 | 8 | 9 | 0 | 1 | 2 | 3 | 4 | | 6 | 7 | 8 | 9 | 0 | 1 | 2 | 3 | 4 | * | | 7 | 8 | 9 | 0 | 1 | 2 | 3 | 4 | * | 6 | | 8 | 9 | 0 | 1 | 2 | 3 | 4 | * | 6 | 7 | | 9 | 0 | 1 | 2 | 3 | 4 | * | 6 | 7 | 8 | * [[http://www.vimgolf.com/challenges/511d618c094242000200001a][199 Fibonacci Numbers]] <2017-02-28 Tue> Use Calc. * [[http://www.vimgolf.com/challenges/548c6254c3fe990002bb28f7][Hail to Alekseï Pajitnov]] <2017-02-28 Tue> Pass. * [[http://www.vimgolf.com/challenges/542c8cb02da21600022c7477][Acute accents]] <2017-02-28 Tue> Pass. * [[http://www.vimgolf.com/challenges/4e7dedb4f447090001000002][Refactor to Helpers]] <2017-02-28 Tue> Pass. * [[http://www.vimgolf.com/challenges/51a388ac06f7d20002000006][Change The Perspective]] <2017-02-28 Tue> Pass. * [[http://www.vimgolf.com/challenges/54f8cc2718a13f0a630041e5][Conway sequence]] <2017-03-01 Wed> #+BEGIN_SRC emacs-lisp (defun look-and-say (number) "Return the next to NUMBER (a string). See URL `http://en.wikipedia.org/wiki/Look-and-say_sequence'." (let ((s number) (pos 0) char match (result "")) (while (< pos (length s)) (setq char (elt s pos)) (setq re (rx-to-string `(1+ ,char))) (string-match re s pos) (setq match (match-string 0 s)) (setq result (concat result (format "%d%c" (length match) char))) (incf pos (length match))) result)) (look-and-say "111221") #+END_SRC #+RESULTS: : 312211 * [[http://www.vimgolf.com/challenges/55b18bbea9c2c30d04000001][Simple, Practical, and Common]] <2017-03-01 Wed> Pass. * [[http://www.vimgolf.com/challenges/57d7d06d9ce5640f6f000001][Every other line]] <2017-03-01 Wed> Pass. * [[http://www.vimgolf.com/challenges/4d1a34ccfa85f32065000004][Simple text editing with Vim]] <2017-03-01 Wed> Pass. * [[http://www.vimgolf.com/challenges/587cab5a0740c90006000006][Combines all items]] <2017-03-01 Wed> - Sort lines - Delete unneeded leading numbers - Join lines * [[http://www.vimgolf.com/challenges/58753af0f5ef5c0006000006][Change attribute to getter]] <2017-03-01 Wed> Run ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE \.\(\w+\) → \,(format ".get('%s')" \&) #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/58860440c57fb30006000004][Extract HTML option values from tag values]] <2017-03-01 Wed> Pass. * [[http://www.vimgolf.com/challenges/587e0a9d5944680006000007][Turn a ninja to case-insensitive {Nn}{Ii}{Nn}{Jj}{Aa} regexp!]] <2017-03-01 Wed> #+BEGIN_SRC emacs-lisp (loop for c in (string-to-list "SarCastic") concat (format "[%c%c]" (upcase c) (downcase c))) #+END_SRC #+RESULTS: : [Ss][Aa][Rr][Cc][Aa][Ss][Tt][Ii][Cc] * [[http://www.vimgolf.com/challenges/56421fb1603ec626ec000003][Angular naming conventions]] <2017-03-01 Wed> #+BEGIN_SRC emacs-lisp (let ((case-fold-search nil)) (replace-regexp-in-string "[A-Z]" (lambda (s) (concat "-" (downcase s))) "greatDanesAreMyFriends" t)) #+END_SRC #+RESULTS: : great-danes-are-my-friends * [[http://www.vimgolf.com/challenges/5796493277f1fc12b1002044][Array of characters]] <2017-03-01 Wed> Use ~M-%~ (~query-replace~) and ~C-M-%~ (~query-replace-regexp~). * [[http://www.vimgolf.com/challenges/56eb0843251cf25ae40963de][underscore_to_camelCase]] <2017-03-01 Wed> Use ~C-M-%~ (~query-replace-regexp~). * [[http://www.vimgolf.com/challenges/56704157109fb85a6d017d08][FoodCritic023: Prefer conditional attributes]] <2017-03-01 Wed> Pass. * [[http://www.vimgolf.com/challenges/4fca701fd3a0d40001000074][Remove noise from HTTP log]] <2017-03-01 Wed> Use ~C-M-%~ (~query-replace-regexp~). * [[http://www.vimgolf.com/challenges/4d1a522ea860b7447200010b][Braces or Brackets?]] <2017-03-02 Thu> Try [[https://github.com/Fuco1/smartparens][Fuco1/smartparens: Minor mode for Emacs that deals with parens pairs and tries to be smart about it.]] * [[http://www.vimgolf.com/challenges/4d1a71c0b8cb34093200010b][Remember FizzBuzz?]] <2017-03-02 Thu> #+BEGIN_QUOTE Output FizzBuzz to 100. Start with nothing. #+END_QUOTE #+BEGIN_SRC emacs-lisp :exports both (loop for i from 1 to 100 collect (cond ((zerop (% i 15)) (format "%d FizzBuzz" i)) ((zerop (% i 3)) (format "%d Fizz" i)) ((zerop (% i 5)) (format "%d Buzz" i)) (t (format "%d" i)))) #+END_SRC #+RESULTS: | 1 | 2 | 3 Fizz | 4 | 5 Buzz | 6 Fizz | 7 | 8 | 9 Fizz | 10 Buzz | 11 | 12 Fizz | 13 | 14 | 15 FizzBuzz | 16 | 17 | 18 Fizz | 19 | 20 Buzz | 21 Fizz | 22 | 23 | 24 Fizz | 25 Buzz | 26 | 27 Fizz | 28 | 29 | 30 FizzBuzz | 31 | 32 | 33 Fizz | 34 | 35 Buzz | 36 Fizz | 37 | 38 | 39 Fizz | 40 Buzz | 41 | 42 Fizz | 43 | 44 | 45 FizzBuzz | 46 | 47 | 48 Fizz | 49 | 50 Buzz | 51 Fizz | 52 | 53 | 54 Fizz | 55 Buzz | 56 | 57 Fizz | 58 | 59 | 60 FizzBuzz | 61 | 62 | 63 Fizz | 64 | 65 Buzz | 66 Fizz | 67 | 68 | 69 Fizz | 70 Buzz | 71 | 72 Fizz | 73 | 74 | 75 FizzBuzz | 76 | 77 | 78 Fizz | 79 | 80 Buzz | 81 Fizz | 82 | 83 | 84 Fizz | 85 Buzz | 86 | 87 Fizz | 88 | 89 | 90 FizzBuzz | 91 | 92 | 93 Fizz | 94 | 95 Buzz | 96 Fizz | 97 | 98 | 99 Fizz | 100 Buzz | * [[http://www.vimgolf.com/challenges/4d1ace6c142cca7133000033][Reformat some Python]] <2017-03-02 Thu> Edit normally. * [[http://www.vimgolf.com/challenges/4d1b4ac3c58eaa2a8a0005c2][Ruby 1.9 compat]] <2017-03-02 Thu> Use ~M-%~ (~query-replace~). * [[http://www.vimgolf.com/challenges/4d1b795a81502541ad00000f][Context Insensitive completion 1]] <2017-03-02 Thu> The completion works like expected out of box in Emacs. * [[http://www.vimgolf.com/challenges/4d1bdde3b2c3e0646800007f][Indentation]] <2017-03-02 Thu> Edit normally. * [[http://www.vimgolf.com/challenges/4d1bfc7ab2c3e06468000137][Round Round]] <2017-03-02 Thu> Pass. * [[http://www.vimgolf.com/challenges/4d1ed78425ba287b2a000227][CSV to JSON]] <2017-03-02 Thu> Pass. * [[http://www.vimgolf.com/challenges/4d42cde1e6dc010cb7000024][expand a list comprehension (python)]] <2017-03-02 Thu> Pass. * [[http://www.vimgolf.com/challenges/4db0b1c8e8eb0f564b00001c][Case preserving word replacement]] <2017-03-02 Thu> ~M-%~ (~query-replace~) works out of box. * [[http://www.vimgolf.com/challenges/4ddbd92898957e0001000016][Line Zipper]] <2017-03-02 Thu> Use ~C-x r M-w~ (~copy-rectangle-as-kill~) and ~C-x r y~ (~yank-rectangle~), then ~C-M-%~ (~query-replace-regexp~). * [[http://www.vimgolf.com/challenges/4e31627b74ab580001000007][PHP <--> Java class conversion Part 1]] <2017-03-02 Thu> Pass. * [[http://www.vimgolf.com/challenges/4e9edef5cef4c50001000007][PHP Array Syntax -> MailChimp Merge Syntax]] <2017-03-02 Thu> Use ~M-%~ (~query-replace~). * [[http://www.vimgolf.com/challenges/4f2be242779cbc000100000c][Ugly spreadsheet copy/paste to CSV]] <2017-03-02 Thu> Use ~C-x SPC~ (~rectangle-mark-mode~), ~C-x r M-w~ (~copy-rectangle-as-kill~) and ~C-x r y~ (~yank-rectangle~), then add comma with ~C-M-%~ (~query-replace-regexp~). * [[http://www.vimgolf.com/challenges/4fa085222037000001000045][Reverse and double space]] <2017-03-03 Fri> ~M-x reverse-region~ then add one extra newline per line by replacing one newline with two newlines via ~M-%~ (~query-replace~). * [[http://www.vimgolf.com/challenges/4fca29ddd3a0d40001000038][Remove semicolons after expressions]] <2017-03-03 Fri> Delete unwanted semicolons with ~M-%~ (~query-replace~). * [[http://www.vimgolf.com/challenges/4fcccb70024f950001000026][Switch function arguments]] <2017-03-03 Fri> Use ~C-M-t~ (~transpose-sexps~). * [[http://www.vimgolf.com/challenges/4fcd8dc2ff37f20001000020][Create a pandoc compatible table]] <2017-03-03 Fri> Edit as usual. * [[http://www.vimgolf.com/challenges/4fe9ab8b5089660001000002][Shuffle and Sort]] <2017-03-03 Fri> #+BEGIN_SRC emacs-lisp (defun shuffle () (declare (interactive-only t)) (interactive) (let ((str (buffer-substring (line-beginning-position) (line-end-position)))) (delete-region (line-beginning-position) (line-end-position)) (insert (mapconcat #'identity (-rotate -1 (split-string str ",")) ",")))) #+END_SRC * [[http://www.vimgolf.com/challenges/50048db8cdc4060002000004][Vertical Limit]] <2017-03-03 Fri> Enable ~electric-pair-mode~ and use keyboard macro. * [[http://www.vimgolf.com/challenges/5039216a1eb07a0002000026][Sierpinski's Triangle]] <2017-03-03 Fri> Pass. * [[http://www.vimgolf.com/challenges/504e43017890650002000019][The Quick Brown Fox Jumps Over The Lazy Vim]] <2017-03-03 Fri> Pass. * [[http://www.vimgolf.com/challenges/505cb13a52512d000200002b][you're stuck on jQuery < 1.7]] <2017-03-03 Fri> Use ~C-M-%~ (~query-replace-regexp~). * [[http://www.vimgolf.com/challenges/50b1d7239aad89000200002d][Extract text from xml]] <2017-03-03 Fri> Edit as usual. * [[http://www.vimgolf.com/challenges/51dfe1d12b2f6d0002000046][Delete unwanted lines]] <2017-03-03 Fri> ~M-x delete-non-matching-lines~. * [[http://www.vimgolf.com/challenges/51ed21c65b7a9c0002000012][Counting in binary]] <2017-03-03 Fri> #+BEGIN_SRC emacs-lisp :exports both (defun number-to-binary (num) ;; num is less than 16 (let (res) (while (/= 0 (/ num 2)) (push (% num 2) res) (setq num (/ num 2))) (push num res) (let ((s (mapconcat #'number-to-string res ""))) ;; Make sure width is 4 (replace-regexp-in-string "1" "A" (replace-regexp-in-string "0" "a" (concat (make-string (- 4 (length s)) ?0) s)))))) (loop for i from 0 to 15 collect (number-to-binary i)) #+END_SRC #+RESULTS: | aaaa | aaaA | aaAa | aaAA | aAaa | aAaA | aAAa | aAAA | Aaaa | AaaA | AaAa | AaAA | AAaa | AAaA | AAAa | AAAA | * [[http://www.vimgolf.com/challenges/52222f6ea98cbe0002000078][Letter case trickery]] <2017-03-04 Sat> Edit as usual. * [[http://www.vimgolf.com/challenges/524e1a20b81fe50002000008][attr_aligner]] <2017-03-04 Sat> Use ~M-%~ (~query-replace~) and ~TAB~ (~indent-for-tab-command~). * [[http://www.vimgolf.com/challenges/5293b3574f09ff0002000033][Going underground....]] <2017-03-04 Sat> Pass. * [[http://www.vimgolf.com/challenges/53159f5d33b3f800023aa880][Vim tetris]] <2017-03-04 Sat> Pass. * [[http://www.vimgolf.com/challenges/53bddd87dbd3db0002c48c0f][Neither Fizz nor Buzz]] <2017-03-04 Sat> Type ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE 0 → \,(format "%d" (line-number-at-pos)) #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/53eac8a559e21500021ee41b][NBCU Weekly Challenge - Test]] <2017-03-04 Sat> Edit as usual. * [[http://www.vimgolf.com/challenges/54180e031079d30002383ee5][vim1001]] <2017-03-04 Sat> #+BEGIN_SRC emacs-lisp :exports both (loop repeat 5 for x from 1001 by 10 for y from 1005 by 10 collect (list x y)) #+END_SRC #+RESULTS: | 1001 | 1005 | | 1011 | 1015 | | 1021 | 1025 | | 1031 | 1035 | | 1041 | 1045 | * [[http://www.vimgolf.com/challenges/542eff6588fc4d00021aa9cd][Refactor static member invocation]] <2017-03-04 Sat> Pass. * [[http://www.vimgolf.com/challenges/54514fd7238fe900021e7c42][Shift down]] <2017-03-04 Sat> Use the following command to insert the new but also preserve indent. #+BEGIN_SRC emacs-lisp (defun chunyang-newline-keep-indent () (declare (interactive-only t)) (interactive) (insert (format "\n%s" (make-string (current-column) ?\s)))) #+END_SRC *Update* or simply use ~C-M-o~ (~split-line~). * [[http://www.vimgolf.com/challenges/545baafb7974800002353443][Replace Parameter with Explicit Methods]] <2017-03-04 Sat> Pass. * [[http://www.vimgolf.com/challenges/54aa4898e87aa400023e3a19][Wget failed to download redirections]] <2017-03-04 Sat> Make the whole buffer then type ~M-| grep --only-matching https://.*$~ (~shell-command-on-region~). * [[http://www.vimgolf.com/challenges/54e2169fb89efb2ab10012e6][Sorting database text output]] <2017-03-04 Sat> - Use ~C-x SPC~ (~rectangle-mark-mode~) to remove unwanted words - Use ~M-%~ (~query-replace~) to remove unwanted spaces - Use ~sort-numeric-fields~ to sort lines as numbers - Use ~delete-duplicate-lines~ to delete duplicates - Use ~M-^~ (~org-delete-indentation~) and keyboard macro to join lines - Use ~M-%~ (~query-replace~) to add commas. * [[http://www.vimgolf.com/challenges/5518cd2bfb03aa1d9402a6a3][Fix the XML]] <2017-03-04 Sat> Turn on ~xml-mode~ then issue ~C-c /~ (~nxml-finish-element~) to fix the tags. * [[http://www.vimgolf.com/challenges/558aef9a9b964426b5010562][Restore order to the alphabet]] <2017-03-04 Sat> Run ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE [a-z] → \,(char-to-string (+ ?a \#)) #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/55926044bbcb9851bc000001][Mirror Symmetry]] <2017-03-05 Sun> Use ~M-% / RET \/ RET~ (~query-replace~). * [[http://www.vimgolf.com/challenges/559e6360b6f8bd0f17010b61][Make HTML List]] <2017-03-05 Sun> Pass. * [[http://www.vimgolf.com/challenges/563368fc3a2bb61edd0128f5][Manual SQL]] <2017-03-05 Sun> Pass. * [[http://www.vimgolf.com/challenges/5666943bac55c907fd02066f][comments galore]] <2017-03-05 Sun> Use ~C-x SPC~ (~rectangle-mark-mode~) and ~C-x r t~ (~string-rectangle~). * [[http://www.vimgolf.com/challenges/5675405ac5936f0ba3000002][Create bison tokens]] <2017-03-05 Sun> Pass. * [[http://www.vimgolf.com/challenges/56add9a16518ef02c001af3d][Alsa configuration]] <2017-03-05 Sun> Pass. * [[http://www.vimgolf.com/challenges/56e36925d64dfc4d28000001][Inner hyphens]] <2017-03-05 Sun> Use ~C-M-%~ (~query-replace-regexp~) with the following arguments #+BEGIN_EXAMPLE . → \&- #+END_EXAMPLE * [[http://www.vimgolf.com/challenges/56e59ff88cf5905fe501ce5b][ASCII Art]] <2017-03-05 Sun> Use copy-and-paste and ~M-x reverse-region~ to create the half part. * [[http://www.vimgolf.com/challenges/571028960c64c90990000003][From A to B]] <2017-03-05 Sun> - Use ~M-%~ (~query-replace~) to replace ~A~ with ~B~ then ~a~ with ~b~. - Use ~M-%~ (~query-replace~) wot remove unwanted text - Use ~M-x reverse-region~ * [[http://www.vimgolf.com/challenges/57786c012ec4a10d2e000001][Wrap text in quotes]] <2017-03-05 Sun> Use ~M-h~ (~mark-paragraph~) and enter double quote (Also make sure ~electric-pair-mode~ is on). * [[http://www.vimgolf.com/challenges/57959f8a083a7e0c45000001][Paragraph sort]] <2017-03-05 Sun> Mark paragraph with ~M-h~ (~mark-paragraph~) then hit ~M-x sort-lines~. * [[http://www.vimgolf.com/challenges/57a4ec036f04c40bf8000001][ascii-art diamond]] <2017-03-05 Sun> Pass. * [[http://www.vimgolf.com/challenges/57ab8b6f621d160fcd000001][C Reformatting]] <2017-03-05 Sun> Pass. * [[http://www.vimgolf.com/challenges/57cf3e398c660c1f8f014717][Paragraph breaks]] <2017-03-05 Sun> Pass. * [[http://www.vimgolf.com/challenges/57fbb753ab6108077204f440][7th Birthday]] <2017-03-05 Sun> Pass. * [[http://www.vimgolf.com/challenges/5853f052854f48716101cc70][replace 2nd column blanks with values in same column if blank]] <2017-03-05 Sun> Pass. #+BEGIN_SRC emacs-lisp (defun chunyang-browse-vimgolf (id) (interactive (list ;; Delete the diff leading char '+' if any (replace-regexp-in-string "^\+" "" (buffer-substring (line-beginning-position) (line-end-position))))) (browse-url (format "http://www.vimgolf.com/challenges/%s" id))) #+END_SRC