task_url
stringlengths
30
116
task_name
stringlengths
2
86
task_description
stringlengths
0
14.4k
language_url
stringlengths
2
53
language_name
stringlengths
1
52
code
stringlengths
0
61.9k
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Scala
Scala
class Dot[T](v1: Seq[T])(implicit n: Numeric[T]) { import n._ // import * operator def dot(v2: Seq[T]) = { require(v1.size == v2.size) (v1 zip v2).map{ Function.tupled(_ * _)}.sum } }   object Main extends App { implicit def toDot[T: Numeric](v1: Seq[T]) = new Dot(v1)   val v1 = List(1, 3, -5) val v...
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Ring
Ring
  sanitation= 0 see "police fire sanitation" + nl   for police = 2 to 7 step 2 for fire = 1 to 7 if fire = police loop ok sanitation = 12 - police - fire if sanitation = fire or sanitation = police loop ok if sanitation >= 1 and sanitation <= ...
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Ruby
Ruby
  (1..7).to_a.permutation(3){|p| puts p.join if p.first.even? && p.sum == 12 }  
http://rosettacode.org/wiki/Delete_a_file
Delete a file
Task Delete a file called "input.txt" and delete a directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#Visual_Basic_.NET
Visual Basic .NET
'Current Directory IO.Directory.Delete("docs") IO.Directory.Delete("docs", True) 'also delete files and sub-directories IO.File.Delete("output.txt")   'Root IO.Directory.Delete("\docs") IO.File.Delete("\output.txt")   'Root, platform independent IO.Directory.Delete(IO.Path.DirectorySeparatorChar & "docs") IO.File.Delet...
http://rosettacode.org/wiki/Delete_a_file
Delete a file
Task Delete a file called "input.txt" and delete a directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#Wren
Wren
import "io" for File   File.delete("input.txt")   // check it worked System.print(File.exists("input.txt"))
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#R
R
> strings <- c("152", "-3.1415926", "Foo123") > suppressWarnings(!is.na(as.numeric(strings))) [1] TRUE TRUE FALSE  
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Racket
Racket
(define (string-numeric? s) (number? (string->number s)))
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Scheme
Scheme
(define (dot-product a b) (apply + (map * a b)))   (display (dot-product '(1 3 -5) '(4 -2 -1))) (newline)
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Scilab
Scilab
A = [1 3 -5] B = [4 -2 -1] C = sum(A.*B)
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Rust
Rust
extern crate num_iter; fn main() { println!("Police Sanitation Fire"); println!("----------------------");   for police in num_iter::range_step(2, 7, 2) { for sanitation in 1..8 { for fire in 1..8 { if police != sanitation && sanitation != fire ...
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Scala
Scala
val depts = { (1 to 7).permutations.map{ n => (n(0),n(1),n(2)) }.toList.distinct // All permutations of possible department numbers .filter{ n => n._1 % 2 == 0 } // Keep only even numbers favored by Police Chief .filter{ n => n._1 + n._2 + n._3 == 12 } ...
http://rosettacode.org/wiki/Delete_a_file
Delete a file
Task Delete a file called "input.txt" and delete a directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#X86_Assembly
X86 Assembly
  ;syscall numbers for readability. :] %define sys_rmdir 40 %define sys_unlink 10   section .text global _start   _start: mov ebx, fn mov eax, sys_unlink int 0x80 test eax, eax js _ragequit   mov ebx, dn mov eax, sys_rmdir int 0x80   mov ebx, rfn mov eax, sys_unlink int 0x80 cmp eax, 0 je...
http://rosettacode.org/wiki/Delete_a_file
Delete a file
Task Delete a file called "input.txt" and delete a directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#Yorick
Yorick
remove, "input.txt"; remove, "/input.txt"; rmdir, "docs"; rmdir, "/docs";
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Raku
Raku
sub is-number-w-ws( Str $term --> Bool ) { # treat Falsey strings as numeric $term.Numeric !~~ Failure; }   sub is-number-wo-ws( Str $term --> Bool ) { # treat Falsey strings as non-numeric ?($term ~~ / \S /) && $term.Numeric !~~ Failure; }   say " Coerce Don't coerce"; say ' String white...
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Seed7
Seed7
$ include "seed7_05.s7i";   $ syntax expr: .().dot.() is -> 6; # priority of dot operator   const func integer: (in array integer: a) dot (in array integer: b) is func result var integer: sum is 0; local var integer: index is 0; begin if length(a) <> length(b) then raise RANGE_ERROR; else ...
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Sidef
Sidef
func dot_product(a, b) { (a »*« b)«+»; }; say dot_product([1,3,-5], [4,-2,-1]); # => 3
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Sidef
Sidef
@(1..7)->combinations(3, {|*a| a.sum == 12 || next a.permutations {|*b| b[0].is_even || next say (%w(police fire sanitation) ~Z b -> join(" ")) } })
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Swift
Swift
let res = [2, 4, 6].map({x in return (1...7) .filter({ $0 != x }) .map({y -> (Int, Int, Int)? in let z = 12 - (x + y)   guard y != z && 1 <= z && z <= 7 else { return nil }   return (x, y, z) }).compactMap({ $0 }) }).flatMap({ $0 })   for result in res { p...
http://rosettacode.org/wiki/Delete_a_file
Delete a file
Task Delete a file called "input.txt" and delete a directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#zig
zig
const std = @import("std"); const fs = std.fs;   pub fn main() !void { const here = fs.cwd(); try here.deleteFile("input.txt"); try here.deleteDir("docs");   const root = try fs.openDirAbsolute("/", .{}); try root.deleteFile("input.txt"); try root.deleteDir("docs"); }
http://rosettacode.org/wiki/Delete_a_file
Delete a file
Task Delete a file called "input.txt" and delete a directory called "docs". This should be done twice: once "here", i.e. in the current working directory and once in the filesystem root.
#zkl
zkl
zkl: System.cmd((System.isWindows and "del" or "unlink") + " input.txt") 0 zkl: System.cmd((System.isWindows and "del" or "unlink") + " /input.txt") unlink: cannot unlink ‘/input.txt’: No such file or directory 256 zkl: System.cmd("rmdir docs") rmdir: failed to remove ‘docs’: Directory not empty 256 zkl: System.cmd("rm...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#RapidQ
RapidQ
isnumeric $Typecheck on   Defint FALSE, TRUE   FALSE = 0 TRUE = NOT FALSE   Function isNumeric(s as string, optchar as string) as integer If len(s) = 0 then Result = FALSE Exit Function End If if instr(s,"+") > 1 then Result = FALSE exit function end if if instr(...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#REBOL
REBOL
  rebol [ Title: "Is Numeric?" URL: http://rosettacode.org/wiki/IsNumeric ]   ; Built-in.   numeric?: func [x][not error? try [to-decimal x]]   ; Parse dialect for numbers.   sign: [0 1 "-"] digit: charset "0123456789" int: [some digit] float: [int "." int] number: [ sign float ["e" | "E"] sign int | sign in...
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Slate
Slate
v@(Vector traits) <dot> w@(Vector traits) "Dot-product." [ (0 below: (v size min: w size)) inject: 0 into: [| :sum :index | sum + ((v at: index) * (w at: index))] ].
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Smalltalk
Smalltalk
Array extend [ * anotherArray [ |acc| acc := 0. self with: anotherArray collect: [ :a :b | acc := acc + ( a * b ) ]. ^acc ] ]   ( #(1 3 -5) * #(4 -2 -1 ) ) printNl.
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Tcl
Tcl
  # Procedure named ".." returns list of integers from 1 to max. proc .. max { for {set i 1} {$i <= $max} {incr i} { lappend l $i } return $l }   # Procedure named "anyEqual" returns true if any elements are equal, # false otherwise. proc anyEqual l { if {[llength [lsort -unique $l]] != [llength $l]} { ...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Retro
Retro
'123 a:from-string TRUE [ swap c:digit? and ] a:reduce
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#REXX
REXX
/*REXX program determines if a string is numeric, using REXX's rules for numbers. */ yyy=' -123.78' /*or some such. */   /*strings below are all numeric (REXX).*/ zzz= ' -123.78 ' zzz= '-123.78' zzz= '2' zzz=...
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#SNOBOL4
SNOBOL4
define("dotp(a,b)sum,i")  :(dotp_end) dotp i = 1; sum = 0 loop sum = sum + (a<i> * b<i>) i = i + 1 ?a<i> :s(loop) dotp = sum  :(return) dotp_end   a = array(3); a<1> = 1; a<2> = 3; a<3> = -5; b = array(3); b<1> = 4; b<2> = -2; b<3> = -1; output = do...
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#SPARK
SPARK
with Spark_IO; --# inherit Spark_IO; --# main_program; procedure Dot_Product_Main --# global in out Spark_IO.Outputs; --# derives Spark_IO.Outputs from *; is Limit : constant := 1000; type V_Elem is range -Limit .. Limit; V_Size : constant := 100; type V_Index is range 1 .. V_Size; type Vector is array(V...
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Tiny_BASIC
Tiny BASIC
PRINT "Police Sanitation Fire" PRINT "------|----------|----" 10 LET P = P + 2 LET S = 0 20 LET S = S + 1 LET F = 0 IF S = P THEN GOTO 20 30 LET F = F + 1 IF S = F THEN GOTO 30 IF F = P THEN GOTO 30 IF P + S + F = 12 THEN PRINT " ",P," ", S," ", F IF F < 7 THEN GOTO 30 IF S <...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Ring
Ring
  see isdigit("0123456789") + nl + # print 1 isdigit("0123a") # print 0  
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Ruby
Ruby
def is_numeric?(s) begin Float(s) rescue false # not numeric else true # numeric end end
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#SQL
SQL
SELECT i, k, SUM(A.N*B.N) AS N FROM A INNER JOIN B ON A.j=B.j GROUP BY i, k
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Transd
Transd
#lang transd   MainModule : { _start: (lambda (lout "Police | Sanit. | Fire") (for i in Range(1 8) where (not (mod i 2)) do (for j in Range(1 8) where (neq i j) do (for k in Range(1 8) where (and (neq i k) (neq j k)) do (if (eq (+ i j k) 12) (lout i " "...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Run_BASIC
Run BASIC
print isNumeric("123") print isNumeric("1ab")   ' ------------------------ ' Numeric Check ' 0 = bad ' 1 = good ' ------------------------ FUNCTION isNumeric(f$) isNumeric = 1 f$ = trim$(f$) if left$(f$,1) = "-" or left$(f$,1) = "+" then f$ = mid$(f$,2) for i = 1 to len(f$) d$ = mid$(f$,i,1) if d$ = "," then ...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Rust
Rust
// This function is not limited to just numeric types but rather anything that implements the FromStr trait. fn parsable<T: FromStr>(s: &str) -> bool { s.parse::<T>().is_ok() }
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Standard_ML
Standard ML
val dot = ListPair.foldlEq Real.*+ 0.0   (* - dot ([1.0, 3.0, ~5.0], [4.0, ~2.0, ~1.0]); val it = 3.0 : real *)
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Stata
Stata
matrix a=1,3,-5 matrix b=4,-2,-1 matrix c=a*b' di el("c",1,1)
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#TypeScript
TypeScript
  // Department numbers console.log(`POLICE SANITATION FIRE`); let f: number; for (var p = 2; p <= 7; p += 2) { for (var s = 1; s <= 7; s++) { if (s != p) { f = (12 - p) - s; if ((f > 0) && (f <= 7) && (f != s) && (f != p)) console.log(` ${p} ${s} ${f}`); } } }  
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Scala
Scala
  import scala.util.control.Exception.allCatch   def isNumber(s: String): Boolean = (allCatch opt s.toDouble).isDefined  
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Scheme
Scheme
(define (numeric? s) (string->number s))
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Swift
Swift
func dot(v1: [Double], v2: [Double]) -> Double { return reduce(lazy(zip(v1, v2)).map(*), 0, +) }   println(dot([1, 3, -5], [4, -2, -1]))
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Tcl
Tcl
package require math::linearalgebra   set a {1 3 -5} set b {4 -2 -1} set dotp [::math::linearalgebra::dotproduct $a $b] proc pp vec {return \[[join $vec ,]\]} puts "[pp $a] \u2219 [pp $b] = $dotp"
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   Sub Main() For p = 2 To 7 Step 2 For s = 1 To 7 Dim f = 12 - p - s If s >= f Then Exit For End If If f > 7 Then Continue For End If If s = p Or...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "scanstri.s7i";   const func boolean: isNumeric (in var string: stri) is func result var boolean: isNumeric is FALSE; local var string: numberStri is ""; begin numberStri := getNumber(stri); isNumeric := stri = ""; end func;
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Sidef
Sidef
say "0.1E-5".looks_like_number; #=> true
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#TI-83_BASIC
TI-83 BASIC
sum({1,3,–5}*{4,–2,–1})
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#TI-89_BASIC
TI-89 BASIC
dotP([1, 3, –5], [4, –2, –1])
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Vlang
Vlang
fn main() { println("Police Sanitation Fire") println("------ ---------- ----") mut count := 0 for i := 2; i < 7; i += 2 { for j in 1..8 { if j == i { continue } for k in 1..8 { if k == i || k == j { continue } if i + j + k != 12 { cont...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Simula
Simula
BEGIN   BOOLEAN PROCEDURE ISNUMERIC(W); TEXT W; BEGIN BOOLEAN PROCEDURE MORE; MORE := W.MORE; CHARACTER PROCEDURE NEXT; NEXT := IF MORE THEN W.GETCHAR ELSE CHAR(0); CHARACTER PROCEDURE LAST; LAST := IF W.LENGTH = 0 THEN CHAR(0) ...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Smalltalk
Smalltalk
String extend [ realIsNumeric [ (self first = $+) | (self first = $-) ifTrue: [ ^ (self allButFirst) isNumeric ] ifFalse: [ ^ self isNumeric ] ] ]   { '1234'. "true" '3.14'. '+3.8111'. "true" '+45'. "true" '-3.78'. ...
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Ursala
Ursala
#import int   dot = sum:-0+ product*p   #cast %z   test = dot(<1,3,-5>,<4,-2,-1>)
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#VBA
VBA
Private Function dot_product(x As Variant, y As Variant) As Double dot_product = WorksheetFunction.SumProduct(x, y) End Function   Public Sub main() Debug.Print dot_product([{1,3,-5}], [{4,-2,-1}]) End Sub
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#VTL-2
VTL-2
10 P=2 20 S=1 30 F=1 40 #=0<((P=S)+(P=F)+(S=F)+(P+S+F=12=0))*110 50 ?=P 60 $=32 70 ?=S 80 $=32 90 ?=F 100 ?="" 110 F=F+1 120 #=F<8*40 130 S=S+1 140 #=S<8*30 150 P=P+2 160 #=P<8*20
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#Wren
Wren
System.print("Police Sanitation Fire") System.print("------ ---------- ----") var count = 0 for (h in 1..3) { var i = h * 2 for (j in 1..7) { if (j != i) { for (k in 1..7) { if ((k != i && k != j) && (i + j + k == 12) ) { System.print("  %(i)  %...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#SNOBOL4
SNOBOL4
define('nchk(str)') :(nchk_end) nchk convert(str,'real') :s(return)f(freturn) nchk_end   * # Wrapper for testing define('isnum(str)') :(isnum_end) isnum isnum = 'F'; isnum = nchk(str) 'T' isnum = isnum ': ' str :(return) isnum_end   * # Test and display o...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#SQL
SQL
DECLARE @s VARCHAR(10) SET @s = '1234.56'   print isnumeric(@s) --prints 1 if numeric, 0 if not.   IF isnumeric(@s)=1 BEGIN print 'Numeric' END ELSE print 'Non-numeric'
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#VBScript
VBScript
  WScript.Echo DotProduct("1,3,-5","4,-2,-1")   Function DotProduct(vector1,vector2) arrv1 = Split(vector1,",") arrv2 = Split(vector2,",") If UBound(arrv1) <> UBound(arrv2) Then WScript.Echo "The vectors are not of the same length." Exit Function End If DotProduct = 0 For i = 0 To UBound(arrv1) DotProduct =...
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#XPL0
XPL0
  \Department numbers code CrLf=9, IntIn=10, IntOut=11, Text=12; integer P, S, F;   begin Text(0, "POLICE SANITATION FIRE"); CrLf(0); P:= 2; while P <= 7 do begin for S:= 1, 7 do if S # P then begin F:= (12 - P) - S; if (F > 0) & (F <= 7) & (F # S) & (F # P) then begin Text(0, ...
http://rosettacode.org/wiki/Department_numbers
Department numbers
There is a highly organized city that has decided to assign a number to each of their departments:   police department   sanitation department   fire department Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and mu...
#zkl
zkl
Utils.Helpers.pickNFrom(3,[1..7].walk()) // 35 combos .filter(fcn(numbers){ numbers.sum(0)==12 }) // which all sum to 12 (==5) .println();
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#SQL_PL
SQL PL
  --#SET TERMINATOR @   CREATE OR REPLACE FUNCTION IS_NUMERIC ( IN STRING VARCHAR(10) ) RETURNS SMALLINT -- ) RETURNS BOOLEAN BEGIN DECLARE RET SMALLINT; -- DECLARE RET BOOLEAN; DECLARE TMP INTEGER; DECLARE CONTINUE HANDLER FOR SQLSTATE '22018' SET RET = 1; -- SET RET = FALSE;   SET RET = 0; --...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Standard_ML
Standard ML
(* this function only recognizes integers in decimal format *) fun isInteger s = case Int.scan StringCvt.DEC Substring.getc (Substring.full s) of SOME (_,subs) => Substring.isEmpty subs | NONE => false   fun isReal s = case Real.scan Substring.getc (Substring.full s) of SOME (_,subs) => Substring.isEmpt...
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Visual_Basic
Visual Basic
Option Explicit   Function DotProduct(a() As Long, b() As Long) As Long Dim l As Long, u As Long, i As Long Debug.Assert DotProduct = 0 'return value automatically initialized with 0 l = LBound(a()) If l = LBound(b()) Then u = UBound(a()) If u = UBound(b()) Then For i = l To u DotProduct = D...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Swift
Swift
func isNumeric(a: String) -> Bool { return Double(a) != nil }
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Tcl
Tcl
proc isNumeric str {string is double -strict $str}
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Visual_Basic_.NET
Visual Basic .NET
Module Module1   Function DotProduct(a As Decimal(), b As Decimal()) As Decimal Return a.Zip(b, Function(x, y) x * y).Sum() End Function   Sub Main() Console.WriteLine(DotProduct({1, 3, -5}, {4, -2, -1})) Console.ReadLine() End Sub   End Module
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#TMG
TMG
prog: ignore(<< >>) parse(line)\prog parse(error)\prog; line: number *; number: ignore(none) sign float (exp | ={}) = { < True: > 3 2 1 * }; sign: <+>={} | <->={<->} | ={}; float: int ( <.> decim = { 2 <.> 1 } | = { 1 } ) | <.> int = { <.> 1 }; int: smark any(digit) strin...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Toka
Toka
[ ( string -- flag ) >number nip ] is isNumeric   ( Some tests ) decimal " 100" isNumeric . ( succeeds, 100 is a valid decimal integer ) " 100.21" isNumeric . ( fails, 100.21 is not an integer) " a" isNumeric . ( fails, 'a' is not a valid integer in the decimal base ) " $a" isNumeric . ( succeeds, bec...
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Vlang
Vlang
fn dot(x []int, y []int) ?int { if x.len != y.len { return error("incompatible lengths") } mut r := 0 for i, xi in x { r += xi * y[i] } return r }   fn main() { d := dot([1, 3, -5], [4, -2, -1])?   println(d) }
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Wart
Wart
def (dot_product x y) (sum+map (*) x y)
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#True_BASIC
True BASIC
  DECLARE FUNCTION isnumeric$   LET true$ = "True" LET false$ = "False" LET s$ = "-152.34" PRINT s$, " => "; isnumeric$(s$) LET s$ = "1234.056789" PRINT s$, " => "; isnumeric$(s$) LET s$ = "1234.56" PRINT s$, " => "; isnumeric$(s$) LET s$ = "021101" PRINT s$, " => "; isnumeric$(s$) LET s$ = "Dog" PRINT s$, " => "; isnu...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#UNIX_Shell
UNIX Shell
  #!/bin/bash isnum() { printf "%f" $1 >/dev/null 2>&1 }     check() { if isnum $1 then echo "$1 is numeric" else echo "$1 is NOT numeric" fi }   check 2 check -3 check +45.44 check -33.332 check 33.aa check 3.3.3  
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Wren
Wren
class Vector { construct new(a) { if (a.type != List || a.count == 0 || !a.all { |i| i is Num }) { Fiber.abort("Argument must be a non-empty list of numbers.") } _a = a }   a { _a } length { _a.count }   dot(other) { if (other.type != Vector || length != o...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Ursa
Ursa
def isnum (string str) try double str return true catch valueerror return false end try end isnum
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#VBA
VBA
Sub Main() Debug.Print Is_Numeric("") Debug.Print Is_Numeric("-5.32") Debug.Print Is_Numeric("-51,321 32") Debug.Print Is_Numeric("123.4") Debug.Print Is_Numeric("123,4") Debug.Print Is_Numeric("123;4") Debug.Print Is_Numeric("123.4x") End Sub   Private Function Is_Numeric(s As String) As Bo...
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#X86_Assembly
X86 Assembly
format PE64 console entry start   include 'win64a.inc'   section '.text' code readable executable   start: stdcall dotProduct, vA, vB invoke printf, msg_num, rax   stdcall dotProduct, vA, vC invoke printf, msg_num, rax   invoke ExitProcess, 0   proc dotProduct vectorA...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#VBScript
VBScript
IsNumeric(Expr)
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Vedit_macro_language
Vedit macro language
:IS_NUMERIC: if (Num_Eval(SUPPRESS)==0 && Cur_Char != '0') { Return(FALSE) } else { Return(TRUE) }
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#XPL0
XPL0
include c:\cxpl\codes;   func DotProd(U, V, L); int U, V, L; int S, I; [S:= 0; for I:= 0 to L-1 do S:= S + U(I)*V(I); return S; ];   [IntOut(0, DotProd([1, 3, -5], [4, -2, -1], 3)); CrLf(0); ]
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Yabasic
Yabasic
  sub sq_mul(a(), b(), c()) local n, i   n = arraysize(a(), 1)   for i = 1 to n c(i) = a(i) * b(i) next i end sub   sub sq_sum(a()) local n, i, r   n = arraysize(a(), 1)   for i = 1 to n r = r + a(i) next i return r end sub   dim a(3), b(3), c(3)   a(1) = 1 : a(2) = 3 : a(3) = -5 b(1) = 4 : b(2) = -2 : b(3...
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Visual_Basic_.NET
Visual Basic .NET
Dim Value As String = "+123"   If IsNumeric(Value) Then PRINT "It is numeric." End If
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Vlang
Vlang
import strconv   fn is_numeric(s string) bool { strconv.atof64(s) or { return false } return true }   fn main() { println("Are these strings numeric?") strings := ["1", "3.14", "-100", "1e2", "NaN", "rose", "0xff", "0b110"] for s in strings { println(" ${s:4} -> ${is_numeric(s)}") } }
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#Zig
Zig
const std = @import("std"); const Vector = std.meta.Vector;   pub fn main() !void { const a: Vector(3, i32) = [_]i32{1, 3, -5}; const b: Vector(3, i32) = [_]i32{4, -2, -1}; var dot: i32 = @reduce(.Add, a*b);   try std.io.getStdOut().writer().print("{d}\n", .{dot}); }
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#zkl
zkl
fcn dotp(a,b){Utils.zipWith('*,a,b).sum()}
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Wren
Wren
import "/fmt" for Fmt   System.print("Are these strings numeric?")   for (s in ["1", "3.14", "-100", "1e2", "NaN", "0xaf", "rose"]) { var i = Num.fromString(s) // returns null if 's' is not numeric System.print("  %(Fmt.s(4, s)) -> %((i != null) ? "yes" : "no")") }
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#XLISP
XLISP
(DEFUN NUMERICP (X) (IF (STRING->NUMBER X) T))
http://rosettacode.org/wiki/Dot_product
Dot product
Task Create a function/use an in-built function, to compute the   dot product,   also known as the   scalar product   of two vectors. If possible, make the vectors of arbitrary length. As an example, compute the dot product of the vectors:   [1,  3, -5]     and   [4, -2, -1] If implementing the dot ...
#ZX_Spectrum_Basic
ZX Spectrum Basic
10 DIM a(3): LET a(1)=1: LET a(2)=3: LET a(3)=-5 20 DIM b(3): LET b(1)=4: LET b(2)=-2: LET b(3)=-1 30 LET sum=0 40 FOR i=1 TO 3: LET sum=sum+a(i)*b(i): NEXT i 50 PRINT sum
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#zkl
zkl
fcn isNum(text){ try{ text.toInt(); True } catch{ try{ text.toFloat(); True } catch{ False } } }
http://rosettacode.org/wiki/Determine_if_a_string_is_numeric
Determine if a string is numeric
Task Create a boolean function which takes in a string and tells whether it is a numeric string (floating point and negative numbers included) in the syntax the language uses for numeric literals or numbers converted from strings. Other tasks related to string operations: Metrics Array length String length Cop...
#Zoea
Zoea
  program: numeric case: 1 input: '1' output: true case: 2 input: '-3' output: true case: 3 input: '22.7' output: true case: 4 input: 'a' output: false case: 5 input: 'Fred' output: false case: 6 input: '' output: false  
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#ALGOL_68
ALGOL 68
BEGIN # find repunits (all digits are 1 ) such that R(n-1) is divisible by n and n is not prime # # R(n) is the nth repunit, so has n 1s # PR precision 8000 PR # set precision of LONG LONG INT, enough for up to R(8000) # PR read "primes.incl.a...
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Arturo
Arturo
deceptive?: function [n][ and? -> not? prime? n -> zero? (to :integer repeat "1" n-1) % n ]   cnt: 0 i: 3   while [cnt < 10][ if deceptive? i [ print i cnt: cnt + 1 ] i: i + 2 ]
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#C.2B.2B
C++
#include <gmpxx.h>   #include <iomanip> #include <iostream>   bool is_prime(int n) { if (n < 2) return false; if (n % 2 == 0) return n == 2; if (n % 3 == 0) return n == 3; for (int p = 5; p * p <= n; p += 4) { if (n % p == 0) return false; p += 2; ...
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#F.23
F#
  // Deceptive numbers. Nigel Galloway: February 13th., 2022 Seq.unfold(fun n->Some(n|>Seq.filter(isPrime>>not)|>Seq.filter(fun n->(10I**(n-1)-1I)%(bigint n)=0I),n|>Seq.map((+)30)))(seq{1;7;11;13;17;19;23;29})|>Seq.concat|>Seq.skip 1 |>Seq.chunkBySize 10|>Seq.take 7|>Seq.iter(fun n->n|>Array.iter(printf "%7d "); printf...
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Factor
Factor
USING: io kernel lists lists.lazy math math.functions math.primes prettyprint ;   : repunit ( m -- n ) 10^ 1 - 9 / ;   : composite ( -- list ) 4 lfrom [ prime? not ] lfilter ;   : deceptive ( -- list ) composite [ [ 1 - repunit ] keep divisor? ] lfilter ;   10 deceptive ltake [ pprint bl ] leach nl
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Fermat
Fermat
Func Rep(n)=Sigma<m=0,n-1>[10^m].; c:=0; n:=3; while c<10 do n:=n+1; if Isprime(n)>1 and Divides(n,Rep(n-1)) then !!n; c:+; fi od;
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Go
Go
package main   import ( "fmt" "math/big" "rcu" )   func main() { count := 0 limit := 25 n := int64(17) repunit := big.NewInt(1111111111111111) t := new(big.Int) zero := new(big.Int) eleven := big.NewInt(11) hundred := big.NewInt(100) var deceptive []int64 for count < ...
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#J
J
R=: (10x #. #&1)"0 deceptive=: 1&p: < 0 = ] | R@<:   2+I.deceptive 2+i.10000 91 259 451 481 703 1729 2821 2981 3367 4141 4187 5461 6533 6541 6601 7471 7777 8149 8401 8911 10001
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Julia
Julia
using Primes   function deceptives(numwanted) n, r, ret = 2, big"1", Int[] while length(ret) < numwanted  !isprime(n) && r % n == 0 && push!(ret, n) n += 1 r = 10r + 1 end return ret end   @time println(deceptives(30))  
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#Mathematica.2FWolfram_Language
Mathematica/Wolfram Language
ClearAll[DeceptiveNumberQ] DeceptiveNumberQ[n_Integer] := If[! PrimeQ[n], PowerMod[10, n - 1, 9 n] == 1] c = 0; out = Reap[Do[ If[DeceptiveNumberQ[i], Sow[i]; c++; If[c >= 1000, Break[]] ] , {i, 2, \[Infinity]} ]][[2, 1]]; Print["The first 100:"] Multicolumn[Take[out, 100], A...
http://rosettacode.org/wiki/Deceptive_numbers
Deceptive numbers
Repunits are numbers that consist entirely of repetitions of the digit one (unity). The notation Rn symbolizes the repunit made up of n ones. Every prime p larger than 5, evenly divides the repunit Rp-1. E.G. The repunit R6 is evenly divisible by 7. 111111 / 7 = 15873 The repunit R42 is evenly divisible by 43. 1...
#PARI.2FGP
PARI/GP
Rep(n)=sum(X=0,n-1,10^X) c=0 n=4 while(c<10,if(!isprime(n)&&Rep(n-1)%n==0,c=c+1;print(n));n=n+1)