Two identical strings: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 11:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F bits(=n)
‘Count the amount of bits required to represent n’
V r = 0
Line 26:
L concat(n) <= 1000
print(‘#.: #.’.format(concat(n), bin(concat(n))))
n++</langsyntaxhighlight>
 
{{out}}
Line 63:
 
=={{header|8080 Assembly}}==
<langsyntaxhighlight lang="8080asm"> ;;; Print positive integers whose base-2 representation
;;; is the concatenation of two identical binary strings,
;;; for 1 < n < 1000
Line 152:
db '***********'
outbuf: db 9,'$'
nl: db 13,10,'$'</langsyntaxhighlight>
 
{{out}}
Line 188:
 
=={{header|8086 Assembly}}==
<langsyntaxhighlight lang="asm">puts: equ 9
cpu 8086
org 100h
Line 241:
nl: db 13,10,'$'
db '****************'
outbuf: db 9,'$'</langsyntaxhighlight>
{{out}}
<pre>3 11
Line 275:
 
=={{header|Action!}}==
<langsyntaxhighlight Actionlang="action!">INT FUNC Encode(INT x CHAR ARRAY s)
BYTE len,i
CHAR tmp
Line 310:
i==+1 count==+1
OD
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Two_identical_strings.png Screenshot from Atari 8-bit computer]
Line 332:
 
=={{header|Ada}}==
<langsyntaxhighlight Adalang="ada">with Ada.Text_Io; use Ada.Text_Io;
with Ada.Strings.Fixed; use Ada.Strings.Fixed;
 
Line 353:
end if;
end loop;
end Two_Identical;</langsyntaxhighlight>
{{out}}
<pre> 3 2#11#
Line 387:
 
=={{header|ALGOL 68}}==
<langsyntaxhighlight lang="algol68">BEGIN # show the decimal and binary representations of numbers that are of the concatenation of #
# two identical binary strings #
# returns a binary representation of v #
Line 410:
print( ( whole( cat value, -4 ), ": ", TOBINSTRING cat value, newline ) )
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 446:
 
=={{header|ALGOL-M}}==
<langsyntaxhighlight lang="algolm">begin
integer function concatself(n);
integer n;
Line 478:
m := concatself(n);
end;
end</langsyntaxhighlight>
{{out}}
<pre> 3: 11
Line 513:
=={{header|ALGOL W}}==
{{Trans|MAD}}
<langsyntaxhighlight lang="oberon2">BEGIN
INTEGER PROCEDURE BITSP ( INTEGER VALUE BT ) ;
BEGIN
Line 550:
END DO WRITE( S_W := 0, I_W := 3, DPLBIT(N), ": ", I_W := 10, BITSP(DPLBIT(N)) )
END
END.</langsyntaxhighlight>
{{out}}
<pre>
Line 587:
=={{header|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight APLlang="apl">↑(((⊂2∘⊥),⊂)(,⍨2∘⊥⍣¯1))¨⍳30</langsyntaxhighlight>
{{out}}
<pre> 3 1 1
Line 624:
Drawing members of the sequence from a non-finite list,
up to a given limit.
<langsyntaxhighlight lang="applescript">------ CONCATENATION OF TWO IDENTICAL BINARY STRINGS -----
 
-- binaryTwin :: Int -> (Int, String)
Line 809:
set my text item delimiters to dlm
s
end unlines</langsyntaxhighlight>
{{Out}}
<pre>3 -> 11
Line 843:
----
===Idiomatic===
<langsyntaxhighlight lang="applescript">on task(maxN)
set startWith0 to false -- Change to true to start with 0 and "00".
set rhv to -(startWith0 as integer) -- Start value of "right hand" string.
Line 877:
end task
 
task(999)</langsyntaxhighlight>
 
{{output}}
<langsyntaxhighlight lang="applescript">"3: 11
10: 1010
15: 1111
Line 909:
924: 1110011100
957: 1110111101
990: 1111011110"</langsyntaxhighlight>
 
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">loop 0..1000 'i [
bin: as.binary i
if even? size bin [
Line 921:
print [pad to :string i 4 ":" bin]
]
]</langsyntaxhighlight>
 
{{out}}
Line 957:
 
=={{header|AutoHotkey}}==
<syntaxhighlight lang="autohotkey">n:=0
<lang AutoHotkey>n:=0
while (n++<=1000)
{
Line 975:
b := u ^ 1 & i // (1 << c++) . b
Return, b
}</langsyntaxhighlight>
{{out}}
<pre>3 11
Line 1,009:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f TWO_IDENTICAL_STRINGS.AWK
BEGIN {
Line 1,035:
return(str)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,072:
 
=={{header|BASIC}}==
<langsyntaxhighlight BASIClang="basic">10 DEFINT A-Z: DIM B(15)
20 N=0
30 N=N+1
Line 1,090:
170 NEXT I
180 PRINT
190 GOTO 30</langsyntaxhighlight>
{{out}}
<pre> 3 11
Line 1,124:
 
==={{header|BASIC256}}===
<langsyntaxhighlight lang="freebasic">n = 1
k = 0
p = 2
Line 1,133:
if k < 1000 then print k; " = "; tobinary(k) else end
n += 1
end while</langsyntaxhighlight>
 
==={{header|QBasic}}===
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<langsyntaxhighlight QBasiclang="qbasic">FUNCTION tobin$ (d)
s$ = ""
DO WHILE d <> 0
Line 1,158:
END IF
n = n + 1
LOOP</langsyntaxhighlight>
 
==={{header|PureBasic}}===
<langsyntaxhighlight PureBasiclang="purebasic">OpenConsole()
n.i = 1
k.i = 0
Line 1,181:
Input()
CloseConsole()
</syntaxhighlight>
</lang>
 
==={{header|True BASIC}}===
<langsyntaxhighlight QBasiclang="qbasic">FUNCTION tobin$(d)
LET s$ = ""
DO WHILE d <> 0
Line 1,207:
LET n = n+1
LOOP
END</langsyntaxhighlight>
 
 
=={{header|BCPL}}==
<langsyntaxhighlight lang="bcpl">get "libhdr"
 
let bitlength(n) = n=0 -> 0, 1 + bitlength(n >> 1)
Line 1,230:
conc := concat(n,n)
$)
$)</langsyntaxhighlight>
{{out}}
<pre> 3: 11
Line 1,264:
 
=={{header|Befunge}}==
<langsyntaxhighlight lang="befunge">1>:::>:#v_++:91+v
>^ / >\vv**::<
^2\*2<>`#@_v
Line 1,272:
1:^
$!,
^_^</langsyntaxhighlight>
{{out}}
<pre>3 11
Line 1,306:
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdint.h>
 
Line 1,335:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 1,372:
=={{header|C#|CSharp}}==
{{trans|Visual Basic .NET}}
<langsyntaxhighlight lang="csharp">using System; using static System.Console;
class Program { static void Main() { int c = 0, lmt = 1000;
for (int n = 1, p = 2, k; n <= lmt; n++)
Line 1,379:
Convert.ToString(k, 2), ++c % 5 == 0 ? "\n" : "");
Write("\nFound {0} numbers whose base 2 representation is the " +
"concatenation of two identical binary strings.", c); } }</langsyntaxhighlight>
{{out}}
Same as Visual Basic. NET
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <string>
 
Line 1,411:
base2_increment(s);
}
}</langsyntaxhighlight>
 
{{out}}
Line 1,449:
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">nth_ident = proc (n: int) returns (int)
h: int := n
l: int := n
Line 1,472:
stream$putl(po, ": " || bits(ident))
end
end start_up</langsyntaxhighlight>
{{out}}
<pre> 3: 11
Line 1,506:
 
=={{header|COBOL}}==
<langsyntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. IDENTICAL-STRINGS.
 
Line 1,570:
COMPUTE BIT-VALUE = 2 ** (10 - CURRENT-BIT)
MULTIPLY BIT(CURRENT-BIT) BY BIT-VALUE.
ADD BIT-VALUE TO OUTPUT-NUMBER.</langsyntaxhighlight>
{{out}}
<pre> 3: 11
Line 1,604:
 
=={{header|Cowgol}}==
<langsyntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub bitLength(n: uint32): (l: uint8) is
Line 1,640:
print_nl();
n := n + 1;
end loop;</langsyntaxhighlight>
 
{{out}}
Line 1,677:
=={{header|Crystal}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">(0..1000).each do |i|
bin = i.to_s(2)
if bin.size.even?
Line 1,685:
end
end
end</langsyntaxhighlight>
{{out}}
<pre> 3: 11
Line 1,719:
 
=={{header|Draco}}==
<langsyntaxhighlight lang="draco">proc nonrec concat_self(word n) word:
word rslt, k;
k := n;
Line 1,740:
n := n + 1
od
corp</langsyntaxhighlight>
{{out}}
<pre> 3: 11
Line 1,774:
 
=={{header|F_Sharp|F#}}==
<langsyntaxhighlight lang="fsharp">
// Nigel Galloway. April 5th., 2021
let fN g=let rec fN g=function n when n<2->(char(n+48))::g |n->fN((char(n%2+48))::g)(n/2) in fN [] g|>Array.ofList|>System.String
Seq.unfold(fun(n,g,l)->Some((n<<<l)+n,if n=g-1 then (n+1,g*2,l+1) else (n+1,g,l)))(1,2,1)|>Seq.takeWhile((>)1000)|>Seq.iter(fun g->printfn "%3d %s" g (fN g))
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,815:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: formatting kernel lists lists.lazy math math.parser
sequences ;
 
1 lfrom [ >bin dup append bin> ] lmap-lazy [ 1000 < ] lwhile
[ dup "%d %b\n" printf ] leach</langsyntaxhighlight>
{{out}}
<pre style="height:14em">
Line 1,855:
 
=={{header|FALSE}}==
<langsyntaxhighlight FALSElang="false">1[$$$[$][2/\2*\]#%|$1000>~][
$.": "
0\10\[$1&'0+\2/$][]#%
[$][,]#%
1+
]#%%</langsyntaxhighlight>
 
{{out}}
Line 1,895:
 
=={{header|FOCAL}}==
<langsyntaxhighlight FOCALlang="focal">01.10 S N=0
01.20 S N=N+1
01.30 D 3
Line 1,922:
04.30 I (B(I))4.4,4.5,4.4
04.40 T "1"
04.50 T "0"</langsyntaxhighlight>
 
{{out}}
Line 1,958:
 
=={{header|Forth}}==
<langsyntaxhighlight lang="forth">: concat-self
dup dup
begin dup while
Line 1,985:
;
 
to1000 bye</langsyntaxhighlight>
 
{{out}}
Line 2,021:
 
=={{header|Fortran}}==
<langsyntaxhighlight lang="fortran"> program IdentStr
implicit none
integer n, concat, bits
Line 2,059:
goto 100
end if
end</langsyntaxhighlight>
{{out}}
<pre> 3 11
Line 2,093:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">dim as uinteger n=1, k=0
do
k = n + 2*n*2^int(log(n)/log(2))
if k<1000 then print k, bin(k) else end
n=n+1
loop</langsyntaxhighlight>
{{out}}
<pre>3 11
Line 2,133:
===Alternate===
No ''log()'' function required.
<langsyntaxhighlight lang="freebasic">dim as uinteger n = 1, k = 0, p = 2
do
if n >= p then p = p + p
Line 2,139:
if k < 1000 then print k, bin(k) else end
n = n + 1
loop</langsyntaxhighlight>
{{out}}
Same as ''log()'' version.
 
=={{header|Frink}}==
<langsyntaxhighlight lang="frink">for n = 1 to 999
if base2[n] =~ %r/^(\d+)\1$/
println["$n\t" + base2[n]]</langsyntaxhighlight>
{{out}}
<pre>
Line 2,184:
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 2,204:
}
fmt.Println("\nFound", i-1, "numbers.")
}</langsyntaxhighlight>
 
{{out}}
Line 2,244:
=={{header|Haskell}}==
===Data.Bits===
<langsyntaxhighlight lang="haskell">import Control.Monad (join)
import Data.Bits
( countLeadingZeros,
Line 2,272:
map (join $ printf "%d: %b") to1000
where
to1000 = takeWhile (<= 1000) identStrInts</langsyntaxhighlight>
 
{{out}}
Line 2,309:
===Data.Char===
As an alternative to Data.Bits, we could also express this in terms of Data.Char
<langsyntaxhighlight lang="haskell">import Control.Monad (join)
import Data.Char (digitToInt, intToDigit)
import Numeric (showIntAtBase)
Line 2,337:
(\c (e, n) -> (2 * e, digitToInt c * e + n))
(1, 0)
s</langsyntaxhighlight>
<pre>(3,"11")
(10,"1010")
Line 2,370:
 
=={{header|J}}==
<langsyntaxhighlight Jlang="j">(":,': ',":@#:)@(,~&.#:)"0 (>:i.30)</langsyntaxhighlight>
{{out}}
<pre>3: 1 1
Line 2,404:
 
=={{header|Java}}==
<langsyntaxhighlight lang="java">public class TwoIdenticalStrings {
public static void main(String[] args) {
System.out.println("Decimal Binary");
Line 2,417:
}
}
}</langsyntaxhighlight>
{{out}}
<pre>Decimal Binary
Line 2,454:
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<syntaxhighlight lang="jq">
<lang jq>
def binary_digits:
if . == 0 then 0
Line 2,470:
| select(.[$half:] == .[:$half])
| [$i, .]
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 2,504:
[990,"1111011110"]</pre>
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">function twoidenticalstringsinbase(base, maxnum, verbose=true)
found = Int[]
for i in 1:maxnum
Line 2,522:
twoidenticalstringsinbase(2, 999)
twoidenticalstringsinbase(16, 999)
</langsyntaxhighlight>{{out}}
<pre>
Decimal Base 2
Line 2,575:
 
=== Generator version ===
<langsyntaxhighlight lang="julia">function twoidenticalstringsinbase(base, mx, verbose = true)
gen = filter(x -> x < mx,
reduce(vcat, [[i * (base^d + 1) for i in base^(d-1):base^d-1] for d in 1:ndigits(mx; base) ÷ 2]))
Line 2,587:
twoidenticalstringsinbase(2, 999)
twoidenticalstringsinbase(16, 999)
</langsyntaxhighlight>{{out}}<pre>Same as filter version above.</pre>
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="liberty basic">maxNumber = 1000
maxN = Int(Len(DecToBin$(maxNumber))/ 2)
Print "Value"," Binary"
Line 2,609:
Wend
If (DecToBin$ = "") Then DecToBin$ = "0"
End Function</langsyntaxhighlight>
 
{{out}}
Line 2,646:
 
=={{header|MAD}}==
<langsyntaxhighlight MADlang="mad"> NORMAL MODE IS INTEGER
INTERNAL FUNCTION(BT)
Line 2,679:
 
VECTOR VALUES NFMT = $I3,2H: ,I10*$
END OF PROGRAM </langsyntaxhighlight>
{{out}}
<pre> 3: 11
Line 2,713:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">max = 1000;
maxbin = Ceiling[Ceiling[Log2[max]]/2];
s = Table[
Line 2,722:
{i, 2^maxbin - 1}
];
Select[s, First/*LessThan[1000]] // Grid</langsyntaxhighlight>
{{out}}
<pre>3 11
Line 2,756:
 
=={{header|Modula-2}}==
<langsyntaxhighlight lang="modula2">MODULE IdenticalStrings;
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
 
Line 2,788:
INC(n);
END;
END IdenticalStrings.</langsyntaxhighlight>
{{out}}
<pre> 3: 11
Line 2,822:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import strformat
 
func isConcat(s: string): bool =
Line 2,831:
for n in 0..999:
let b = &"{n:b}"
if b.isConcat: echo &"{n:3} {b}"</langsyntaxhighlight>
 
{{out}}
Line 2,867:
=={{header|Pascal}}==
{{works with|Turbo Pascal}}
<langsyntaxhighlight lang="pascal">program IdenticalStrings;
const
LIMIT = 1000;
Line 2,912:
n := n + 1;
end;
end.</langsyntaxhighlight>
 
{{out}}
Line 2,948:
 
=={{header|PL/I}}==
<langsyntaxhighlight lang="pli">identstr: procedure options(main);
bitLength: procedure(nn) returns(fixed);
declare (n, nn, r) fixed;
Line 2,985:
call printBits(concat(n,n));
end;
end identstr;</langsyntaxhighlight>
{{out}}
<pre> 3 11
Line 3,019:
 
=={{header|PL/M}}==
<langsyntaxhighlight lang="plm">100H:
 
/* BINARY CONCATENATION OF A NUMBER WITH ITSELF */
Line 3,070:
 
CALL BDOS(0,0);
EOF</langsyntaxhighlight>
{{out}}
<pre>3 11
Line 3,105:
=={{header|Python}}==
===Python: Procedural===
<langsyntaxhighlight lang="python">def bits(n):
"""Count the amount of bits required to represent n"""
r = 0
Line 3,120:
while concat(n) <= 1000:
print("{0}: {0:b}".format(concat(n)))
n += 1</langsyntaxhighlight>
 
{{out}}
Line 3,159:
 
Values are drawn, up to a limit, from a non-finite list.
<langsyntaxhighlight lang="python">'''Two identical strings'''
 
from itertools import count, takewhile
Line 3,192:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>(3, '11')
Line 3,226:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict; # https://rosettacode.org/wiki/Two_identical_strings
Line 3,236:
(my $decimal = oct "b$binary") >= 1000 and last;
printf "%4d %s\n", $decimal, $binary;
}</langsyntaxhighlight>
{{out}}
<pre>
Line 3,272:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #004080;">integer</span> <span style="color: #000000;">n</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">1</span>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{}</span>
Line 3,283:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"Found %d numbers:\n%s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">n</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">join_by</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">,</span><span style="color: #000000;">6</span><span style="color: #0000FF;">)})</span>
<!--</langsyntaxhighlight>-->{{out}}
<pre>
Found 30 numbers:
Line 3,294:
 
=={{header|Picat}}==
<langsyntaxhighlight Picatlang="picat">main =>
bp.length(_L,I),
I > 0,
Line 3,301:
parse_radix_string(BB,2) = Dec,
( Dec < 1000 -> printf("%4w %10w\n",Dec,BB), fail ; true),
nl.</langsyntaxhighlight>
 
{{out}}
Line 3,337:
=={{header|Prolog}}==
{{works with|SWI Prolog}}
<langsyntaxhighlight lang="prolog">main:-
writeln('Decimal\tBinary'),
main(1, 1000).
Line 3,350:
N1 is N + 1,
main(N1, Limit).
main(_, _).</langsyntaxhighlight>
 
{{out}}
Line 3,389:
=={{header|Quackery}}==
 
<langsyntaxhighlight Quackerylang="quackery"> [ 2 base put
number$ dup size 2 / split =
base release ] is 2identical ( n --> b )
Line 3,398:
2 base put
i^ echo cr
base release ] ] </langsyntaxhighlight>
 
{{out}}
Line 3,435:
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>my @cat = (1..*).map: { :2([~] .base(2) xx 2) };
say "{+$_} matching numbers\n{.batch(5)».map({$_ ~ .base(2).fmt('(%s)')})».fmt('%15s').join: "\n"}\n"
given @cat[^(@cat.first: * > 1000, :k)];</langsyntaxhighlight>
{{out}}
<pre>30 matching numbers
Line 3,449:
=={{header|REXX}}==
=== sans formatting ===
<syntaxhighlight lang="text">/*REXX program finds/displays decimal numbers whose binary version is a doubled literal.*/
numeric digits 20 /*ensure 'nuff dec. digs for conversion*/
do #=1 for 1000-1; b= x2b( d2x(#) ) + 0 /*find binary values that can be split.*/
Line 3,455:
if left(b, L%2)\==right(b, L%2) then iterate /*Left half ≡ right half? No, skip it.*/
say right(#, 4)':' right(b, 12) /*display number in decimal and binary.*/
end /*#*/ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; (shown at three-quarter size.)}}
<pre style="font-size:75%">
Line 3,491:
 
=== with formatting ===
<langsyntaxhighlight lang="rexx">/*REXX program finds/displays decimal numbers whose binary version is a doubled literal.*/
numeric digits 100 /*ensure hangling of larger integers. */
parse arg hi cols . /*obtain optional argument from the CL.*/
Line 3,522:
exit 0 /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
commas: parse arg ?; do jc=length(?)-3 to 1 by -3; ?=insert(',', ?, jc); end; return ?</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 3,541:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">load "stdlib.ring"
decList = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
Line 3,594:
s = string(x) l = len(s)
if l > y y = l ok
return substr(" ", 11 - y + l) + s</langsyntaxhighlight>
{{out}}
<pre>working...
Line 3,610:
=={{header|Ruby}}==
{{trans|C}}
<langsyntaxhighlight lang="ruby">for i in 0 .. 1000
bin = i.to_s(2)
if bin.length % 2 == 0 then
Line 3,618:
end
end
end</langsyntaxhighlight>
{{out}}
<pre> 3: 11
Line 3,652:
 
=={{header|Snobol}}==
<langsyntaxhighlight lang="snobol"> define("bits(n)") :(bits_end)
bits bits = gt(n,0) remdr(n,2) bits :f(return)
n = n / 2 :(bits)
Line 3,669:
m = concat(n)
output = lt(m,1000) m ": " bits(m) :s(loop)
end</langsyntaxhighlight>
{{out}}
<pre>3: 11
Line 3,703:
 
=={{header|Swift}}==
<langsyntaxhighlight lang="swift">print("Decimal\tBinary")
var n = 1
while (true) {
Line 3,713:
print("\(i)\t\(binary)\(binary)")
n += 1
}</langsyntaxhighlight>
 
{{out}}
Line 3,752:
=={{header|Visual Basic .NET}}==
{{trans|FreeBASIC}}Based on the Alternate version.
<langsyntaxhighlight lang="vbnet">Imports System.Console
Module Module1
Sub Main()
Line 3,763:
Next : WriteLine(vbLf + "Found {0} numbers whose base 2 representation is the concatenation of two identical binary strings.", c)
End Sub
End Module</langsyntaxhighlight>
{{out}}
<pre> 3 (11 ) 10 (1010 ) 15 (1111 ) 36 (100100 ) 45 (101101 )
Line 3,776:
=={{header|Vlang}}==
{{trans|Go}}
<langsyntaxhighlight lang="vlang">import strconv
fn main() {
Line 3,791:
}
println("\nFound ${i-1} numbers.")
}</langsyntaxhighlight>
 
{{out}}
Line 3,832:
=={{header|Wren}}==
{{libheader|Wren-fmt}}
<langsyntaxhighlight lang="ecmascript">import "/fmt" for Conv, Fmt
 
var i = 1
Line 3,843:
i = i + 1
}
System.print("\nFound %(i-1) numbers.")</langsyntaxhighlight>
 
{{out}}
Line 3,882:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">proc BinOut(N); \Output N in binary
int N, Rem;
[Rem:= N&1;
Line 3,903:
];
];
]</langsyntaxhighlight>
 
{{out}}
Line 3,940:
 
=={{header|Yabasic}}==
<langsyntaxhighlight Yabasiclang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Two_identical_strings
// by Galileo, 04/2022
 
Line 3,949:
if left$(n$, k) = right$(n$, k) print n, " = ", n$
endif
next</langsyntaxhighlight>
{{out}}
<pre>3 = 11
10,327

edits