Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,125 @@
' version 17-02-2016
' compile with: fbc -s console
' TRUE/FALSE are built-in constants since FreeBASIC 1.04
' For older versions they have to be defined.
#Ifndef TRUE
#Define FALSE 0
#Define TRUE Not FALSE
#EndIf
Function WD(m As Integer, d As Integer, y As Integer) As Integer
' Zellerish
' 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday
' 4 = Thursday, 5 = Friday, 6 = Saturday
If m < 3 Then ' if m = 1 or m = 2 then
m += 12
y -= 1
End If
Return (y + (y \ 4) - (y \ 100) + (y \ 400) + d + ((153 * m + 8) \ 5)) Mod 7
End Function
Function LEAPYEAR(y As Integer) As Integer
If (y Mod 4) <> 0 Then Return FALSE
If (y Mod 100) = 0 AndAlso (y Mod 400) <> 0 Then Return FALSE
Return TRUE
End Function
' ------=< main >=------
Dim As String wdn = "Mo Tu We Th Fr Sa Su" ' weekday names
Dim As String mo(1 To 12) => {"January", "February", "March", "April", _
"May", "June", "July", "August", "September", _
"October", "November", "December"}
Dim As String tmp1, tmp2, d(1 To 12)
Dim As UInteger ml(1 To 12) => {31,28,31,30,31,30,31,31,30,31,30,31}
Dim As UInteger i, i1, j, k, y = 1969
Dim As UInteger m_row = 6
Do
While InKey <> "" : Wend ' clear keyboard buffer
Print : Print " For wich year do want a calendar"
Print " Year must be greater then 1752"
Input " Input year (enter = 1969)";tmp1
If tmp1 = "" Then Exit Do
i = Val(tmp1)
If i < 1752 Then
Print
Print " Can only make a calendar for a year after 1752"
Beep : Sleep 5000, 1 : Print
Else
y = i : Exit Do
End If
Loop
Cls
Do
While InKey <> "" : Wend ' clear keyboard buffer
Print : Print " Make device choice"
Print " 132 characters Line printer, 6x2 months (Enter or 1)"
Print " 80x43 display, 3x4 months (2)"
Do
tmp1 = InKey
If tmp1 = Chr(13) Or tmp1 = "1" Then Exit Do, Do
If tmp1 = "2" Then
m_row = 3
Exit Do, Do
End If
Loop Until tmp1 <> ""
Print : Print " Enter, 1 or 2 only"
Beep : Sleep 5000, 1 : Print
Loop
Cls
Dim As UInteger char_line = m_row * 22 - 1
If LEAPYEAR(y) = TRUE Then ml(2) = 29
tmp1 = ""
For i = 1 To 31
tmp1 = tmp1 + Right((" " + Str(i)), 3)
Next
For i = 1 To 12
tmp2 = ""
j = WD(i,1, y)
If j = 0 Then j = 7
j = j - 1
tmp2 = Space(j * 3) + Left(tmp1, ml(i) * 3) + Space(21)
d(i) = tmp2
Next
Print
tmp1 = Str(y)
Print Space((char_line + (char_line And 1) - Len(tmp1)) \ 2); tmp1
Print
tmp2 = " " ' make the weekday names line
For i = 1 To m_row
tmp2 = tmp2 + wdn
If i < m_row Then tmp2 = tmp2 + " "
Next
For i = 1 To 12 Step m_row
tmp1 = ""
For j = i To i + m_row -2 ' make the month names line
tmp1 = tmp1 + Left(Space((22 - Len(mo(j))) \ 2) + mo(j) + Space(21), 22)
Next
tmp1 = tmp1 + Space((22 - Len(mo(i + m_row -1))) \ 2) + mo(i + m_row -1)
Print tmp1
Print tmp2
For j = 1 To 85 Step 21
For k = i To i + m_row -2
Print Mid(d(k), j ,21); " ";
Next
Print Mid(d(i + m_row -1), j ,21)
Next
Print
Next
' empty keyboard buffer
While InKey <> "" : Wend
'Print : Print "hit any key to end program
Sleep
End

View file

@ -0,0 +1,10 @@
include "ConsoleWindow"
dim as Str255 a
open "UNIX", 1,"cal 1969"
do
line input #1, a
print a
until eof(1)
close 1

View file

@ -0,0 +1,57 @@
----------------------------------------
-- @desc Class "Calendar"
-- @file parent script "Calendar"
----------------------------------------
property _months
property _weekdayStr
property _refDateObj
property _year
property _calStr
on new (me)
me._months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
me._weekdayStr = "Mo Tu We Th Fr Sa Su"
me._refDateObj = date(1905,1,2)
return me
end
on make (me, year)
me._year = year
me._calStr = ""
-- prefill cal string with spaces
emptyLine = bytearray(68,32).readRawString(68)&RETURN
repeat with i = 1 to 38
put emptyLine after _calStr
end repeat
me._write (string(year), 32, 1)
repeat with i = 1 to 12
me._writeMonth(i)
end repeat
return me._calStr
end
on _writeMonth (me, monthNum)
xOffset = (monthNum-1) mod 3 * 24
yOffset = (monthNum-1)/3 * 9 + 2
pre = (20 - me._months[monthNum].length)/2
me._write(me._months[monthNum], 1+xOffset+pre, 1+yOffset)
me._write(me._weekdayStr, 1+xOffset, 2+yOffset)
y = 3
x = ((date(me._year, monthNum, 1) - me._refDateObj) mod 7)+1
repeat with i = 1 to 31
if date(me._year, monthNum, i).month<>monthNum then exit repeat
dayStr = string(i)
if i<10 then put " " before dayStr
me._write(dayStr, x*3-2+xOffset, y+yOffset)
if x=7 then
y = y+1
x = 1
else
x = x+1
end if
end repeat
end
on _write (me, str, x, y)
put str into char x to x+str.length-1 of line y of _calStr
end

View file

@ -0,0 +1,3 @@
calObj = script("Calendar").new()
calStr = calObj.make(1969)
put calStr

View file

@ -0,0 +1,66 @@
include builtins\timedate.e
function centre(string s, integer width)
integer pad = width-length(s),
left = floor(pad/2),
right = pad-left
return repeat(' ',left)&s&repeat(' ',right)
end function
function one_month(integer year, integer month)
integer dow = day_of_week(year,month,1)
sequence ldm = adjust_timedate(iff(month=12?{year+1,1,1,0,0,0,0,0}
:{year,month+1,1,0,0,0,0,0}),
timedelta(days:=-1))
sequence res = {centre(format_timedate(ldm,"Mmmm"),20),"Su Mo Tu We Th Fr Sa"}
integer lastday = ldm[DT_DAY]
string line = repeat(' ',20)
integer p = dow*3-2
for d=1 to lastday do
line[p..p+1] = sprintf("%2d",d)
p += 3
if dow=7 or d=lastday then
res = append(res,line)
line = repeat(' ',20)
dow = 1
p = 1
else
dow += 1
end if
end for
return res
end function
procedure print_calendar(integer year, integer width)
sequence months = repeat(0,12)
integer wide = floor((width+2)/22)
printf(1,centre("[Spot Reserved For Snoopy]",width)&"\n")
printf(1,centre(sprintf("%d",year),width)&"\n")
for month=1 to 12 do
months[month] = one_month(year,month)
end for
for month=1 to 12 by wide do
for k=1 to 9 do -- (more than enough)
integer any = 0
string line = "", this
for j=0 to wide-1 do
if length(line) then
line &= " "
end if
if k>length(months[month+j]) then
line &= repeat(' ',20)
else
line &= months[month+j][k]
any = 1
end if
end for
if any=0 then exit end if
printf(1,centre(line,width)&"\n")
end for
end for
end procedure
print_calendar(1969,80)
printf(1,join(repeat("1234567890",8),"")&"\n")
print_calendar(1969,132)
printf(1,join(repeat("1234567890",13),"")&"12\n")

View file

@ -0,0 +1,52 @@
require('DateTime')
define months_per_col = 3
define week_day_names = <Mo Tu We Th Fr Sa Su>
define month_names = <Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec>
func fmt_month (year, month) {
var str = sprintf("%-20s\n", month_names[month-1])
str += week_day_names.join(' ')+"\n"
var dt = %s'DateTime'
var date = dt.new(year => year, month => month)
var week_day = date.day_of_week
str += ([" "] * week_day-1 -> join(" "))
var last_day = dt.last_day_of_month(year => year, month => month).day
for day in range(date.day, last_day) {
date = dt.new(year => year, month => month, day => day)
str += " " if (week_day ~~ range(2,7))
if (week_day == 8) {
str += "\n"
week_day = 1
}
str += sprintf("%2d", day)
++week_day
}
str += " " if (week_day < 8)
str += ([" "] * 8-week_day -> join(" "))
str += "\n"
}
func fmt_year (year) {
var month_strs = 12.of { |i| fmt_month(year, i).lines }
var str = (' '*30 + year + "\n")
for month in range(0, 11, months_per_col) {
while (month_strs[month]) {
months_per_col.times { |i|
month_strs[month + i - 1] || next
str += month_strs[month + i - 1].shift
str += ' '*3
}
str += "\n"
}
str += "\n"
}
return str
}
print fmt_year(ARGV.is_empty ? 1969 : ARGV[0].to_i)

View file

@ -0,0 +1,58 @@
(defun calendar (year)
(define months-list '(("JANUARY" 31) ("FEBRUARY" 28) ("MARCH" 31) ("APRIL" 30) ("MAY" 31) ("JUNE" 30) ("JULY" 31) ("AUGUST" 31) ("SEPTEMBER" 30) ("OCTOBER" 31) ("NOVEMBER" 30) ("DECEMBER" 31)))
(define days #(" Sunday " "Monday " "Tuesday " "Wednesday " "Thursday " "Friday " "Saturday"))
(defun gauss-algorithm (a)
(rem (+ 1 (+ (* 5 (rem (- a 1) 4)) (* 4 (rem (- a 1) 100)) (* 6 (rem (- a 1) 400)))) 7))
(defun range (start end)
(if (<= start end)
(cons start (range (+ start 1) end))))
(defun string-repeat (s n)
(if (= n 0)
""
(string-append s (string-repeat s (- n 1)))))
(defun print-month (number-of-days start-day)
(defun print-days (day day-of-week end-day)
(if (= day-of-week 7)
(begin
(newline)
(define day-of-week 0)))
(display (string-repeat " " 8))
(if (= day-of-week 0)
(display (string-repeat " " 6)))
(if (< day 10)
(display " "))
(display day)
(display (string-repeat " " 8))
(if (= day end-day)
(begin
(fresh-line)
(+ day-of-week 1))
(print-days (+ day 1) (+ day-of-week 1) end-day)))
(mapcar (lambda (n) (display (vector-ref days n))) (range 0 6))
(newline)
(display (string-repeat (string-repeat " " 18) start-day))
(print-days 1 start-day number-of-days))
(defun leap-yearp (y)
(and (= (mod year 4) 0) (or (/= (mod year 100) 0) (= (mod year 400) 0))))
(define months (make-table))
(mapcar (lambda (month) (table-set! months (car month) (cadr month))) months-list)
(if (leap-yearp year)
(table-set! months "FEBRUARY" 29))
(defun print-calendar (calendar-months weekday)
(newline)
(newline)
(display (string-repeat " " 60))
(display (caar calendar-months))
(newline)
(define next-month-starts (print-month (table-ref months (caar calendar-months)) weekday))
(if (cdr calendar-months)
(print-calendar (cdr calendar-months) next-month-starts)))
(display (string-repeat " " 60))
(display "******** SNOOPY CALENDAR ")
(display year)
(display " ********")
(newline)
(newline)
(print-calendar months-list (gauss-algorithm year)))
(calendar 1969)