Skip to content

Instantly share code, notes, and snippets.

View draegtun's full-sized avatar

Barry Walsh draegtun

View GitHub Profile
@draegtun
draegtun / challenge-304-accounts.reb
Created March 1, 2017 16:19
Reddit DailyProgrammer - "Little Accountant"
Rebol [
see: https://www.reddit.com/r/dailyprogrammer/comments/5wnbsi/20170228_challenge_304_easy_little_accountant/
]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Helper functions
tie: function [s delim /string] [
s: next s
forskip s 2 [insert s delim]
Rebol [
see: https://www.reddit.com/r/dailyprogrammer/comments/5go843/20161205_challenge_294_easy_rack_management_1/
]
scrabble: function [rack word] [
rack: reverse sort copy rack
score: 0
score-and-remove: func [s] [
score: score + score-letter s/1
@draegtun
draegtun / door.reb
Created March 30, 2016 18:39
Door challenge in Rebol
Rebol [
see: https://www.reddit.com/r/dailyprogrammer/comments/4cb7eh/20160328_challenge_260_easy_garage_door_opener/
]
states: [
'CLOSED [click: 'OPENING blocked: '*CLOSED]
'OPENING [click: 'STOPPED_WHILE_OPENING complete: 'OPEN blocked: '*OPENING]
'OPEN [click: 'CLOSING blocked: 'OPEN_BLOCKED]
'CLOSING [click: 'STOPPED_WHILE_CLOSING complete: 'CLOSED blocked: 'EMERGENCY_OPENING]
'STOPPED_WHILE_OPENING [click: 'CLOSING blocked: '*STOPPED_WHILE_OPENING]
@draegtun
draegtun / cheryls-birthday.reb
Last active August 29, 2015 14:22
Direct port of Norvig's "When is Cheryl's birthday?"
Rebol [
Title: {Direct port of Norvig's "When is Cheryl's birthday?"}
see: http://nbviewer.ipython.org/url/norvig.com/ipython/Cheryl.ipynb
version: 1.0.0 ; short & sweet version (no function docs or optional dates)
]
filter: function [f s] [
collect [foreach n s [if f n [keep n]]]
]
@draegtun
draegtun / json-csv-challenge.reb
Last active August 29, 2015 14:20
JSON -> CSV challenge
Rebol [
see: https://gist.github.com/jorin-vogel/2e43ffa981a97bc17259
version: 0.0.3
]
import http://reb4.me/r3/altjson
json: load-json https://gist.githubusercontent.com/jorin-vogel/7f19ce95a9a842956358/raw/e319340c2f6
file: to-file format/pad [-4 -2 -2] reduce [now/year now/month now/day ".csv"] 0
csv: open/write file
Rebol [
see: http://codegolf.stackexchange.com/a/34337/11021
]
c: complement charset "<>"
f: func [s n] [
w: none
tag-level: 0
trigger: does [n <= 0]
@draegtun
draegtun / reverse-words.reb
Created May 11, 2014 19:39
Reverse Words in a string - "Potential answer to SO CodeGolf challenge"
Rebol []
reverse-words: function [
"Reverse the order of words. Modifies and returns string (series)"
series [string!] "At position (modified)"
][
first-time: on
until [
f: any [
if first-time [tail series]
@draegtun
draegtun / date.r3
Created March 4, 2014 14:13
ISO week date conversions in Rebol
Rebol []
; see - http://codegolf.stackexchange.com/questions/22268/convert-calendar-dates-to-week-dates-and-vice-versa
;
; Grrr.. question now doesn't allow languages that use date/time operators :(
; So here the beginning is my (not golfed) version prior to the change! :)
;
; 28-Feb-2014
to-iso-week: func [date [date!] /local week-day last-year? week-in-year?] [
@draegtun
draegtun / comma1.r3
Created January 15, 2014 15:48
Some comma quibbling in Rebol
Rebol []
comma-quibbling: func [block] [
rejoin [
"^{"
to-string use [s] [
s: copy block
s: next s
forskip s 2 [insert s either tail? next s [" and "] [", "]]
@draegtun
draegtun / rebocalc.rebol
Created November 13, 2013 19:05
Spreadsheet in Rebol2 by Carl Sassenrath - http://www.rebol.org/view-script.r?script=rebocalc.r - Replicated here for nicer syntax highlighting
REBOL [
Title: "Rebocalc"
Date: 19-Jun-2001
Version: 1.0.0
File: %rebocalc.r
Author: "Carl Sassenrath"
Purpose: {The world's smallest spreadsheet program, but very powerful.}
Email: %carl--rebol--com
library: [
level: 'beginner