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_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...
#Picat
Picat
import util.   go => text(1,Text), foreach(LineWidth in [60,80]) println(lineWidth=LineWidth), println(wrap(Text,LineWidth)), nl end, nl.   wrap(Text,LineWidth) = Wrapped => Words = Text.split(), Wrapped = Words[1], SpaceLeft = LineWidth - Wrapped.len, foreach(Word in Words.tail) ...
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...
#PicoLisp
PicoLisp
: (prinl (wrap 12 (chop "The quick brown fox jumps over the lazy dog"))) The quick brown fox jumps over the lazy dog -> "The quick^Jbrown fox^Jjumps over^Jthe lazy dog"
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Tcl
Tcl
package require tdom set tree [dom parse $xml] set studentNodes [$tree getElementsByTagName Student] ;# or: set studentNodes [[$tree documentElement] childNodes]   foreach node $studentNodes { puts [$node getAttribute Name] }
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...
#Piet
Piet
array onehundreddoors() { array doors = allocate(100); foreach(doors; int i;) for(int j=i; j<100; j+=i+1) doors[j] = !doors[j]; return doors; }
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,...
#OCaml
OCaml
let () = let _,_, page_content = make_request ~url:Sys.argv.(1) ~kind:GET () in   let lines = Str.split (Str.regexp "\n") page_content in let str = List.find (fun line -> try ignore(Str.search_forward (Str.regexp "UTC") line 0); true with Not_found -> false) lines in let str = ...
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...
#Phix
Phix
without javascript_semantics ?"loading..." constant subs = '\t'&"\r\n_.,\"\'!;:?][()|=<>#/*{}+@%&$", reps = repeat(' ',length(subs)), fn = open("135-0.txt","r") string text = lower(substitute_all(get_text(fn),subs,reps)) close(fn) sequence words = append(sort(split(text,no_empty:=true)),"") constant w...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Raku
Raku
class Wireworld { has @.line; method height () { @!line.elems } has int $.width;   multi method new(@line) { samewith :@line, :width(max @line».chars) } multi method new($str ) { samewith $str.lines }   method gist { join "\n", @.line }   method !neighbors($i where ^$.height, $j where ^$.wid...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#VBA
VBA
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Need to reference the following object library (From the Tools menu, choose References) Microsoft Forms 2.0 Object Library !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! And : Programmatic Access to Visual Basic ...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Vedit_macro_language
Vedit macro language
Win_Create(A, 2, 5, 20, 80)
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...
#PL.2FI
PL/I
*process source attributes xref or(!); ww: proc Options(main); /********************************************************************* * 21.08-2013 Walter Pachl derived from REXX version 2 *********************************************************************/ Dcl in record input; Dcl out record output; On Endfi...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#TUSCRIPT
TUSCRIPT
  $$ MODE TUSCRIPT MODE DATA $$ SET xmldata =* <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /> <Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" /> <Student Name="Dave" Gender="M" DateOfBirth="1992-07-08"> <Pet Type...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#TXR
TXR
<Students> @(collect :vars (NAME GENDER YEAR MONTH DAY (PET_TYPE "none") (PET_NAME ""))) @ (cases) <Student Name="@NAME" Gender="@GENDER" DateOfBirth="@YEAR-@MONTH-@DAY"@(skip) @ (or) <Student DateOfBirth="@YEAR-@MONTH-@DAY" Gender="@GENDER" Name="@NAME"@(skip) @ (end) @ (maybe) <Pet Type="@PET_TYPE" Name="...
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...
#Pike
Pike
array onehundreddoors() { array doors = allocate(100); foreach(doors; int i;) for(int j=i; j<100; j+=i+1) doors[j] = !doors[j]; return doors; }
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,...
#ooRexx
ooRexx
  /* load the RexxcURL library */ Call RxFuncAdd 'CurlLoadFuncs', 'rexxcurl', 'CurlLoadFuncs' Call CurlLoadFuncs   url = "http://tycho.usno.navy.mil/cgi-bin/timer.pl"   /* get a curl session */ curl = CurlInit() if curl \= '' then do call CurlSetopt curl, 'URL', Url if curlerror.intcode \= 0 then exit call cur...
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,...
#Oz
Oz
declare [Regex] = {Module.link ['x-oz://contrib/regex']}   fun {GetPage Url} F = {New Open.file init(url:Url)} Contents = {F read(list:$ size:all)} in {F close} Contents end   fun {GetDateString Doc} case {Regex.search "<BR>([A-Za-z0-9:., ]+ UTC)" Doc} of match(1:S#E ...) then {L...
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...
#Phixmonti
Phixmonti
include ..\Utilitys.pmt   "loading..." ? "135-0.txt" "r" fopen var fn " " true while fn fgets number? if drop fn fclose false else lower " " chain chain true endif endwhile   "process..." ? len for var i i get dup 96 > swap 123 < and not if 32 i set endif endfor split sort   "count..." ? ( ) var words "" va...
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...
#PHP
PHP
  <?php   preg_match_all('/\w+/', file_get_contents($argv[1]), $words); $frecuency = array_count_values($words[0]); arsort($frecuency);   echo "Rank\tWord\tFrequency\n====\t====\t=========\n"; $i = 1; foreach ($frecuency as $word => $count) { echo $i . "\t" . $word . "\t" . $count . "\n"; if ($i >= 10) { ...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#REXX
REXX
/*REXX program displays a wire world Cartesian grid of four─state cells. */ parse arg iFID . '(' generations rows cols bare head tail wire clearScreen reps if iFID=='' then iFID= "WIREWORLD.TXT" /*should default input file be used? */ bla = 'BLANK' ...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Visual_Basic_.NET
Visual Basic .NET
Dim newForm as new Form newForm.Text = "It's a new window"   newForm.Show()
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Wren
Wren
import "dome" for Window   class EmptyWindow { construct new(width, height) { Window.title = "Empty window" Window.resize(width, height) }   init() {}   update() {}   draw(alpha) {} }   var Game = EmptyWindow.new(600, 600)
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#X86_Assembly
X86 Assembly
  ;GTK imports and defines etc. %define GTK_WINDOW_TOPLEVEL 0   extern gtk_init extern gtk_window_new extern gtk_widget_show extern gtk_signal_connect extern gtk_main extern g_print extern gtk_main_quit   bits 32   section .text global _main   ;exit signal sig_main_exit: push exit_sig_msg call g_print 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...
#PowerShell
PowerShell
function wrap{ $divide=$args[0] -split " " $width=$args[1] $spaceleft=$width   foreach($word in $divide){ if($word.length+1 -gt $spaceleft){ $output+="`n$word " $spaceleft=$width-($word.length+1) } else { $output+="$word " $spaceleft-=$word.length+1 } }   return "$output`n" }...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#VBA
VBA
Option Explicit   Const strXml As String = "" & _ "<Students>" & _ "<Student Name=""April"" Gender=""F"" DateOfBirth=""1989-01-02"" />" & _ "<Student Name=""Bob"" Gender=""M"" DateOfBirth=""1990-03-04"" />" & _ "<Student Name=""Chad"" Gender=""M"" DateOfBirth=""1991-05-06"" />" & _ "<Student Name=""Da...
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...
#PL.2FI
PL/I
  declare door(100) bit (1) aligned; declare closed bit (1) static initial ('0'b), open bit (1) static initial ('1'b); declare (i, inc) fixed binary;   door = closed; inc = 1; do until (inc >= 100); do i = inc to 100 by inc; door(i) = ^door(i); /* close door if open; open it if closed. */ end; ...
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,...
#Peloton
Peloton
<@ DEFAREPRS>Rexx Parse</@> <@ DEFPRSLIT>Rexx Parse|'<BR>' UTCtime 'UTC'</@> <@ LETVARURL>timer|http://tycho.usno.navy.mil/cgi-bin/timer.pl</@> <@ ACTRPNPRSVAR>Rexx Parse|timer</@> <@ SAYVAR>UTCtime</@>
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,...
#Perl
Perl
use LWP::Simple;   my $url = 'http://tycho.usno.navy.mil/cgi-bin/timer.pl'; get($url) =~ /<BR>(.+? UTC)/ and print "$1\n";
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...
#Picat
Picat
main => NTop = 10, File = "les_miserables.txt", Chars = read_file_chars(File),    % Remove the Project Gutenberg header/footer find(Chars,"*** START OF THE PROJECT GUTENBERG EBOOK LES MISÉRABLES ***",_,HeaderEnd), find(Chars,"*** END OF THE PROJECT GUTENBERG EBOOK LES MISÉRABLES ***",FooterStart,_),   Bo...
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...
#PicoLisp
PicoLisp
(setq *Delim " ^I^J^M-_.,\"'*[]?!&@#$%^\(\):;") (setq *Skip (chop *Delim))   (de word+ NIL (prog1 (lowc (till *Delim T)) (while (member (peek) *Skip) (char)) ) )   (off B) (in "135-0.txt" (until (eof) (let W (word+) (if (idx 'B W T) (inc (car @)) (set W 1)) ) ) ) (for L (head 10 (flip (...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Ruby
Ruby
use std::str::FromStr;   #[derive(Debug, Copy, Clone, PartialEq)] pub enum State { Empty, Conductor, ElectronTail, ElectronHead, }   impl State { fn next(&self, e_nearby: usize) -> State { match self { State::Empty => State::Empty, State::Conductor => { ...
http://rosettacode.org/wiki/Window_creation
Window creation
Display a GUI window. The window need not have any contents, but should respond to requests to be closed.
#Yabasic
Yabasic
open window 400,200 //minimum line required to accomplish the indicated task clear screen text 200,100,"I am a window - close me!","cc" end
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...
#Prolog
Prolog
% See https://en.wikipedia.org/wiki/Line_wrap_and_word_wrap#Minimum_number_of_lines word_wrap(String, Length, Wrapped):- re_split("\\S+", String, Words), wrap(Words, Length, Length, Wrapped, '').   wrap([_], _, _, Result, Result):-!. wrap([Space, Word|Words], Line_length, Space_left, Result, String):- strin...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Vedit_macro_language
Vedit macro language
Repeat(ALL) { Search("<Student|X", ERRBREAK) #1 = Cur_Pos Match_Paren() if (Search_Block(/Name=|{",'}/, #1, Cur_Pos, BEGIN+ADVANCE+NOERR+NORESTORE)==0) { Continue } #2 = Cur_Pos Search(/|{",'}/) Type_Block(#2, Cur_Pos) Type_Newline }
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...
#PL.2FM
PL/M
100H: /* FIND THE FIRST FEW SQUARES VIA THE UNOPTIMISED DOOR FLIPPING METHOD */   /* BDOS SYSTEM CALL */ BDOS: PROCEDURE( FN, ARG ); DECLARE FN BYTE, ARG ADDRESS; GO TO 5; END BDOS;   /* PRINTS A BYTE AS A CHARACTER */ PRINT$CHAR: PROCEDURE( CH ); DECLARE CH BYTE; CAL...
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,...
#Phix
Phix
-- -- demo\rosetta\web_scrape.exw -- =========================== -- without js -- (libcurl) include builtins\libcurl.e include builtins\timedate.e object res = curl_easy_perform_ex("https://rosettacode.org/wiki/Talk:Web_scraping") if string(res) then res = split(res,'\n') for i=1 to length(res) do inte...
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...
#Prolog
Prolog
print_top_words(File, N):- read_file_to_string(File, String, [encoding(utf8)]), re_split("\\w+", String, Words), lower_case(Words, Lower), sort(1, @=<, Lower, Sorted), merge_words(Sorted, Counted), sort(2, @>, Counted, Top_words), writef("Top %w words:\nRank\tCount\tWord\n", [N]), print_...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Rust
Rust
use std::str::FromStr;   #[derive(Debug, Copy, Clone, PartialEq)] pub enum State { Empty, Conductor, ElectronTail, ElectronHead, }   impl State { fn next(&self, e_nearby: usize) -> State { match self { State::Empty => State::Empty, State::Conductor => { ...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Sidef
Sidef
var f = [[], DATA.lines.map {['', .chars..., '']}..., []];   10.times { say f.map { .join(" ") + "\n" }.join; var a = [[]]; for y in (1 .. f.end-1) { var r = f[y]; var rr = ['']; for x in (1 .. r.end-1) { var c = r[x]; rr << ( given(c) { ...
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...
#PureBasic
PureBasic
  DataSection Data.s "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/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Visual_Basic_.NET
Visual Basic .NET
Dim xml = <Students> <Student Name="April"/> <Student Name="Bob"/> <Student Name="Chad"/> <Student Name="Dave"/> <Student Name="Emily"/> </Students>   Dim names = (From node In xml...<Student> Select node.@Name).ToArray   For Each name In ...
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...
#PL.2FSQL
PL/SQL
  DECLARE TYPE doorsarray IS VARRAY(100) OF BOOLEAN; doors doorsarray := doorsarray(); BEGIN   doors.EXTEND(100); --ACCOMMODATE 100 DOORS   FOR i IN 1 .. doors.COUNT --MAKE ALL 100 DOORS FALSE TO INITIALISE LOOP doors(i) := FALSE; END LOOP;   FOR j IN 1 .. 100 --ITERATE THRU USING 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,...
#PHP
PHP
<?   $contents = file('http://tycho.usno.navy.mil/cgi-bin/timer.pl'); foreach ($contents as $line){ if (($pos = strpos($line, ' UTC')) === false) continue; echo subStr($line, 4, $pos - 4); //Prints something like "Dec. 06, 16:18:03" break; }
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...
#PureBasic
PureBasic
EnableExplicit   Structure wordcount wkey$ count.i EndStructure   Define token.c, word$, idx.i, start.i, arg$ NewMap wordmap.i() NewList wordlist.wordcount()   If OpenConsole("") arg$ = ProgramParameter(0) If arg$ = "" : End 1 : EndIf start = ElapsedMilliseconds() If ReadFile(0, arg$, #PB_Ascii) Whi...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Smalltalk
Smalltalk
(* Maximilian Wuttke 12.04.2016 *)   type world = char vector vector   fun getstate (w:world, (x, y)) = (Vector.sub (Vector.sub (w, y), x)) handle Subscript => #" "   fun conductor (w:world, (x, y)) = let val s = [getstate (w, (x-1, y-1)) = #"H", getstate (w, (x-1, y)) = #"H", getstate (w, (x-1, y+1)) = #"H", ...
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...
#Python
Python
>>> import textwrap >>> help(textwrap.fill) Help on function fill in module textwrap:   fill(text, width=70, **kwargs) Fill a single paragraph of text, returning a new string.   Reformat the single paragraph in 'text' to fit in lines of no more than 'width' columns, and return a new string containing the en...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Wren
Wren
import "/pattern" for Pattern import "/fmt" for Conv   var xml = "<Students> <Student Name=\"April\" Gender=\"F\" DateOfBirth=\"1989-01-02\" /> <Student Name=\"Bob\" Gender=\"M\" DateOfBirth=\"1990-03-04\" /> <Student Name=\"Chad\" Gender=\"M\" DateOfBirth=\"1991-05-06\" /> <Student Name=\"Dave\" Gender=\"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...
#Pointless
Pointless
output = range(1, 100) |> map(visit(100)) |> println   ----------------------------------------------------------   toggle(state) = if state == Closed then Open else Closed   ---------------------------------------------------------- -- Door state on iteration i is recursively -- defined in terms of previous do...
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,...
#PicoLisp
PicoLisp
(load "@lib/http.l")   (client "tycho.usno.navy.mil" 80 "cgi-bin/timer.pl" (when (from "<BR>") (pack (trim (till "U"))) ) )
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,...
#PowerShell
PowerShell
$wc = New-Object Net.WebClient $html = $wc.DownloadString('http://tycho.usno.navy.mil/cgi-bin/timer.pl') $html -match ', (.*) UTC' | Out-Null Write-Host $Matches[1]
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...
#Python
Python
import collections import re import string import sys   def main(): counter = collections.Counter(re.findall(r"\w+",open(sys.argv[1]).read().lower())) print counter.most_common(int(sys.argv[2]))   if __name__ == "__main__": main()
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Standard_ML
Standard ML
(* Maximilian Wuttke 12.04.2016 *)   type world = char vector vector   fun getstate (w:world, (x, y)) = (Vector.sub (Vector.sub (w, y), x)) handle Subscript => #" "   fun conductor (w:world, (x, y)) = let val s = [getstate (w, (x-1, y-1)) = #"H", getstate (w, (x-1, y)) = #"H", getstate (w, (x-1, y+1)) = #"H", ...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Tcl
Tcl
#import std   rule = case~&l\~&l {`H: `t!, `t: `.!,`.: @r ==`H*~; {'H','HH'}?</`H! `.!}   neighborhoods = ~&thth3hthhttPCPthPTPTX**K7S+ swin3**+ swin3@hNSPiCihNCT+ --<0>*+ 0-*   evolve "n" = @iNC ~&x+ rep"n" ^C\~& rule**+ neighborhoods@h
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...
#Quackery
Quackery
$ "Consider the inexorable logic of the Big Lie. If a man has a consuming love for cats and dedicates himself to the protection of cats, you have only to accuse him of killing and mistreating cats. Your lie will have the unmistakable ring of truth, whereas his outraged denials will reek of fa...
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...
#R
R
> x <- "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacin...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#XPL0
XPL0
code ChOut=8, CrLf=9; \intrinsic routines string 0; \use zero-terminated strings   func StrLen(A); \Return number of characters in an ASCIIZ string char A; int I; for I:= 0 to -1>>1-1 do if A(I) = 0 then return I;   func StrFind(A, B); \Search for ASCIIZ string A in string B \Returns ad...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#Yabasic
Yabasic
// ========== routine for set code conversion ================   data 32, 173, 189, 156, 207, 190, 221, 245, 249, 184, 166, 174, 170, 32, 169, 238 data 248, 241, 253, 252, 239, 230, 244, 250, 247, 251, 167, 175, 172, 171, 243, 168 data 183, 181, 182, 199, 142, 143, 146, 128, 212, 144, 210, 211, 222, 214, 215, 216 data ...
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...
#Polyglot:PL.2FI_and_PL.2FM
Polyglot:PL/I and PL/M
/* FIND THE FIRST FEW SQUARES VIA THE UNOPTIMISED DOOR FLIPPING METHOD */ doors_100H: procedure options (main);   /* PROGRAM-SPECIFIC %REPLACE STATEMENTS MUST APPEAR BEFORE THE %INCLUDE AS */ /* E.G. THE CP/M PL/I COMPILER DOESN'T LIKE THEM TO FOLLOW PROCEDURES */ ...
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,...
#PureBasic
PureBasic
URLDownloadToFile_( #Null, "http://tycho.usno.navy.mil/cgi-bin/timer.pl", "timer.htm", 0, #Null) ReadFile(0, "timer.htm") While Not Eof(0)  : Text$ + ReadString(0)  : Wend MessageRequester("Time", Mid(Text$, FindString(Text$, "UTC", 1) - 9 , 8))
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,...
#Python
Python
import urllib page = urllib.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl') for line in page: if ' UTC' in line: print line.strip()[4:] break page.close()
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...
#R
R
  wordcount<-function(file,n){ punctuation=c("`","~","!","@","#","$","%","^","&","*","(",")","_","+","=","{","[","}","]","|","\\",":",";","\"","<",",",">",".","?","/","'s") wordlist=scan(file,what=character()) wordlist=tolower(wordlist) for(i in 1:length(punctuation)){ wordlist=gsub(punctuation[i],"",wordli...
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...
#Racket
Racket
#lang racket   (define (all-words f (case-fold string-downcase)) (map case-fold (regexp-match* #px"\\w+" (file->string f))))   (define (l.|l| l) (cons (car l) (length l)))   (define (counts l (>? >)) (sort (map l.|l| (group-by values l)) >? #:key cdr))   (module+ main (take (counts (all-words "data/les-mis.txt")) 1...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Ursala
Ursala
#import std   rule = case~&l\~&l {`H: `t!, `t: `.!,`.: @r ==`H*~; {'H','HH'}?</`H! `.!}   neighborhoods = ~&thth3hthhttPCPthPTPTX**K7S+ swin3**+ swin3@hNSPiCihNCT+ --<0>*+ 0-*   evolve "n" = @iNC ~&x+ rep"n" ^C\~& rule**+ neighborhoods@h
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Wren
Wren
import "/fmt" for Fmt import "/ioutil" for FileUtil, Stdin   var rows = 0 // extent of input configuration var cols = 0 // """ var rx = 0 // grid extent (includes border) var cx = 0 // """ var mn = [] // offsets of Moore neighborhood   var print = Fn.new { |grid| System.print("__" * cols) ...
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...
#Racket
Racket
  #lang at-exp racket (require scribble/text/wrap) (define text @(λ xs (regexp-replace* #rx" *\n *" (string-append* xs) " ")){ 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,...
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...
#Raku
Raku
my $s = "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 lime-tree in th...
http://rosettacode.org/wiki/XML/Input
XML/Input
Given the following XML fragment, extract the list of student names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML and XPath. <Students> <Student Name="April" Gender="F" DateOfBirth="1989-01-02" /> <Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" /...
#zkl
zkl
student:=RegExp(0'|.*<Student\s*.+Name\s*=\s*"([^"]+)"|); unicode:=RegExp(0'|.*(&#x[0-9a-fA-F]+;)|); xml:=File("foo.xml").read();   students:=xml.pump(List,'wrap(line){ if(student.search(line)){ s:=student.matched[1]; // ( (match start,len),group text ) while(unicode.search(s)){ // convert "&#x00C9;" ...
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...
#Pony
Pony
  actor Toggler let doors:Array[Bool] let env: Env new create(count:USize,_env:Env) => var i:USize=0 doors=Array[Bool](count) env=_env while doors.size() < count do doors.push(false) end be togglin(interval : USize)=> var i:USize=0 try ...
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,...
#R
R
  all_lines <- readLines("http://tycho.usno.navy.mil/cgi-bin/timer.pl") utc_line <- grep("UTC", all_lines, value = TRUE) matched <- regexpr("(\\w{3}.*UTC)", utc_line) utc_time_str <- substring(line, matched, matched + attr(matched, "match.length") - 1L)  
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,...
#Racket
Racket
  #lang racket (require net/url) ((compose1 car (curry regexp-match #rx"[^ <>][^<>]+ UTC") port->string get-pure-port string->url) "https://tycho.usno.navy.mil/cgi-bin/timer.pl")  
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...
#Raku
Raku
sub MAIN ($filename, $top = 10) { my $file = $filename.IO.slurp.lc.subst(/ (<[\w]-[_]>'-')\n(<[\w]-[_]>) /, {$0 ~ $1}, :g ); my @matcher = ( rx/ <[a..z]>+ /, # simple 7-bit ASCII rx/ \w+ /, # word characters with underscore rx/ <[\w]-[_]>+ /, # word characters without unders...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#XPL0
XPL0
include c:\cxpl\codes; \intrinsic 'code' declarations char New(53,40), Old(53,40);   proc Block(X0, Y0, C); \Display a colored block int X0, Y0, C; \big (6x5) coordinates, char int X, Y; [case C of \convert char to color ^H: C:= $9; \blue ^t...
http://rosettacode.org/wiki/Wireworld
Wireworld
Wireworld Conway's Game of Life It is capable of doing sophisticated computations with appropriate programs (it is actually Turing complete), and is much simpler to program for. A Wireworld arena consists of a Cartesian grid of cells, each of which can be in one of four states. All cell transitions happen simultaneous...
#Yabasic
Yabasic
open window 230,130 backcolor 0,0,0 clear window   label circuit DATA " " DATA " tH......... " DATA " . . " DATA " ... " DATA " . . " DATA " Ht.. ...... " DATA " " DATA ""   do read a$ if a$ = "" break n = n + 1 redim t$(n) t$(n) = a$+a$ loop   size = len(t$(...
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...
#REXX
REXX
/*REXX program reads a file and displays it to the screen (with word wrap). */ parse arg iFID width . /*obtain optional arguments from the CL*/ if iFID=='' | iFID=="," then iFID='LAWS.TXT' /*Not specified? Then use the default.*/ if width=='' | width=="," then width=linesize(...
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...
#Pop11
Pop11
lvars i; lvars doors = {% for i from 1 to 100 do false endfor %}; for i from 1 to 100 do for j from i by i to 100 do not(doors(j)) -> doors(j); endfor; endfor; ;;; Print state for i from 1 to 100 do printf('Door ' >< i >< ' is ' >< if doors(i) then 'open' else 'closed' endif, '%s\n'); endfor;
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,...
#Raku
Raku
# 20210301 Updated Raku programming solution   use HTTP::Client; # https://github.com/supernovus/perl6-http-client/   #`[ Site inaccessible since 2019 ? my $site = "http://tycho.usno.navy.mil/cgi-bin/timer.pl"; HTTP::Client.new.get($site).content.match(/'<BR>'( .+? <ws> UTC )/)[0].say # ]   my $site = "https://www.utct...
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...
#REXX
REXX
/*REXX pgm displays top 10 words in a file (includes foreign letters), case is ignored.*/ parse arg fID top . /*obtain optional arguments from the CL*/ if fID=='' | fID=="," then fID= 'les_mes.txt' /*None specified? Then use the default.*/ if top=='' | top=="," then top= 10 ...
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...
#Ring
Ring
  # Project : Word wrap   load "stdlib.ring"   doc = "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 ...
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...
#Ruby
Ruby
class String def wrap(width) txt = gsub("\n", " ") para = [] i = 0 while i < length j = i + width j -= 1 while j != txt.length && j > i + 1 && !(txt[j] =~ /\s/) para << txt[i ... j] i = j + 1 end para end end   text = <<END In olden times when wishing still helped on...
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...
#PostScript
PostScript
/doors [ 100 { false } repeat ] def   1 1 100 { dup 1 sub exch 99 { dup doors exch get not doors 3 1 roll put } for } for doors pstack
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,...
#REBOL
REBOL
rebol [ Title: "Web Scraping" URL: http://rosettacode.org/wiki/Web_Scraping ]   ; Notice that REBOL understands unquoted URL's:   service: http://tycho.usno.navy.mil/cgi-bin/timer.pl   ; The 'read' function can read from any data scheme that REBOL knows ; about, which includes web URLs. NOTE: Depending on your secu...
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,...
#Ruby
Ruby
require "open-uri"   open('http://tycho.usno.navy.mil/cgi-bin/timer.pl') do |p| p.each_line do |line| if line =~ /UTC/ puts line.match(/ (\d{1,2}:\d{1,2}:\d{1,2}) /) break end end end  
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...
#Ring
Ring
  # project : Word count   fp = fopen("Miserables.txt","r") str = fread(fp, getFileSize(fp)) fclose(fp)   mis =substr(str, " ", nl) mis = lower(mis) mis = str2list(mis) count = list(len(mis)) ready = [] for n = 1 to len(mis) flag = 0 for m = 1 to len(mis) if mis[n] = mis[m] and n != m ...
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...
#Ruby
Ruby
  class String def wc n = Hash.new(0) downcase.scan(/[A-Za-zÀ-ÿ]+/) { |g| n[g] += 1 } n.sort{|n,g| n[1]<=>g[1]} end end   open('135-0.txt') { |n| n.read.wc[-10,10].each{|n| puts n[0].to_s+"->"+n[1].to_s} }  
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...
#Run_BASIC
Run BASIC
doc$ = "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."   wrap$ = " style='white-space: pre-wrap;white-space: -moz-pre-wrap;wh...
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...
#Rust
Rust
#[derive(Clone, Debug)] pub struct LineComposer<I> { words: I, width: usize, current: Option<String>, }   impl<I> LineComposer<I> { pub(crate) fn new<S>(words: I, width: usize) -> Self where I: Iterator<Item = S>, S: AsRef<str>, { LineComposer { words, ...
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...
#Potion
Potion
square=1, i=3 1 to 100(door): if (door == square): ("door", door, "is open") say square += i i += 2. .
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,...
#Run_BASIC
Run BASIC
print word$(word$(httpget$("http://tycho.usno.navy.mil/cgi-bin/timer.pl"),1,"UTC"),2,"<BR>")
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,...
#Rust
Rust
// 202100302 Rust programming solution   use std::io::Read; use regex::Regex;   fn main() {   let client = reqwest::blocking::Client::new(); let site = "https://www.utctime.net/"; let mut res = client.get(site).send().unwrap(); let mut body = String::new();   res.read_to_string(&mut body).unwrap()...
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...
#Rust
Rust
use std::cmp::Reverse; use std::collections::HashMap; use std::fs::File; use std::io::{BufRead, BufReader};   extern crate regex; use regex::Regex;   fn word_count(file: File, n: usize) { let word_regex = Regex::new("(?i)[a-z']+").unwrap();   let mut words = HashMap::new(); for line in BufReader::new(file)....
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...
#Scala
Scala
import scala.io.Source   object WordCount extends App {   val url = "http://www.gutenberg.org/files/135/135-0.txt" val header = "Rank Word Frequency\n==== ======== ======"   def wordCnt = Source.fromURL(url).getLines() .filter(_.nonEmpty) .flatMap(_.split("""\W+""")).toSeq .groupBy(_.toLowe...
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...
#Scala
Scala
import java.util.StringTokenizer   object WordWrap extends App { final val defaultLineWidth = 80 final val spaceWidth = 1   def letsWrap(text: String, lineWidth: Int = defaultLineWidth) = { println(s"\n\nWrapped at: $lineWidth") println("." * lineWidth) minNumLinesWrap(ewd, lineWidth) }   final 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...
#PowerShell
PowerShell
$doors = @(0..99) for($i=0; $i -lt 100; $i++) { $doors[$i] = 0 # start with all doors closed } for($i=0; $i -lt 100; $i++) { $step = $i + 1 for($j=$i; $j -lt 100; $j = $j + $step) { $doors[$j] = $doors[$j] -bxor 1 } } foreach($doornum in 1..100) { if($doors[($doornum-1)] -eq $true) {"$doornum open"} el...
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,...
#Scala
Scala
  import scala.io.Source   object WebTime extends Application { val text = Source.fromURL("http://tycho.usno.navy.mil/cgi-bin/timer.pl") val utc = text.getLines.find(_.contains("UTC")) utc match { case Some(s) => println(s.substring(4)) case _ => println("error") } }  
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,...
#Scheme
Scheme
; Use the regular expression module to parse the url (use-modules (ice-9 regex) (ice-9 rdelim))   ; Variable to store result (define time "")   ; Set the url and parse the hostname, port, and path into variables (define url "http://tycho.usno.navy.mil/cgi-bin/timer.pl") (define r (make-regexp "^(http://)?([^:/]+)(:)?((...
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...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "gethttp.s7i"; include "strifile.s7i"; include "scanfile.s7i"; include "chartype.s7i"; include "console.s7i";   const type: wordHash is hash [string] integer; const type: countHash is hash [integer] array string;   const proc: main is func local var file: inFile is STD_...
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...
#Sidef
Sidef
var count = Hash() var file = File(ARGV[0] \\ '135-0.txt')   file.open_r.each { |line| line.lc.scan(/[\pL]+/).each { |word| count{word} := 0 ++ } }   var top = count.sort_by {|_,v| v }.last(10).flip   top.each { |pair| say "#{pair.key}\t-> #{pair.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...
#Scheme
Scheme
  (import (scheme base) (scheme write) (only (srfi 13) string-join string-tokenize))   ;; word wrap, using greedy algorithm with minimum lines (define (simple-word-wrap str width) (let loop ((words (string-tokenize str)) (line-length 0) (line '()) (lines '())) ...
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...
#Processing
Processing
boolean[] doors = new boolean[100];   void setup() { for (int i = 0; i < 100; i++) { doors[i] = false; } for (int i = 1; i < 100; i++) { for (int j = 0; j < 100; j += i) { doors[j] = !doors[j]; } } println("Open:"); for (int i = 1; i < 100; i++) { if (doors[i]) { println(i); ...
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,...
#Seed7
Seed7
$ include "seed7_05.s7i"; include "gethttp.s7i";   const proc: main is func local var string: pageWithTime is ""; var integer: posOfUTC is 0; var integer: posOfBR is 0; var string: timeStri is ""; begin pageWithTime := getHttp("tycho.usno.navy.mil/cgi-bin/timer.pl"); posOfUTC := pos(pageWi...
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,...
#Sidef
Sidef
var ua = frequire('LWP::Simple'); var url = 'http://tycho.usno.navy.mil/cgi-bin/timer.pl'; var match = /<BR>(.+? UTC)/.match(ua.get(url)); say match[0] if match;
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...
#Simula
Simula
COMMENT COMPILE WITH $ cim -m64 word-count.sim ; BEGIN   COMMENT ----- CLASSES FOR GENERAL USE ;    ! ABSTRACT HASH KEY TYPE ; CLASS HASHKEY; VIRTUAL: PROCEDURE HASH IS INTEGER PROCEDURE HASH;; PROCEDURE EQUALTO IS BOOLEAN PROCEDURE EQUALTO(K); REF(HASHKEY) K;; ...