September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
8
Task/Even-or-odd/AppleScript/even-or-odd-1.applescript
Normal file
8
Task/Even-or-odd/AppleScript/even-or-odd-1.applescript
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
set nList to {3, 2, 1, 0, -1, -2, -3}
|
||||
repeat with n in nList
|
||||
if (n / 2) = n / 2 as integer then
|
||||
log "Value " & n & " is even."
|
||||
else
|
||||
log "Value " & n & " is odd."
|
||||
end if
|
||||
end repeat
|
||||
45
Task/Even-or-odd/AppleScript/even-or-odd-2.applescript
Normal file
45
Task/Even-or-odd/AppleScript/even-or-odd-2.applescript
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
-- even :: Integral a => a -> Bool
|
||||
on even(n)
|
||||
n mod 2 = 0
|
||||
end even
|
||||
|
||||
-- odd :: Integral a => a -> Bool
|
||||
on odd(n)
|
||||
not even(n)
|
||||
end odd
|
||||
|
||||
|
||||
-- GENERIC FUNCTIONS FOR TEST ----------------------------------
|
||||
|
||||
-- filter :: (a -> Bool) -> [a] -> [a]
|
||||
on filter(f, xs)
|
||||
tell mReturn(f)
|
||||
set lst to {}
|
||||
set lng to length of xs
|
||||
repeat with i from 1 to lng
|
||||
set v to item i of xs
|
||||
if lambda(v, i, xs) then set end of lst to v
|
||||
end repeat
|
||||
return lst
|
||||
end tell
|
||||
end filter
|
||||
|
||||
-- Lift 2nd class handler function into 1st class script wrapper
|
||||
-- mReturn :: Handler -> Script
|
||||
on mReturn(f)
|
||||
if class of f is script then
|
||||
f
|
||||
else
|
||||
script
|
||||
property lambda : f
|
||||
end script
|
||||
end if
|
||||
end mReturn
|
||||
|
||||
|
||||
-- TEST ---------------------------------------------------------
|
||||
on run
|
||||
set xs to [-6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6]
|
||||
|
||||
{filter(even, xs), filter(odd, xs)}
|
||||
end run
|
||||
1
Task/Even-or-odd/AppleScript/even-or-odd-3.applescript
Normal file
1
Task/Even-or-odd/AppleScript/even-or-odd-3.applescript
Normal file
|
|
@ -0,0 +1 @@
|
|||
{{-6, -4, -2, 0, 2, 4, 6}, {-5, -3, -1, 1, 3, 5}}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
set nList to {3, 2, 1, 0, -1, -2, -3}
|
||||
repeat with n in nList
|
||||
if (n / 2) = n / 2 as integer then
|
||||
log "Value " & n & " is even."
|
||||
else
|
||||
log "Value " & n & " is odd."
|
||||
end if
|
||||
end repeat
|
||||
5
Task/Even-or-odd/BaCon/even-or-odd.bacon
Normal file
5
Task/Even-or-odd/BaCon/even-or-odd.bacon
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
' Even or odd
|
||||
OPTION MEMTYPE int
|
||||
SPLIT ARGUMENT$ BY " " TO arg$ SIZE dim
|
||||
n = IIF$(dim < 2, 0, VAL(arg$[1]))
|
||||
PRINT n, " is ", IIF$(EVEN(n), "even", "odd")
|
||||
8
Task/Even-or-odd/Bc/even-or-odd.bc
Normal file
8
Task/Even-or-odd/Bc/even-or-odd.bc
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
i = -3
|
||||
|
||||
/* Assumes that i is an integer. */
|
||||
scale = 0
|
||||
if (i % 2 == 0) "i is even
|
||||
"
|
||||
if (i % 2) "i is odd
|
||||
"
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
<Cfif i MOD 2 eq 0>
|
||||
She's even
|
||||
<Cfelse>
|
||||
He's odd
|
||||
</cfif>
|
||||
function f(numeric n) {
|
||||
return n mod 2?"odd":"even"
|
||||
}
|
||||
|
|
|
|||
33
Task/Even-or-odd/EDSAC-order-code/even-or-odd.edsac
Normal file
33
Task/Even-or-odd/EDSAC-order-code/even-or-odd.edsac
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
[ Even or odd
|
||||
===========
|
||||
|
||||
A program for the EDSAC
|
||||
|
||||
Determines whether the number stored at
|
||||
address 15@ is even or odd, and prints
|
||||
'E' or 'O' accordingly
|
||||
|
||||
Works with Initial Orders 2 ]
|
||||
|
||||
T56K [ load point ]
|
||||
GK [ base address ]
|
||||
|
||||
O11@ [ print letter shift ]
|
||||
T10@ [ clear accumulator ]
|
||||
H15@ [ multiplier := n ]
|
||||
C12@ [ acc +:= mult AND 1 ]
|
||||
S12@ [ acc -:= 1 ]
|
||||
G8@ [ branch on negative ]
|
||||
O14@ [ print 'O' ]
|
||||
ZF [ halt ]
|
||||
[ 8 ] O13@ [ print 'E' ]
|
||||
ZF [ halt ]
|
||||
|
||||
[ 10 ] P0F [ used to clear acc ]
|
||||
[ 11 ] *F [ letter shift character ]
|
||||
[ 12 ] P0D [ const: 1 ]
|
||||
[ 13 ] EF [ character 'E' ]
|
||||
[ 14 ] OF [ character 'O' ]
|
||||
[ 15 ] P18D [ number to test: 37 ]
|
||||
|
||||
EZPF [ branch to load point ]
|
||||
|
|
@ -1,13 +1,13 @@
|
|||
defmodule RC do
|
||||
require Integer
|
||||
import Integer
|
||||
|
||||
def even_or_odd(n) when Integer.is_even(n), do: "#{n} is even"
|
||||
def even_or_odd(n) , do: "#{n} is odd"
|
||||
def even_or_odd(n) when is_even(n), do: "#{n} is even"
|
||||
def even_or_odd(n) , do: "#{n} is odd"
|
||||
# In second "def", the guard clauses of "is_odd(n)" is unnecessary.
|
||||
|
||||
# Another definition way
|
||||
def even_or_odd2(n) do
|
||||
if Integer.is_even(n), do: "#{n} is even", else: "#{n} is odd"
|
||||
if is_even(n), do: "#{n} is even", else: "#{n} is odd"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
15
Task/Even-or-odd/Gambas/even-or-odd.gambas
Normal file
15
Task/Even-or-odd/Gambas/even-or-odd.gambas
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
Public Sub Form_Open()
|
||||
Dim sAnswer, sMessage As String
|
||||
|
||||
sAnswer = InputBox("Input an integer", "Odd or even")
|
||||
|
||||
If IsInteger(sAnswer) Then
|
||||
If Odd(Val(sAnswer)) Then sMessage = "' is an odd number"
|
||||
If Even(Val(sAnswer)) Then sMessage = "' is an even number"
|
||||
Else
|
||||
sMessage = "' does not compute!!"
|
||||
Endif
|
||||
|
||||
Print "'" & sAnswer & sMessage
|
||||
|
||||
End
|
||||
11
Task/Even-or-odd/Haskell/even-or-odd-2.hs
Normal file
11
Task/Even-or-odd/Haskell/even-or-odd-2.hs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import Prelude hiding (even, odd)
|
||||
|
||||
even, odd
|
||||
:: (Integral a)
|
||||
=> a -> Bool
|
||||
even = (0 ==) . (`rem` 2)
|
||||
|
||||
odd = not . even
|
||||
|
||||
main :: IO ()
|
||||
main = print (even <$> [0 .. 9])
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
// EMCAScript 6
|
||||
const isEven=x=>!(x%2)
|
||||
const isEven = x => !(x % 2)
|
||||
|
|
|
|||
25
Task/Even-or-odd/JavaScript/even-or-odd-4.js
Normal file
25
Task/Even-or-odd/JavaScript/even-or-odd-4.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(() => {
|
||||
'use strict';
|
||||
|
||||
// even : Integral a => a -> Bool
|
||||
const even = x => (x % 2) === 0;
|
||||
|
||||
// odd : Integral a => a -> Bool
|
||||
const odd = x => !even(x);
|
||||
|
||||
|
||||
// TEST ----------------------------------------
|
||||
// range :: Int -> Int -> [Int]
|
||||
const range = (m, n) =>
|
||||
Array.from({
|
||||
length: Math.floor(n - m) + 1
|
||||
}, (_, i) => m + i);
|
||||
|
||||
// show :: a -> String
|
||||
const show = JSON.stringify;
|
||||
|
||||
// xs :: [Int]
|
||||
const xs = range(-6, 6);
|
||||
|
||||
return show([xs.filter(even), xs.filter(odd)]);
|
||||
})();
|
||||
13
Task/Even-or-odd/Kotlin/even-or-odd.kotlin
Normal file
13
Task/Even-or-odd/Kotlin/even-or-odd.kotlin
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
// version 1.0.5-2
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
while (true) {
|
||||
print("Enter an integer or 0 to finish : ")
|
||||
val n = readLine()!!.toInt()
|
||||
when {
|
||||
n == 0 -> return
|
||||
n % 2 == 0 -> println("Your number is even")
|
||||
else -> println("Your number is odd")
|
||||
}
|
||||
}
|
||||
}
|
||||
7
Task/Even-or-odd/Processing/even-or-odd
Normal file
7
Task/Even-or-odd/Processing/even-or-odd
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
boolean isEven(int i){
|
||||
return i%2 == 0;
|
||||
}
|
||||
|
||||
boolean isOdd(int i){
|
||||
return i%2 == 1;
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
print "evens: "
|
||||
p -5.upto(5).select {|n| n.even?}
|
||||
p -5.upto(5).select(&:even?)
|
||||
print "odds: "
|
||||
p -5.upto(5).select {|n| n.odd?}
|
||||
p -5.upto(5).select(&:odd?)
|
||||
|
|
|
|||
4
Task/Even-or-odd/SPL/even-or-odd.spl
Normal file
4
Task/Even-or-odd/SPL/even-or-odd.spl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
> n, 0..9
|
||||
? #.even(n), #.output(n," even")
|
||||
? #.odd(n), #.output(n," odd")
|
||||
<
|
||||
7
Task/Even-or-odd/Shen/even-or-odd-1.shen
Normal file
7
Task/Even-or-odd/Shen/even-or-odd-1.shen
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
(define even?
|
||||
0 -> true
|
||||
X -> (odd? (- X 1)))
|
||||
|
||||
(define odd?
|
||||
0 -> false
|
||||
X -> (even? (- X 1)))
|
||||
3
Task/Even-or-odd/Shen/even-or-odd-2.shen
Normal file
3
Task/Even-or-odd/Shen/even-or-odd-2.shen
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
(define even? X -> (= 0 (shen.mod X 2)))
|
||||
|
||||
(define odd? X -> (not (= 0 (shen.mod X 2))))
|
||||
4
Task/Even-or-odd/XEec/even-or-odd.xeec
Normal file
4
Task/Even-or-odd/XEec/even-or-odd.xeec
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
>100 p i# jz-1 o# t h#1 ms jz2003 p >0110 h#2 r ms t h#1 ms p
|
||||
jz1002 h? jz2003 p jn0110 h#10 o$ p jn100 >2003 p p h#0 h#10
|
||||
h$d h$d h$o h#32 h$s h$i h#32 jn0000 >1002 p p h#0 h#10
|
||||
h$n h$e h$v h$e h#32 h$s h$i h#32 >0000 o$ p jn0000 jz100
|
||||
5
Task/Even-or-odd/XLISP/even-or-odd.xlisp
Normal file
5
Task/Even-or-odd/XLISP/even-or-odd.xlisp
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
(defun my-evenp (x)
|
||||
(= (logand x 1) 0) )
|
||||
|
||||
(defun my-oddp (x)
|
||||
(/= (logand x 1) 0) )
|
||||
1
Task/Even-or-odd/Zkl/even-or-odd-1.zkl
Normal file
1
Task/Even-or-odd/Zkl/even-or-odd-1.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
[-3..4].pump(fcn(n){ println(n," is ",n.isEven and "even" or "odd") })
|
||||
1
Task/Even-or-odd/Zkl/even-or-odd-2.zkl
Normal file
1
Task/Even-or-odd/Zkl/even-or-odd-2.zkl
Normal file
|
|
@ -0,0 +1 @@
|
|||
[-3..4].apply("isEven").println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue