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/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Swift
Swift
import Foundation   func printTopWords(path: String, count: Int) throws { // load file contents into a string let text = try String(contentsOfFile: path, encoding: String.Encoding.utf8) var dict = Dictionary<String, Int>() // split text into words, convert to lowercase and store word counts in dict ...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Seed7
Seed7
$ include "seed7_05.s7i";   const func string: wrap (in string: aText, in integer: lineWidth) is func result var string: wrapped is ""; local var array string: words is 0 times ""; var string: word is ""; var integer: spaceLeft is 0; begin words := split(aText, " "); if length(words) <> 0 ...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Sidef
Sidef
class String { method wrap(width) { var txt = self.gsub(/\s+/, " "); var len = txt.len; var para = []; var i = 0; while (i < len) { var j = (i + width); while ((j < len) && (txt.char_at(j) != ' ')) { --j }; para.append(txt.substr(i, j-i)); ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#ProDOS
ProDOS
enableextensions enabledelayedexpansion editvar /newvar /value=0 /title=closed editvar /newvar /value=1 /title=open editvar /newvar /range=1-100 /increment=1 /from=2 editvar /newvar /value=2 /title=next :doors for /alloccurrences (!next!-!102!) do editvar /modify /value=-open- editvar /modify /value=-next-=+1 if -next...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Standard_ML
Standard ML
  val getTime = fn url => let val fname = "/tmp/fConv" ^ (String.extract (Time.toString (Posix.ProcEnv.time()),7,NONE) ); val shellCommand = " fetch -o - \""^ url ^"\" | sed -ne 's/^.*alt=.Los Angeles:\\(.* (Daylight Saving)\\).*$/\\1/p' " ; val me = ( Posix.FileSys.mkfifo ...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Tcl
Tcl
package require http   set request [http::geturl "http://tycho.usno.navy.mil/cgi-bin/timer.pl"] if {[regexp -line {<BR>(.* UTC)} [http::data $request] --> utc]} { puts $utc }
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Tcl
Tcl
lassign $argv head while { [gets stdin line] >= 0 } { foreach word [regexp -all -inline {[A-Za-z]+} $line] { dict incr wordcount [string tolower $word] } }   set sorted [lsort -stride 2 -index 1 -int -decr $wordcount] foreach {word count} [lrange $sorted 0 [expr {$head * 2 - 1}]] { puts "$count\t$wo...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Standard_ML
Standard ML
fun wordWrap n s = let fun appendLine (line, text) = text ^ line ^ "\n" fun wrap (word, prev as (line, text)) = if size line + 1 + size word > n then (word, appendLine prev) else (line ^ " " ^ word, text) in case String.tokens Char.isSpace s of [] => "" | (w :: ws) => a...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Tcl
Tcl
package require Tcl 8.5   proc wrapParagraph {n text} { regsub -all {\s+} [string trim $text] " " text set RE "^(.{1,$n})(?:\\s+(.*))?$" for {set result ""} {[regexp $RE $text -> line text]} {} { append result $line "\n" } return [string trimright $result "\n"] }   set txt \ "In olden times when...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Prolog
Prolog
main :- forall(between(1,100,Door), ignore(display(Door))).   % show output if door is open after the 100th pass display(Door) :- status(Door, 100, open), format("Door ~d is open~n", [Door]).   % true if Door has Status after Pass is done status(Door, Pass, Status) :- Pass > 0, Remainder is Door mod...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#ToffeeScript
ToffeeScript
e, page = require('request').get! 'http://tycho.usno.navy.mil/cgi-bin/timer.pl' l = line for line in page.body.split('\n') when line.indexOf('UTC')>0 console.log l.substr(4,l.length-20)
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT SET time = REQUEST ("http://tycho.usno.navy.mil/cgi-bin/timer.pl") SET utc = FILTER (time,":*UTC*:",-)  
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#TMG
TMG
/* Input format: N text */ /* Only lowercase letters can constitute a word in text. */ /* (c) 2020, Andrii Makukha, 2-clause BSD licence. */   progrm: readn/error table(freq) table(chain) [firstword = ~0] loop: not(!<<>>) output | [j=777] batch...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#UNIX_Shell
UNIX Shell
#!/bin/sh <"$1" tr -cs A-Za-z '\n' | tr A-Z a-z | LC_ALL=C sort | uniq -c | sort -rn | head -n "$2"
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#TPP
TPP
The kings youngest daughter was so beautiful that the sun itself, which has seen so much, was astonished whenever it shone in her face.
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT text="In olden times when wishing still helped one, there lived a king whose daughters were all beautiful, but the youngest was so beautiful that the sun itself, which has seen so much, was astonished whenever it shone in her face. Close by the king's castle lay a great dark forest, and under an old...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Pure
Pure
using system;   // initialize doors as pairs: number, status where 0 means open let doors = zip (1..100) (repeat 1);   toogle (x,y) = x,~y;   toogleEvery n d = map (tooglep n) d with tooglep n d@((x,_)) = toogle d if ~(x mod n); = d otherwise; end;   // show d...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#TXR
TXR
@(next @(open-command "wget -c http://tycho.usno.navy.mil/cgi-bin/timer.pl -O - 2> /dev/null")) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final"//EN> <html> <body> <TITLE>What time is it?</TITLE> <H2> US Naval Observatory Master Clock Time</H2> <H3><PRE> @(collect :vars (MO DD HH MM SS (PM " ") TZ TZNAME)) <BR>@MO. ...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#UNIX_Shell
UNIX Shell
#!/bin/sh curl -s http://tycho.usno.navy.mil/cgi-bin/timer.pl | sed -ne 's/^<BR>\(.* UTC\).*$/\1/p'
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#VBA
VBA
  Option Explicit   Private Const PATHFILE As String = "C:\HOME\VBA\ROSETTA"   Sub Main() Dim arr Dim Dict As Object Dim Book As String, temp As String Dim T# T = Timer Book = ExtractTxt(PATHFILE & "\les miserables.txt") temp = RemovePunctuation(Book) temp = UCase(temp) arr = Split(temp, " ") Set Dict = ...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#VBScript
VBScript
  column = 60 text = "In olden times when wishing still helped one, there lived a king " &_ "whose daughters were all beautiful, but the youngest was so beautiful "&_ "that the sun itself, which has seen so much, was astonished whenever "&_ "it shone-in-her-face. Close-by-the-king's castle lay a great dark...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Pure_Data
Pure Data
100Doors.pd   #N canvas 241 375 414 447 10; #X obj 63 256 expr doors[$f1] = doors[$f1] ^ 1; #X msg 83 118 \; doors const 0; #X msg 44 66 bang; #X obj 44 92 t b b b; #X obj 43 28 table doors 101; #X obj 44 360 sel 0; #X obj 44 336 expr if (doors[$f1] == 1 \, $f1 \, 0); #X obj 63 204 t b f f; #X text 81 66 run; #X obj 71...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Ursala
Ursala
#import std #import cli   #executable ('parameterized','')   whatime =   <.file$[contents: --<''>]>+ -+ @hm skip/*4+ ~=(9%cOi&)-~l*+ *~ ~&K3/'UTC', (ask bash)/0+ -[wget -O - http://tycho.usno.navy.mil/cgi-bin/timer.pl]-!+-
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#VBA
VBA
Rem add Microsoft VBScript Regular Expression X.X to your Tools References   Function GetUTC() As String Url = "http://tycho.usno.navy.mil/cgi-bin/timer.pl" With CreateObject("MSXML2.XMLHTTP.6.0") .Open "GET", Url, False .send arrt = Split(.responseText, vbLf) End With For Each t...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#Wren
Wren
import "io" for File import "/str" for Str import "/sort" for Sort import "/fmt" for Fmt import "/pattern" for Pattern   var fileName = "135-0.txt" var text = File.read(fileName).trimEnd() var groups = {} // match runs of A-z, a-z, 0-9 and any non-ASCII letters with code-points < 256 var p = Pattern.new("+1&w") var lin...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Vlang
Vlang
fn wrap(text string, line_width int) string { mut wrapped := '' words := text.fields() if words.len == 0 { return wrapped } wrapped = words[0] mut space_left := line_width - wrapped.len for word in words[1..] { if word.len+1 > space_left { wrapped += "\n" + word ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#PureBasic
PureBasic
Dim doors.i(100)   For x = 1 To 100 y = x While y <= 100 doors(y) = 1 - doors(y) y + x Wend Next   OpenConsole() PrintN("Following Doors are open:") For x = 1 To 100 If doors(x) Print(Str(x) + ", ") EndIf Next Input()
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#VBScript
VBScript
Function GetUTC() As String Url = "http://tycho.usno.navy.mil/cgi-bin/timer.pl" With CreateObject("MSXML2.XMLHTTP.6.0") .Open "GET", Url, False .send arrt = Split(.responseText, vbLf) End With For Each t In arrt If InStr(t, "UTC") Then GetUTC = StripHttpTags(t...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Visual_Basic_.NET
Visual Basic .NET
Imports System.Net Imports System.IO Dim client As WebClient = New WebClient() Dim content As String = client.DownloadString("http://tycho.usno.navy.mil/cgi-bin/timer.pl") Dim sr As New StringReader(content) While sr.peek <> -1 Dim s As String = sr.ReadLine If s.C...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#XQuery
XQuery
let $maxentries := 10, $uri := 'https://www.gutenberg.org/files/135/135-0.txt' return <words in="{$uri}" top="{$maxentries}"> { ( let $doc := unparsed-text($uri), $tokens := ( tokenize($doc, '\W+')[normalize-space()]  ! lower-case(.)  ! normalize-unicode(., 'NFC')...
http://rosettacode.org/wiki/Word_frequency
Word frequency
Task Given a text file and an integer   n,   print/display the   n   most common words in the file   (and the number of their occurrences)   in decreasing frequency. For the purposes of this task:   A word is a sequence of one or more contiguous letters.   You are free to define what a   letter   is.   Undersc...
#zkl
zkl
fname,count := vm.arglist; // grab cammand line args   // words may have leading or trailing "_", ie "the" and "_the" File(fname).pump(Void,"toLower", // read the file line by line and hash words RegExp("[a-z]+").pump.fp1(Dictionary().incV)) // line-->(word:count,..) .toList().copy().sort(fcn(a,b){ b[1]<a[1] })...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Wren
Wren
var greedyWordWrap = Fn.new { |text, lineWidth| var words = text.split(" ") var sb = words[0] var spaceLeft = lineWidth - words[0].count for (word in words.skip(1)) { var len = word.count if (len + 1 > spaceLeft) { sb = sb + "\n" + word spaceLeft = lineWidth - len...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Pyret
Pyret
  data Door: | open | closed end   fun flip-door(d :: Door) -> Door: cases(Door) d: | open => closed | closed => open end end     fun flip-doors(doors :: List<Door>) -> List<Door>: doc:```Given a list of door positions, repeatedly switch the positions of every nth door for every nth pass, and re...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Wren
Wren
/* web_scraping.wren */   import "./pattern" for Pattern   var CURLOPT_URL = 10002 var CURLOPT_FOLLOWLOCATION = 52 var CURLOPT_WRITEFUNCTION = 20011 var CURLOPT_WRITEDATA = 10001   var BUFSIZE = 16384   foreign class Buffer { construct new(size) {}   // returns buffer contents as a string foreign value }   ...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#XPL0
XPL0
string 0; proc WordWrap(Text, LineWidth); \Display Text string wrapped at LineWidth char Text, LineWidth, Word, SpaceLeft, WordWidth, I; [SpaceLeft:= 0; loop [loop [if Text(0) = 0 then return; \skip whitespace (like CR) if Text(0) > $20 then quit; Text:= Text+1; ...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#Yabasic
Yabasic
t$ = "In olden times when wishing still helped one, there lived a king " t$ = t$ + "whose daughters were all beautiful, but the youngest was so beautiful " t$ = t$ + "that the sun itself, which has seen so much, was astonished whenever " t$ = t$ + "it shone in her face.\n\n" t$ = t$ + t$   t$ = trim$(t$)   input "Width...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Python
Python
  doors = [False] * 100 for i in range(100): for j in range(i, 100, i+1): doors[j] = not doors[j] print("Door %d:" % (i+1), 'open' if doors[i] else 'close')  
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#Xidel
Xidel
$ xidel -s "https://www.rosettacode.org/wiki/Talk:Web_scraping" -e ' //p[1]/text()[last()] ' 20:53, 20 August 2008 (UTC)   $ xidel -s "https://www.rosettacode.org/wiki/Talk:Web_scraping" -e ' x:parse-dateTime(//p[1]/text()[last()],'hh:nn, dd mmmm yyyy') ' 2008-08-20T20:53:00   $ xidel -s "https://www.rosettacode.o...
http://rosettacode.org/wiki/Web_scraping
Web scraping
Task Create a program that downloads the time from this URL:   http://tycho.usno.navy.mil/cgi-bin/timer.pl   and then prints the current UTC time by extracting just the UTC time from the web page's HTML. Alternatively, if the above url is not working, grab the first date/time off this page's talk page. If possible,...
#zkl
zkl
const HOST="tycho.usno.navy.mil", PORT=80, dir="/cgi-bin/timer.pl"; get:="GET %s HTTP/1.0\r\nHost: %s:%s\r\n\r\n".fmt(dir,HOST,PORT); server:=Network.TCPClientSocket.connectTo(HOST,PORT); server.write(get); // send request to web serer data:=server.read(True); // read data from web server   data.seek(data.find("U...
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#11l
11l
UInt32 seed = 0 F nonrandom(n)  :seed = (1664525 * :seed + 1013904223) [&] FFFF'FFFF R Int(:seed >> 16) % n   F nonrandom_shuffle(&x) L(i) (x.len - 1 .< 0).step(-1) V j = nonrandom(i + 1) swap(&x[i], &x[j])   V SUITS = [‘♣’, ‘♦’, ‘♥’, ‘♠’] V FACES = [‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’, ‘J’...
http://rosettacode.org/wiki/Word_wrap
Word wrap
Even today, with proportional fonts and complex layouts, there are still cases where you need to wrap text at a specified column. Basic task The basic task is to wrap a paragraph of text in a simple way in your language. If there is a way to do this that is built-in, trivial, or provided in a standard library, sho...
#zkl
zkl
fcn formatText(text, // text can be String,Data,File, -->Data length=72, calcIndents=True){ sink:=Data(); getIndents:='wrap(w){ // look at first two lines to indent paragraph reg lines=L(), len=0, prefix="", one=True; do(2){ if(w._next()){ lines.append(line:=w.value); ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Q
Q
`closed`open(100#0b){@[x;where y;not]}/100#'(til[100]#'0b),'1b
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#AutoHotkey
AutoHotkey
suits := ["♠", "♦", "♥", "♣"] faces := [2,3,4,5,6,7,8,9,10,"J","Q","K","A"] deck := [], p1 := [], p2 := [] for i, s in suits for j, v in faces deck.Push(v s) deck := shuffle(deck) deal := deal(deck, p1, p2) p1 := deal.1, p2 := deal.2   for i, v in p2 { if InStr(v, "A") p2[i] := p1[i], p1[i] := v if InStr(v, "K")...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#QB64
QB64
  Const Opened = -1, Closed = 0 Dim Doors(1 To 100) As Integer, Passes As Integer, Index As Integer Rem Normal implementation Print "100doors Normal method" For Passes = 1 To 100 Step 1 Doors(Passes) = Closed Next Passes For Passes = 1 To 100 Step 1 For Index = 0 To 100 Step Passes If Index > 100 Then E...
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Go
Go
package main   import ( "fmt" "math/rand" "time" )   var suits = []string{"♣", "♦", "♥", "♠"} var faces = []string{"2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A"} var cards = make([]string, 52) var ranks = make([]int, 52)   func init() { for i := 0; i < 52; i++ { cards[i] = fmt....
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Quackery
Quackery
/O> [ bit ^ ] is toggle ( f n --> f ) ... ... [ 0 ... 100 times ... [ i^ 1+ swap ... 101 times ... [ i^ toggle over step ] ... nip ] ] is toggledoors ( --> f ) ... ... [ 100 times ... [ 1 >> dup 1 & ... if [ i^ 1+ ...
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Julia
Julia
# https://bicyclecards.com/how-to-play/war/   using Random   const SUITS = ["♣", "♦", "♥", "♠"] const FACES = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" ] const DECK = vec([f * s for s in SUITS, f in FACES]) const rdict = Dict(DECK[i] => div(i + 3, 4) for i in eachindex(DECK))   deal2(deck) = beg...
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Lua
Lua
-- main.lua function newGame () -- new deck local deck = {} for iSuit = 1, #CardSuits do for iRank = 1, #CardRanks do local card = { iSuit = iSuit, iRank = iRank, suit = CardSuits[iSuit], rank = iRank, name = CardRanks[iRank] .. CardSuits[iSuit] } local i = math.random (#deck + 1) t...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#R
R
doors_puzzle <- function(ndoors, passes = ndoors) { doors <- logical(ndoors) for (ii in seq(passes)) { mask <- seq(ii, ndoors, ii) doors[mask] <- !doors[mask] } which(doors) }   doors_puzzle(100)
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Nim
Nim
import strformat import playing_cards   const None = -1 Player1 = 0 Player2 = 1   type Player = range[None..Player2]   const PlayerNames: array[Player1..Player2, string] = ["Player 1", "Player 2"]   #---------------------------------------------------------------------------------------------------   proc `<`(a, ...
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Perl
Perl
#!/usr/bin/perl   use strict; # https://rosettacode.org/wiki/War_Card_Game use warnings; use List::Util qw( shuffle );   my %rank; @rank{ 2 .. 9, qw(t j q k a) } = 1 .. 13; # for winner local $_ = join '', shuffle map { my $f = $_; map $f.$_, qw( S H C D ) } 2 .. 9, qw( a t j q k ); substr $_, 52, 0, "\n"; # split de...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Racket
Racket
  #lang racket   ;; Applies fun to every step-th element of seq, leaving the others unchanged. (define (map-step fun step seq) (for/list ([elt seq] [i (in-naturals)]) ((if (zero? (modulo i step)) fun values) elt)))   (define (toggle-nth n seq) (map-step not n seq))   (define (solve seq) (for/fold ([result seq...
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Phix
Phix
with javascript_semantics sequence deck = shuffle(tagset(52)), hand1 = deck[1..26], hand2 = deck[27..52], pending = {} function pop1() integer res {res, hand1} = {hand1[1],hand1[2..$]} return res end function function pop2() integer res {res, hand2} = {hand2[1],hand2[2....
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Raku
Raku
my @doors = False xx 101;   (.=not for @doors[0, $_ ... 100]) for 1..100;   say "Door $_ is ", <closed open>[ @doors[$_] ] for 1..100;
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Python
Python
""" https://bicyclecards.com/how-to-play/war/ """   from numpy.random import shuffle   SUITS = ['♣', '♦', '♥', '♠'] FACES = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] DECK = [f + s for f in FACES for s in SUITS] CARD_TO_RANK = dict((DECK[i], (i + 3) // 4) for i in range(len(DECK)))     class War...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#RapidQ
RapidQ
  dim x as integer, y as integer dim door(1 to 100) as byte   'initialize array for x = 1 to 100 : door(x) = 0 : next   'set door values for y = 1 to 100 for x = y to 100 step y door(x) = not door(x) next x next y   'print result for x = 1 to 100 if door(x) then print "Door " + str$(x) + " = open" n...
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Racket
Racket
#lang racket   (define current-battle-length (make-parameter 3))   (define cards (string->list (string-append "🂢🂣🂤🂥🂦🂧🂨🂩🂪🂫🂭🂮🂡" "🂲🂳🂴🂵🂶🂷🂸🂹🂺🂻🂽🂾🂱" "🃂🃃🃄🃅🃆🃇🃈🃉🃊🃋🃍🃎🃁" "🃒🃓🃔🃕🃖🃗🃘🃙🃚🃛🃝🃞🃑")))   (define face (curry hash-ref (for/hash ((c car...
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Raku
Raku
unit sub MAIN (:$war where 2..4 = 4, :$sleep = .1);   my %c = ( # convenience hash of ANSI colors red => "\e[38;2;255;10;0m", blue => "\e[38;2;05;10;200m", black => "\e[38;2;0;0;0m" );   my @cards = flat (flat <🂢 🂣 🂤 🂥 🂦 🂧 🂨 🂩 🂪 🂫 🂭 🂮 🂡 🃒 🃓 🃔 🃕 🃖 🃗 🃘 🃙 🃚 🃛 🃝 🃞 🃑>.map(...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#REBOL
REBOL
doors: array/initial 100 'closed repeat i 100 [ door: at doors i forskip door i [change door either 'open = first door ['closed] ['open]] ]
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#Wren
Wren
import "random" for Random import "/queue" for Deque   var rand = Random.new() var suits = ["♣", "♦", "♥", "♠"] var faces = ["2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A" ] var cards = List.filled(52, null) for (i in 0..51) cards[i] = "%(faces[i%13])%(suits[(i/13).floor])" var ranks = List.filled(52,...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Red
Red
Red [ Purpose: "100 Doors Problem (Perfect Squares)" Author: "Barry Arthur" Date: "07-Oct-2016" ] doors: make vector! [char! 8 100] repeat i 100 [change at doors i #"."]   repeat i 100 [ j: i while [j <= 100] [ door: at doors j change door either #"O" = first door [#"."] [#"O"] j: j + i ...
http://rosettacode.org/wiki/War_card_game
War card game
War Card Game Simulate the card game War. Use the Bicycle playing card manufacturer's rules. Show a game as played. User input is optional. References: Bicycle card company: War game site Wikipedia: War (card game) Related tasks: Playing cards Card shuffles Deal cards for FreeCell Poker hand_analyser Go Fish...
#XPL0
XPL0
char Deck(52), \initial card deck (low 2 bits = suit) Stack(2, 52); \each player's stack of cards (52 maximum) int Inx(2), \index to last card (+1) for each stack Top, \index to compared cards, = stack top if not war Card, N, I, J...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Relation
Relation
  relation door, state set i = 1 while i <= 100 insert i, 1 set i = i+1 end while set i = 2 while i <= 100 update state = 1-state where not (door mod i) set i = i+1 end while update state = "open" where state update state = "closed" where state !== "open" print  
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Retro
Retro
:doors (n-) [ #1 repeat dup-pair n:square gt? 0; drop dup n:square n:put sp n:inc again ] do drop-pair ; #100 doors
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#REXX
REXX
/*REXX pgm solves the 100 doors puzzle, doing it the hard way by opening/closing doors.*/ parse arg doors . /*obtain the optional argument from CL.*/ if doors=='' | doors=="," then doors=100 /*not specified? Then assume 100 doors*/ ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Ring
Ring
doors = list(100) for i = 1 to 100 doors[i] = false next   For pass = 1 To 100 For door = pass To 100 if doors[door] doors[door] = false else doors[door] = true ok door += pass-1 Next Next   For door = 1 To 100 see "Door (" + door + ") is " If doors[door] see "Open" els...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Ruby
Ruby
doors = Array.new(101,0) print "Open doors " (1..100).step(){ |i| (i..100).step(i) { |d| doors[d] = doors[d]^= 1 if i == d and doors[d] == 1 then print "#{i} " end } }
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Run_BASIC
Run BASIC
dim doors(100) print "Open doors "; for i = 1 to 100 for door = i to 100 step i doors(door) = (doors(door) <> 1) if i = door and doors(door) = 1 then print i;" "; next door next i
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Rust
Rust
fn main() { let mut door_open = [false; 100]; for pass in 1..101 { let mut door = pass; while door <= 100 { door_open[door - 1] = !door_open[door - 1]; door += pass; } } for (i, &is_open) in door_open.iter().enumerate() { println!("Door {} is {}.",...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#S-BASIC
S-BASIC
  $constant DOOR_OPEN = 1 $constant DOOR_CLOSED = 0 $constant MAX_DOORS = 100   var i, j = integer dim integer doors(MAX_DOORS)   rem - all doors are initially closed for i = 1 to MAX_DOORS doors(i) = DOOR_CLOSED next i   rem - cycle through at increasing intervals and flip doors for i = 1 to MAX_DOORS for j = i to...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#S-lang
S-lang
variable door, isOpen = Char_Type [101], pass;   for (door = 1; door <= 100; door++) { isOpen[door] = 0; }   for (pass = 1; pass <= 100; pass++) { for (door = pass; door <= 100; door += pass) { isOpen[door] = not isOpen[door]; } }   for (door = 1; door <= 100; door++) { if (isOpen[door])...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Salmon
Salmon
variable open := <<(* --> false)>>; for (pass; 1; pass <= 100) for (door_num; pass; door_num <= 100; pass) open[door_num] := !(open[door_num]);;; iterate (door_num; [1...100]) print("Door ", door_num, " is ", (open[door_num] ? "open.\n" : "closed.\n"));;
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#SAS
SAS
data _null_; open=1; close=0; array Door{100}; do Pass = 1 to 100; do Current = Pass to 100 by Pass; if Door{Current} ne open then Door{Current} = open; else Door{Current} = close; end; end; NumberOfOpenDoors = sum(of Door{*}); put "Number of Open Doors...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Sather
Sather
class MAIN is main is doors :ARRAY{BOOL} := #(100); loop pass::= doors.ind!; loop i::= pass.stepto!(doors.size - 1, pass + 1); doors[i] := ~doors[i]; end; end; loop #OUT + (doors.ind! + 1) + " " + doors.elt! + "\n"; end; end; end;
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Scala
Scala
for { i <- 1 to 100 r = 1 to 100 map (i % _ == 0) reduceLeft (_^_) } println (i +" "+ (if (r) "open" else "closed"))
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Scheme
Scheme
(define *max-doors* 100)   (define (show-doors doors) (let door ((i 0) (l (vector-length doors))) (cond ((= i l) (newline)) (else (printf "~nDoor ~a is ~a" (+ i 1) (if (vector-ref doors i) "open" "closed")) (door (+ ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Scilab
Scilab
doors=zeros(1,100); for i = 1:100 for j = i:i:100 doors(j) = ~doors(j); end end for i = 1:100 if ( doors(i) ) s = "open"; else s = "closed"; end printf("%d %s\n", i, s); end
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Scratch
Scratch
$ include "seed7_05.s7i";   const proc: main is func local var array boolean: doorOpen is 100 times FALSE; var integer: pass is 0; var integer: index is 0; var array[boolean] string: closedOrOpen is [boolean] ("closed", "open"); begin for pass range 1 to 100 do for key index range doorOpen...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Seed7
Seed7
$ include "seed7_05.s7i";   const proc: main is func local var array boolean: doorOpen is 100 times FALSE; var integer: pass is 0; var integer: index is 0; var array[boolean] string: closedOrOpen is [boolean] ("closed", "open"); begin for pass range 1 to 100 do for key index range doorOpen...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#SenseTalk
SenseTalk
  put false repeated 100 times as a list into Doors100   repeat 1 to 100 set step to it repeat step to 100 by step set newValue to not item it of Doors100 set item it of Doors100 to newValue end repeat end repeat   put the counter for each item of Doors100 which is true  
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#SequenceL
SequenceL
  import <Utilities/Sequence.sl>;   main:= let doors := flipDoors(duplicate(false, 100), 1); open[i] := i when doors[i]; in open;   flipDoors(doors(1), count) := let newDoors[i] := not doors[i] when i mod count = 0 else doors[i]; in doors when count >= 100 else flipDoors(newDoors, count + 1);  
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#SETL
SETL
program hundred_doors;   const toggle := {['open', 'closed'], ['closed', 'open']};   doorStates := ['closed'] * 100;   (for interval in [1..100]) doorStates := [if i mod interval = 0 then toggle(prevState) else prevState end: prevState = doorStates(i)]; end;   ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#SheerPower_4GL
SheerPower 4GL
  !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! I n i t i a l i z a t i o n !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% doors% = 100   dim doorArray?(doors%)   !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% ! M a i n L o g i c A r e a...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Sidef
Sidef
var doors = []   { |pass| { |i| if (pass `divides` i) { doors[i] := false -> not! } } << 1..100 } << 1..100   { |i| say ("Door %3d is %s" % (i, doors[i] ? 'open' : 'closed')) } << 1..100
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Simula
Simula
BEGIN INTEGER LIMIT = 100, door, stride; BOOLEAN ARRAY DOORS(1:LIMIT); TEXT intro;   FOR stride := 1 STEP 1 UNTIL LIMIT DO FOR door := stride STEP stride UNTIL LIMIT DO DOORS(door) := NOT DOORS(door);   intro :- "All doors closed but "; FOR door := 1 STEP 1 UNTIL LIMIT DO ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Slate
Slate
define: #a -> (Array newSize: 100). a infect: [| :_ | False].   a keysDo: [| :pass | pass to: a indexLast by: pass do: [| :door | a at: door infect: #not `er]].   a keysAndValuesDo: [| :door :isOpen | inform: 'door #' ; door ; ' is ' ; (isOpen ifTrue: ['open'] ifFalse: ['closed'])].
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Smalltalk
Smalltalk
|a| a := Array new: 100 . 1 to: 100 do: [ :i | a at: i put: false ].   1 to: 100 do: [ :pass | pass to: 100 by: pass do: [ :door | a at: door put: (a at: door) not . ] ].   "output" 1 to: 100 do: [ :door | ( 'door #%1 is %2' % { door . (a at: door) ifTrue: [ 'open' ] ifFalse: [ 'closed' ] } ) displayNl ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#smart_BASIC
smart BASIC
x=1!y=3!z=0 PRINT "Open doors: ";x;" "; DO z=x+y PRINT z;" "; x=z y=y+2 UNTIL z>=100 END
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#SNOBOL4
SNOBOL4
  DEFINE('PASS(A,I),O') :(PASS.END) PASS O = 0 PASS.LOOP O = O + I EQ(A<O>,1) :S(PASS.1)F(PASS.0) PASS.0 A<O> = 1 :S(PASS.LOOP)F(RETURN) PASS.1 A<O> = 0 :S(PASS.LOOP)F(RETURN) PASS.END   MAIN D = ARRAY(100,0) I = 0   MAIN.LOOP I = LE(I,100) I + 1 :F(OUTPUT) PASS(D,I) :(MAIN.LOOP)   OUTPUT I = 1 ;...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Sparkling
Sparkling
/* declare the variables */ var isOpen = {}; var pass, door;   /* initialize the doors */ for door = 0; door < 100; door++ { isOpen[door] = true; }   /* do the 99 remaining passes */ for pass = 1; pass < 100; ++pass { for door = pass; door < 100; door += pass+1 { isOpen[door] = !isOpen[door]; } }   /* print the ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Spin
Spin
con _clkmode = xtal1+pll16x _clkfreq = 80_000_000   obj ser : "FullDuplexSerial.spin"   pub init ser.start(31, 30, 0, 115200)   doors   waitcnt(_clkfreq + cnt) ser.stop cogstop(0)   var   byte door[101] ' waste one byte by using only door[1..100]   pri doors | i,j   repeat i from 1 to 100 repeat...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#SQL
SQL
  DECLARE @sqr INT, @i INT, @door INT;   SELECT @sqr =1, @i = 3, @door = 1;   WHILE(@door <=100) BEGIN IF(@door = @sqr) BEGIN PRINT 'Door ' + RTRIM(CAST(@door AS CHAR)) + ' is open.'; SET @sqr= @sqr+@i; SET @i=@i+2; END ELSE BEGIN PRINT 'Door ' + RTRIM(CONVERT(CHAR,@door)) + ' is closed.'; END SET ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#SQL_PL
SQL PL
  --#SET TERMINATOR @   SET SERVEROUTPUT ON @   BEGIN DECLARE TYPE DOORS_ARRAY AS BOOLEAN ARRAY [100]; DECLARE DOORS DOORS_ARRAY; DECLARE I SMALLINT; DECLARE J SMALLINT; DECLARE STATUS CHAR(10); DECLARE SIZE SMALLINT DEFAULT 100;   -- Initializes the array, with all spaces (doors) as false (closed). SET I = 1; ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Standard_ML
Standard ML
  datatype Door = Closed | Opened   fun toggle Closed = Opened | toggle Opened = Closed   fun pass (step, doors) = List.map (fn (index, door) => if (index mod step) = 0 then (index, toggle door) else (index, door)) doors   (* [1..n] *) fun runs n = List.tabulate (n, fn k => k+1)   fun ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Stata
Stata
clear set obs 100 gen doors=0 gen index=_n forvalues i=1/100 { quietly replace doors=!doors if mod(_n,`i')==0 } list index if doors, noobs noheader   +-------+ | 1 | | 4 | | 9 | | 16 | | 25 | |-------| | 36 | | 49 | | 64 | | 81 | | 100 | +-------+
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#SuperCollider
SuperCollider
( var n = 100, doors = false ! n; var pass = { |j| (0, j .. n-1).do { |i| doors[i] = doors[i].not } }; (1..n-1).do(pass); doors.selectIndices { |open| open }; // all are closed except [ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81 ] )
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Swift
Swift
/* declare enum to identify the state of a door */ enum DoorState : String { case Opened = "Opened" case Closed = "Closed" }   /* declare list of doors state and initialize them */ var doorsStateList = [DoorState](count: 100, repeatedValue: DoorState.Closed)   /* do the 100 passes */ for i in 1...100 { /* m...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Tailspin
Tailspin
  source hundredDoors @: [ 1..100 -> 0 ]; templates toggle def jump: $; $jump..100:$jump -> \(when <?($@hundredDoors($) <=0>)> do @hundredDoors($): 1; otherwise @hundredDoors($): 0;\) -> !VOID end toggle 1..100 -> toggle -> !VOID $@ -> \[i](<=1> ' $i;' !\) ! end hundredDoors   $hundredDoors -> 'Open ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#Tcl
Tcl
package require Tcl 8.5 set n 100 set doors [concat - [lrepeat $n 0]] for {set step 1} {$step <= $n} {incr step} { for {set i $step} {$i <= $n} {incr i $step} { lset doors $i [expr { ! [lindex $doors $i]}] } } for {set i 1} {$i <= $n} {incr i} { puts [format "door %d is %s" $i [expr {[lindex $doors ...
http://rosettacode.org/wiki/100_doors
100 doors
There are 100 doors in a row that are all initially closed. You make 100 passes by the doors. The first time through, visit every door and  toggle  the door  (if the door is closed,  open it;   if it is open,  close it). The second time, only visit every 2nd door   (door #2, #4, #6, ...),   and toggle it. The third...
#TI-83_BASIC
TI-83 BASIC
seq(0,X,1,100 For(X,1,100 0 or Ans-not(fPart(cumSum(1 or Ans)/A End Pause Ans