Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
17
Task/Leap-year/ERRE/leap-year.erre
Normal file
17
Task/Leap-year/ERRE/leap-year.erre
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
PROGRAM LEAP_YEAR
|
||||
|
||||
FUNCTION LEAP(YR%)
|
||||
LEAP=(YR% MOD 4=0) AND ((YR% MOD 400=0) OR (YR% MOD 100<>0))
|
||||
END FUNCTION
|
||||
|
||||
BEGIN
|
||||
LOOP
|
||||
INPUT("Enter a year: ",year%)
|
||||
EXIT IF YEAR%=0
|
||||
IF LEAP(year%) THEN
|
||||
PRINT(year%;" is a leap year")
|
||||
ELSE
|
||||
PRINT(year%;" is not a leap year")
|
||||
END IF
|
||||
END LOOP
|
||||
END PROGRAM
|
||||
42
Task/Leap-year/FreeBASIC/leap-year.freebasic
Normal file
42
Task/Leap-year/FreeBASIC/leap-year.freebasic
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
' version 23-06-2015
|
||||
' compile with: fbc -s console
|
||||
|
||||
#Ifndef TRUE ' define true and false for older freebasic versions
|
||||
#Define FALSE 0
|
||||
#Define TRUE Not FALSE
|
||||
#EndIf
|
||||
|
||||
Function leapyear(Year_ As Integer) As Integer
|
||||
|
||||
If (Year_ Mod 4) <> 0 Then Return FALSE
|
||||
If (Year_ Mod 100) = 0 AndAlso (Year_ Mod 400) <> 0 Then Return FALSE
|
||||
Return TRUE
|
||||
|
||||
End Function
|
||||
|
||||
' ------=< MAIN >=------
|
||||
|
||||
' year is a FreeBASIC keyword
|
||||
Dim As Integer Year_
|
||||
|
||||
For Year_ = 1800 To 2900 Step 100
|
||||
Print Year_; IIf(leapyear(Year_), " is a leap year", " is not a leap year")
|
||||
Next
|
||||
|
||||
Print : Print
|
||||
|
||||
For Year_ = 2012 To 2031
|
||||
Print Year_;
|
||||
If leapyear(Year_) = TRUE Then
|
||||
Print " = leap",
|
||||
Else
|
||||
Print " = no",
|
||||
End If
|
||||
If year_ Mod 4 = 3 Then Print ' lf/cr
|
||||
Next
|
||||
|
||||
' empty keyboard buffer
|
||||
While InKey <> "" : Wend
|
||||
Print : Print "hit any key to end program"
|
||||
Sleep
|
||||
End
|
||||
50
Task/Leap-year/FutureBasic/leap-year.futurebasic
Normal file
50
Task/Leap-year/FutureBasic/leap-year.futurebasic
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
include "ConsoleWindow"
|
||||
|
||||
// In-line C function to generate random number in range
|
||||
BeginCFunction
|
||||
long randomInRange( long min, long max ) {
|
||||
int i = (arc4random()%(max-min+1))+min;
|
||||
return (long)i;
|
||||
}
|
||||
EndC
|
||||
toolbox fn randomInRange( long min, long max ) = long
|
||||
|
||||
// Leap year test function
|
||||
local fn LeapYear( year as long ) as Boolean
|
||||
dim as Boolean result : result = _false
|
||||
|
||||
if year mod 400 == 0 then result = _true : exit fn
|
||||
if year mod 100 == 0 then result = _false : exit fn
|
||||
if year mod 4 == 0 then result = _true : exit fn
|
||||
if year mod 4 != 0 then result = _false : exit fn
|
||||
end fn = result
|
||||
|
||||
dim as long i, y, knownLeapYear(10)
|
||||
|
||||
// Array of known leap years from 1980 through 2020 for control
|
||||
knownLeapYear(0) = 1980 : knownLeapYear(1) = 1984 : knownLeapYear(2) = 1988
|
||||
knownLeapYear(3) = 1992 : knownLeapYear(4) = 1996 : knownLeapYear(5) = 2000
|
||||
knownLeapYear(6) = 2004 : knownLeapYear(7) = 2008 : knownLeapYear(8) = 2012
|
||||
knownLeapYear(9) = 2016 : knownLeapYear(10) = 2020
|
||||
|
||||
print "Known leap years:"
|
||||
for i = 0 to 9
|
||||
if ( fn LeapYear( knownLeapYear(i) ) == _true )
|
||||
print knownLeapYear(i); " is a leap year."
|
||||
else
|
||||
print knownLeapYear(i); " is a not leap year."
|
||||
end if
|
||||
next
|
||||
|
||||
print
|
||||
|
||||
// Random years from 1980 to 2020 to test
|
||||
print "Check random years:"
|
||||
for i = 0 to 20
|
||||
y = fn randomInRange( 1980, 2020 )
|
||||
if ( fn LeapYear( y ) == _true )
|
||||
print y; " is a leap year."
|
||||
else
|
||||
print y; " is a not leap year."
|
||||
end if
|
||||
next
|
||||
2
Task/Leap-year/Harbour/leap-year.harbour
Normal file
2
Task/Leap-year/Harbour/leap-year.harbour
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
FUNCTION IsLeapYear( nYear )
|
||||
RETURN iif( nYear % 100 == 0, nYear % 400 == 0, nYear % 4 == 0 )
|
||||
6
Task/Leap-year/Hy/leap-year.hy
Normal file
6
Task/Leap-year/Hy/leap-year.hy
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
(defn leap? [y]
|
||||
(and
|
||||
(= (% y 4) 0)
|
||||
(or
|
||||
(!= (% y 100) 0)
|
||||
(= (% y 400) 0))))
|
||||
11
Task/Leap-year/Lasso/leap-year.lasso
Normal file
11
Task/Leap-year/Lasso/leap-year.lasso
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
define isLeapYear(y::integer) => {
|
||||
#y % 400 == 0 ? return true
|
||||
#y % 100 == 0 ? return false
|
||||
#y % 4 == 0 ? return true
|
||||
return false
|
||||
}
|
||||
|
||||
with test in array(2012,2016,1933,1900,1999,2000) do => {^
|
||||
isLeapYear(#test)
|
||||
'\r'
|
||||
^}
|
||||
3
Task/Leap-year/Lingo/leap-year.lingo
Normal file
3
Task/Leap-year/Lingo/leap-year.lingo
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
on isLeapYear (year)
|
||||
return date(year, 2, 29).month=2
|
||||
end
|
||||
18
Task/Leap-year/LiveCode/leap-year.livecode
Normal file
18
Task/Leap-year/LiveCode/leap-year.livecode
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function isLeapYear year
|
||||
return (year MOD 4 is 0) AND ((year MOD 400 is 0) OR (year MOD 100 is not 0))
|
||||
end isLeapYear
|
||||
|
||||
command testLeapYear
|
||||
set itemDelimiter to comma
|
||||
put "1900,1994,1996,1997,2000" into years
|
||||
repeat for each item y in years
|
||||
put y && "is" && isLeapYear(y) && return after tyears
|
||||
end repeat
|
||||
put tyears
|
||||
end testLeapYear
|
||||
|
||||
1900 is false
|
||||
1994 is false
|
||||
1996 is true
|
||||
1997 is false
|
||||
2000 is true
|
||||
12
Task/Leap-year/Nim/leap-year.nim
Normal file
12
Task/Leap-year/Nim/leap-year.nim
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import times
|
||||
let year = 1980
|
||||
echo isLeapYear(year)
|
||||
|
||||
# or
|
||||
|
||||
proc isLeapYear2(year): bool =
|
||||
if year mod 100 == 0:
|
||||
year mod 400 == 0
|
||||
else: year mod 4 == 0
|
||||
|
||||
echo isLeapYear2(year)
|
||||
1
Task/Leap-year/Oforth/leap-year.oforth
Normal file
1
Task/Leap-year/Oforth/leap-year.oforth
Normal file
|
|
@ -0,0 +1 @@
|
|||
Date.IsLeapYear(2000)
|
||||
3
Task/Leap-year/Phix/leap-year.phix
Normal file
3
Task/Leap-year/Phix/leap-year.phix
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
global function is_leap_year(integer y)
|
||||
return remainder(y,4)=0 and (remainder(y,100)!=0 or remainder(y,400)=0)
|
||||
end function
|
||||
10
Task/Leap-year/Ring/leap-year.ring
Normal file
10
Task/Leap-year/Ring/leap-year.ring
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
give year
|
||||
leap = isLeapYear(year)
|
||||
if leap true see year + " is leap year."
|
||||
else see year + " is not leap year." ok
|
||||
|
||||
Func isLeapYear year
|
||||
if (year % 400) = 0 return true
|
||||
but (year % 100) = 0 return false
|
||||
but (year % 4) = 0 return true
|
||||
else return false ok
|
||||
6
Task/Leap-year/Sidef/leap-year-1.sidef
Normal file
6
Task/Leap-year/Sidef/leap-year-1.sidef
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
func isleap(year) {
|
||||
if (year %% 100) {
|
||||
return (year %% 400);
|
||||
}
|
||||
return (year %% 4);
|
||||
}
|
||||
1
Task/Leap-year/Sidef/leap-year-2.sidef
Normal file
1
Task/Leap-year/Sidef/leap-year-2.sidef
Normal file
|
|
@ -0,0 +1 @@
|
|||
func isleap(year) { year %% 100 ? (year %% 400) : (year %% 4) };
|
||||
6
Task/Leap-year/Swift/leap-year.swift
Normal file
6
Task/Leap-year/Swift/leap-year.swift
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
func isLeapYear(year:Int) -> Bool {
|
||||
return (year % 100 == 0) ? (year % 400 == 0) : (year % 4 == 0)
|
||||
}
|
||||
|
||||
println(isLeapYear(2000))
|
||||
println(isLeapYear(2011))
|
||||
11
Task/Leap-year/Ursa/leap-year.ursa
Normal file
11
Task/Leap-year/Ursa/leap-year.ursa
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
decl int year
|
||||
set year (int args<1>)
|
||||
if (= (mod year 4) 0)
|
||||
if (and (= (mod year 100) 0) (not (= (mod year 400) 0)))
|
||||
out year " is not a leap year" endl console
|
||||
else
|
||||
out year " is a leap year" endl console
|
||||
end if
|
||||
else
|
||||
out year " is not a leap year" endl console
|
||||
end if
|
||||
4
Task/Leap-year/Wortel/leap-year.wortel
Normal file
4
Task/Leap-year/Wortel/leap-year.wortel
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
@let {
|
||||
isLeapYear !?{\~%%1H \~%%4H \~%%4}
|
||||
!-isLeapYear @range[1900 2000]
|
||||
}
|
||||
5
Task/Leap-year/XLISP/leap-year.xlisp
Normal file
5
Task/Leap-year/XLISP/leap-year.xlisp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(DEFUN LEAP-YEARP (YEAR)
|
||||
(AND (= (MOD YEAR 4) 0) (OR (/= (MOD YEAR 100) 0) (= (MOD YEAR 400) 0))))
|
||||
|
||||
; Test the function
|
||||
(DISPLAY (MAPCAR LEAP-YEARP '(1600 1640 1800 1928 1979 1990 2000 2004 2005 2016)))
|
||||
2
Task/Leap-year/jq/leap-year-1.jq
Normal file
2
Task/Leap-year/jq/leap-year-1.jq
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
def leap:
|
||||
. as $y | ($y%4) == 0 and ($y < 1582 or ($y%400) == 0 or ($y%100) != 0);
|
||||
7
Task/Leap-year/jq/leap-year-2.jq
Normal file
7
Task/Leap-year/jq/leap-year-2.jq
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def assert(value; f):
|
||||
value as $value
|
||||
| ($value|f) | if . then empty else error("assertion violation: \($value) => \(.)") end;
|
||||
|
||||
((2400, 2012, 2000, 1600, 1500, 1400) | assert(.; leap)),
|
||||
|
||||
((2100, 2014, 1900, 1800, 1700, 1499) | assert(.; leap|not))
|
||||
Loading…
Add table
Add a link
Reference in a new issue